blob: 8e6b6a2d35cb27984aaddb73cdbc462ef3e350f6 [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,
Johannes Berg567ffc32013-12-18 14:43:31 +010056 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010057 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
58};
59
60static const struct genl_multicast_group nl80211_mcgrps[] = {
61 [NL80211_MCGRP_CONFIG] = { .name = "config", },
62 [NL80211_MCGRP_SCAN] = { .name = "scan", },
63 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
64 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010065 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010066#ifdef CONFIG_NL80211_TESTMODE
67 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
68#endif
69};
70
Johannes Berg89a54e42012-06-15 14:33:17 +020071/* returns ERR_PTR values */
72static struct wireless_dev *
73__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040074{
Johannes Berg89a54e42012-06-15 14:33:17 +020075 struct cfg80211_registered_device *rdev;
76 struct wireless_dev *result = NULL;
77 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
78 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
79 u64 wdev_id;
80 int wiphy_idx = -1;
81 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg5fe231e2013-05-08 21:45:15 +020083 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg89a54e42012-06-15 14:33:17 +020085 if (!have_ifidx && !have_wdev_id)
86 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040087
Johannes Berg89a54e42012-06-15 14:33:17 +020088 if (have_ifidx)
89 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
90 if (have_wdev_id) {
91 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
92 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040093 }
94
Johannes Berg89a54e42012-06-15 14:33:17 +020095 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
96 struct wireless_dev *wdev;
97
98 if (wiphy_net(&rdev->wiphy) != netns)
99 continue;
100
101 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
102 continue;
103
Johannes Berg89a54e42012-06-15 14:33:17 +0200104 list_for_each_entry(wdev, &rdev->wdev_list, list) {
105 if (have_ifidx && wdev->netdev &&
106 wdev->netdev->ifindex == ifidx) {
107 result = wdev;
108 break;
109 }
110 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
111 result = wdev;
112 break;
113 }
114 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200115
116 if (result)
117 break;
118 }
119
120 if (result)
121 return result;
122 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400123}
124
Johannes Berga9455402012-06-15 13:32:49 +0200125static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200126__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200127{
Johannes Berg7fee4772012-06-15 14:09:58 +0200128 struct cfg80211_registered_device *rdev = NULL, *tmp;
129 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg5fe231e2013-05-08 21:45:15 +0200131 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg878d9ec2012-06-15 14:18:32 +0200133 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200134 !attrs[NL80211_ATTR_IFINDEX] &&
135 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200136 return ERR_PTR(-EINVAL);
137
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200139 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200141
Johannes Berg89a54e42012-06-15 14:33:17 +0200142 if (attrs[NL80211_ATTR_WDEV]) {
143 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
144 struct wireless_dev *wdev;
145 bool found = false;
146
147 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
148 if (tmp) {
149 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200150 list_for_each_entry(wdev, &tmp->wdev_list, list) {
151 if (wdev->identifier != (u32)wdev_id)
152 continue;
153 found = true;
154 break;
155 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200156
157 if (!found)
158 tmp = NULL;
159
160 if (rdev && tmp != rdev)
161 return ERR_PTR(-EINVAL);
162 rdev = tmp;
163 }
164 }
165
Johannes Berg878d9ec2012-06-15 14:18:32 +0200166 if (attrs[NL80211_ATTR_IFINDEX]) {
167 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800168 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200169 if (netdev) {
170 if (netdev->ieee80211_ptr)
171 tmp = wiphy_to_dev(
172 netdev->ieee80211_ptr->wiphy);
173 else
174 tmp = NULL;
175
Johannes Berg7fee4772012-06-15 14:09:58 +0200176 /* 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 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800383 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
384 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200385 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
386 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400387};
388
Johannes Berge31b8212010-10-05 19:39:30 +0200389/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000390static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200391 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200392 [NL80211_KEY_IDX] = { .type = NLA_U8 },
393 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200394 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200395 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
396 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200397 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100398 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
399};
400
401/* policy for the key default flags */
402static const struct nla_policy
403nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
404 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
405 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200406};
407
Johannes Bergff1b6e62011-05-04 15:37:28 +0200408/* policy for WoWLAN attributes */
409static const struct nla_policy
410nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
411 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
413 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
414 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200415 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
416 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100419 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
420};
421
422static const struct nla_policy
423nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
424 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
425 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
426 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
427 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
428 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
430 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
431 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
432 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
434 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
435 },
436 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
437 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
438 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200439};
440
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700441/* policy for coalesce rule attributes */
442static const struct nla_policy
443nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
444 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
445 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
446 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
447};
448
Johannes Berge5497d72011-07-05 16:35:40 +0200449/* policy for GTK rekey offload attributes */
450static const struct nla_policy
451nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
452 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
453 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
454 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
455};
456
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300457static const struct nla_policy
458nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200459 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300460 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700461 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300462};
463
Johannes Berg97990a02013-04-19 01:02:55 +0200464static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
465 struct netlink_callback *cb,
466 struct cfg80211_registered_device **rdev,
467 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100468{
Johannes Berg67748892010-10-04 21:14:06 +0200469 int err;
470
Johannes Berg67748892010-10-04 21:14:06 +0200471 rtnl_lock();
472
Johannes Berg97990a02013-04-19 01:02:55 +0200473 if (!cb->args[0]) {
474 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
475 nl80211_fam.attrbuf, nl80211_fam.maxattr,
476 nl80211_policy);
477 if (err)
478 goto out_unlock;
479
480 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
481 nl80211_fam.attrbuf);
482 if (IS_ERR(*wdev)) {
483 err = PTR_ERR(*wdev);
484 goto out_unlock;
485 }
486 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200487 /* 0 is the first index - add 1 to parse only once */
488 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200489 cb->args[1] = (*wdev)->identifier;
490 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200491 /* subtract the 1 again here */
492 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200493 struct wireless_dev *tmp;
494
495 if (!wiphy) {
496 err = -ENODEV;
497 goto out_unlock;
498 }
499 *rdev = wiphy_to_dev(wiphy);
500 *wdev = NULL;
501
Johannes Berg97990a02013-04-19 01:02:55 +0200502 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
503 if (tmp->identifier == cb->args[1]) {
504 *wdev = tmp;
505 break;
506 }
507 }
Johannes Berg97990a02013-04-19 01:02:55 +0200508
509 if (!*wdev) {
510 err = -ENODEV;
511 goto out_unlock;
512 }
Johannes Berg67748892010-10-04 21:14:06 +0200513 }
514
Johannes Berg67748892010-10-04 21:14:06 +0200515 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200516 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200517 rtnl_unlock();
518 return err;
519}
520
Johannes Berg97990a02013-04-19 01:02:55 +0200521static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200522{
Johannes Berg67748892010-10-04 21:14:06 +0200523 rtnl_unlock();
524}
525
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100526/* IE validation */
527static bool is_valid_ie_attr(const struct nlattr *attr)
528{
529 const u8 *pos;
530 int len;
531
532 if (!attr)
533 return true;
534
535 pos = nla_data(attr);
536 len = nla_len(attr);
537
538 while (len) {
539 u8 elemlen;
540
541 if (len < 2)
542 return false;
543 len -= 2;
544
545 elemlen = pos[1];
546 if (elemlen > len)
547 return false;
548
549 len -= elemlen;
550 pos += 2 + elemlen;
551 }
552
553 return true;
554}
555
Johannes Berg55682962007-09-20 13:09:35 -0400556/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000557static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400558 int flags, u8 cmd)
559{
560 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000561 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400562}
563
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400564static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100565 struct ieee80211_channel *chan,
566 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400567{
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
569 chan->center_freq))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
David S. Miller9360ffd2012-03-29 04:41:26 -0400572 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
573 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
574 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200575 if (chan->flags & IEEE80211_CHAN_NO_IR) {
576 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
577 goto nla_put_failure;
578 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
579 goto nla_put_failure;
580 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100581 if (chan->flags & IEEE80211_CHAN_RADAR) {
582 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
583 goto nla_put_failure;
584 if (large) {
585 u32 time;
586
587 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
588
589 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
590 chan->dfs_state))
591 goto nla_put_failure;
592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
593 time))
594 goto nla_put_failure;
595 }
596 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400597
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100598 if (large) {
599 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
600 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
601 goto nla_put_failure;
602 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
603 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
604 goto nla_put_failure;
605 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
606 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
607 goto nla_put_failure;
608 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
609 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
610 goto nla_put_failure;
611 }
612
David S. Miller9360ffd2012-03-29 04:41:26 -0400613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
614 DBM_TO_MBM(chan->max_power)))
615 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400616
617 return 0;
618
619 nla_put_failure:
620 return -ENOBUFS;
621}
622
Johannes Berg55682962007-09-20 13:09:35 -0400623/* netlink command implementations */
624
Johannes Bergb9454e82009-07-08 13:29:08 +0200625struct key_parse {
626 struct key_params p;
627 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200628 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200629 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100630 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200631};
632
633static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
634{
635 struct nlattr *tb[NL80211_KEY_MAX + 1];
636 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
637 nl80211_key_policy);
638 if (err)
639 return err;
640
641 k->def = !!tb[NL80211_KEY_DEFAULT];
642 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
643
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100644 if (k->def) {
645 k->def_uni = true;
646 k->def_multi = true;
647 }
648 if (k->defmgmt)
649 k->def_multi = true;
650
Johannes Bergb9454e82009-07-08 13:29:08 +0200651 if (tb[NL80211_KEY_IDX])
652 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
653
654 if (tb[NL80211_KEY_DATA]) {
655 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
656 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
657 }
658
659 if (tb[NL80211_KEY_SEQ]) {
660 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
661 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
662 }
663
664 if (tb[NL80211_KEY_CIPHER])
665 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
666
Johannes Berge31b8212010-10-05 19:39:30 +0200667 if (tb[NL80211_KEY_TYPE]) {
668 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
669 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
670 return -EINVAL;
671 }
672
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100673 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
674 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100675 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
676 tb[NL80211_KEY_DEFAULT_TYPES],
677 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100678 if (err)
679 return err;
680
681 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
682 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
683 }
684
Johannes Bergb9454e82009-07-08 13:29:08 +0200685 return 0;
686}
687
688static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
689{
690 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
691 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
692 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
693 }
694
695 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
696 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
697 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
698 }
699
700 if (info->attrs[NL80211_ATTR_KEY_IDX])
701 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
702
703 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
704 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
705
706 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
707 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
708
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100709 if (k->def) {
710 k->def_uni = true;
711 k->def_multi = true;
712 }
713 if (k->defmgmt)
714 k->def_multi = true;
715
Johannes Berge31b8212010-10-05 19:39:30 +0200716 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
717 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
718 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
719 return -EINVAL;
720 }
721
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100722 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
723 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
724 int err = nla_parse_nested(
725 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
726 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
727 nl80211_key_default_policy);
728 if (err)
729 return err;
730
731 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
732 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
733 }
734
Johannes Bergb9454e82009-07-08 13:29:08 +0200735 return 0;
736}
737
738static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
739{
740 int err;
741
742 memset(k, 0, sizeof(*k));
743 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200744 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200745
746 if (info->attrs[NL80211_ATTR_KEY])
747 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
748 else
749 err = nl80211_parse_key_old(info, k);
750
751 if (err)
752 return err;
753
754 if (k->def && k->defmgmt)
755 return -EINVAL;
756
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100757 if (k->defmgmt) {
758 if (k->def_uni || !k->def_multi)
759 return -EINVAL;
760 }
761
Johannes Bergb9454e82009-07-08 13:29:08 +0200762 if (k->idx != -1) {
763 if (k->defmgmt) {
764 if (k->idx < 4 || k->idx > 5)
765 return -EINVAL;
766 } else if (k->def) {
767 if (k->idx < 0 || k->idx > 3)
768 return -EINVAL;
769 } else {
770 if (k->idx < 0 || k->idx > 5)
771 return -EINVAL;
772 }
773 }
774
775 return 0;
776}
777
Johannes Bergfffd0932009-07-08 14:22:54 +0200778static struct cfg80211_cached_keys *
779nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530780 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200781{
782 struct key_parse parse;
783 struct nlattr *key;
784 struct cfg80211_cached_keys *result;
785 int rem, err, def = 0;
786
787 result = kzalloc(sizeof(*result), GFP_KERNEL);
788 if (!result)
789 return ERR_PTR(-ENOMEM);
790
791 result->def = -1;
792 result->defmgmt = -1;
793
794 nla_for_each_nested(key, keys, rem) {
795 memset(&parse, 0, sizeof(parse));
796 parse.idx = -1;
797
798 err = nl80211_parse_key_new(key, &parse);
799 if (err)
800 goto error;
801 err = -EINVAL;
802 if (!parse.p.key)
803 goto error;
804 if (parse.idx < 0 || parse.idx > 4)
805 goto error;
806 if (parse.def) {
807 if (def)
808 goto error;
809 def = 1;
810 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100811 if (!parse.def_uni || !parse.def_multi)
812 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200813 } else if (parse.defmgmt)
814 goto error;
815 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200816 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200817 if (err)
818 goto error;
819 result->params[parse.idx].cipher = parse.p.cipher;
820 result->params[parse.idx].key_len = parse.p.key_len;
821 result->params[parse.idx].key = result->data[parse.idx];
822 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530823
824 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
825 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
826 if (no_ht)
827 *no_ht = true;
828 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200829 }
830
831 return result;
832 error:
833 kfree(result);
834 return ERR_PTR(err);
835}
836
837static int nl80211_key_allowed(struct wireless_dev *wdev)
838{
839 ASSERT_WDEV_LOCK(wdev);
840
Johannes Bergfffd0932009-07-08 14:22:54 +0200841 switch (wdev->iftype) {
842 case NL80211_IFTYPE_AP:
843 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200844 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700845 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200846 break;
847 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200848 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200849 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200850 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200851 return -ENOLINK;
852 break;
853 default:
854 return -EINVAL;
855 }
856
857 return 0;
858}
859
Jouni Malinen664834d2014-01-15 00:01:44 +0200860static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
861 struct nlattr *tb)
862{
863 struct ieee80211_channel *chan;
864
865 if (tb == NULL)
866 return NULL;
867 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
868 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
869 return NULL;
870 return chan;
871}
872
Johannes Berg7527a782011-05-13 10:58:57 +0200873static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
874{
875 struct nlattr *nl_modes = nla_nest_start(msg, attr);
876 int i;
877
878 if (!nl_modes)
879 goto nla_put_failure;
880
881 i = 0;
882 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400883 if ((ifmodes & 1) && nla_put_flag(msg, i))
884 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200885 ifmodes >>= 1;
886 i++;
887 }
888
889 nla_nest_end(msg, nl_modes);
890 return 0;
891
892nla_put_failure:
893 return -ENOBUFS;
894}
895
896static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100897 struct sk_buff *msg,
898 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200899{
900 struct nlattr *nl_combis;
901 int i, j;
902
903 nl_combis = nla_nest_start(msg,
904 NL80211_ATTR_INTERFACE_COMBINATIONS);
905 if (!nl_combis)
906 goto nla_put_failure;
907
908 for (i = 0; i < wiphy->n_iface_combinations; i++) {
909 const struct ieee80211_iface_combination *c;
910 struct nlattr *nl_combi, *nl_limits;
911
912 c = &wiphy->iface_combinations[i];
913
914 nl_combi = nla_nest_start(msg, i + 1);
915 if (!nl_combi)
916 goto nla_put_failure;
917
918 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
919 if (!nl_limits)
920 goto nla_put_failure;
921
922 for (j = 0; j < c->n_limits; j++) {
923 struct nlattr *nl_limit;
924
925 nl_limit = nla_nest_start(msg, j + 1);
926 if (!nl_limit)
927 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
929 c->limits[j].max))
930 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200931 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
932 c->limits[j].types))
933 goto nla_put_failure;
934 nla_nest_end(msg, nl_limit);
935 }
936
937 nla_nest_end(msg, nl_limits);
938
David S. Miller9360ffd2012-03-29 04:41:26 -0400939 if (c->beacon_int_infra_match &&
940 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
941 goto nla_put_failure;
942 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
943 c->num_different_channels) ||
944 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
945 c->max_interfaces))
946 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100947 if (large &&
948 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
949 c->radar_detect_widths))
950 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200951
952 nla_nest_end(msg, nl_combi);
953 }
954
955 nla_nest_end(msg, nl_combis);
956
957 return 0;
958nla_put_failure:
959 return -ENOBUFS;
960}
961
Johannes Berg3713b4e2013-02-14 16:19:38 +0100962#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100963static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
964 struct sk_buff *msg)
965{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100967 struct nlattr *nl_tcp;
968
969 if (!tcp)
970 return 0;
971
972 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
973 if (!nl_tcp)
974 return -ENOBUFS;
975
976 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
977 tcp->data_payload_max))
978 return -ENOBUFS;
979
980 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
981 tcp->data_payload_max))
982 return -ENOBUFS;
983
984 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
985 return -ENOBUFS;
986
987 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
988 sizeof(*tcp->tok), tcp->tok))
989 return -ENOBUFS;
990
991 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
992 tcp->data_interval_max))
993 return -ENOBUFS;
994
995 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
996 tcp->wake_payload_max))
997 return -ENOBUFS;
998
999 nla_nest_end(msg, nl_tcp);
1000 return 0;
1001}
1002
Johannes Berg3713b4e2013-02-14 16:19:38 +01001003static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +01001004 struct cfg80211_registered_device *dev,
1005 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006{
1007 struct nlattr *nl_wowlan;
1008
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 return 0;
1011
1012 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1013 if (!nl_wowlan)
1014 return -ENOBUFS;
1015
Johannes Berg964dc9e2013-06-03 17:25:34 +02001016 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001017 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001018 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001019 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001020 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001021 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001022 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001023 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001024 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001025 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001026 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001028 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001029 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001030 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001031 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1032 return -ENOBUFS;
1033
Johannes Berg964dc9e2013-06-03 17:25:34 +02001034 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001035 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +02001036 .max_patterns = dev->wiphy.wowlan->n_patterns,
1037 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1038 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1039 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001040 };
1041
1042 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1043 sizeof(pat), &pat))
1044 return -ENOBUFS;
1045 }
1046
Johannes Bergb56cf722013-02-20 01:02:38 +01001047 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1048 return -ENOBUFS;
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_nest_end(msg, nl_wowlan);
1051
1052 return 0;
1053}
1054#endif
1055
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001056static int nl80211_send_coalesce(struct sk_buff *msg,
1057 struct cfg80211_registered_device *dev)
1058{
1059 struct nl80211_coalesce_rule_support rule;
1060
1061 if (!dev->wiphy.coalesce)
1062 return 0;
1063
1064 rule.max_rules = dev->wiphy.coalesce->n_rules;
1065 rule.max_delay = dev->wiphy.coalesce->max_delay;
1066 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1067 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1068 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1069 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1070
1071 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1072 return -ENOBUFS;
1073
1074 return 0;
1075}
1076
Johannes Berg3713b4e2013-02-14 16:19:38 +01001077static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1078 struct ieee80211_supported_band *sband)
1079{
1080 struct nlattr *nl_rates, *nl_rate;
1081 struct ieee80211_rate *rate;
1082 int i;
1083
1084 /* add HT info */
1085 if (sband->ht_cap.ht_supported &&
1086 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1087 sizeof(sband->ht_cap.mcs),
1088 &sband->ht_cap.mcs) ||
1089 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1090 sband->ht_cap.cap) ||
1091 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1092 sband->ht_cap.ampdu_factor) ||
1093 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1094 sband->ht_cap.ampdu_density)))
1095 return -ENOBUFS;
1096
1097 /* add VHT info */
1098 if (sband->vht_cap.vht_supported &&
1099 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1100 sizeof(sband->vht_cap.vht_mcs),
1101 &sband->vht_cap.vht_mcs) ||
1102 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1103 sband->vht_cap.cap)))
1104 return -ENOBUFS;
1105
1106 /* add bitrates */
1107 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1108 if (!nl_rates)
1109 return -ENOBUFS;
1110
1111 for (i = 0; i < sband->n_bitrates; i++) {
1112 nl_rate = nla_nest_start(msg, i);
1113 if (!nl_rate)
1114 return -ENOBUFS;
1115
1116 rate = &sband->bitrates[i];
1117 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1118 rate->bitrate))
1119 return -ENOBUFS;
1120 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1121 nla_put_flag(msg,
1122 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1123 return -ENOBUFS;
1124
1125 nla_nest_end(msg, nl_rate);
1126 }
1127
1128 nla_nest_end(msg, nl_rates);
1129
1130 return 0;
1131}
1132
1133static int
1134nl80211_send_mgmt_stypes(struct sk_buff *msg,
1135 const struct ieee80211_txrx_stypes *mgmt_stypes)
1136{
1137 u16 stypes;
1138 struct nlattr *nl_ftypes, *nl_ifs;
1139 enum nl80211_iftype ift;
1140 int i;
1141
1142 if (!mgmt_stypes)
1143 return 0;
1144
1145 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1146 if (!nl_ifs)
1147 return -ENOBUFS;
1148
1149 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1150 nl_ftypes = nla_nest_start(msg, ift);
1151 if (!nl_ftypes)
1152 return -ENOBUFS;
1153 i = 0;
1154 stypes = mgmt_stypes[ift].tx;
1155 while (stypes) {
1156 if ((stypes & 1) &&
1157 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1158 (i << 4) | IEEE80211_FTYPE_MGMT))
1159 return -ENOBUFS;
1160 stypes >>= 1;
1161 i++;
1162 }
1163 nla_nest_end(msg, nl_ftypes);
1164 }
1165
1166 nla_nest_end(msg, nl_ifs);
1167
1168 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1169 if (!nl_ifs)
1170 return -ENOBUFS;
1171
1172 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1173 nl_ftypes = nla_nest_start(msg, ift);
1174 if (!nl_ftypes)
1175 return -ENOBUFS;
1176 i = 0;
1177 stypes = mgmt_stypes[ift].rx;
1178 while (stypes) {
1179 if ((stypes & 1) &&
1180 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1181 (i << 4) | IEEE80211_FTYPE_MGMT))
1182 return -ENOBUFS;
1183 stypes >>= 1;
1184 i++;
1185 }
1186 nla_nest_end(msg, nl_ftypes);
1187 }
1188 nla_nest_end(msg, nl_ifs);
1189
1190 return 0;
1191}
1192
Johannes Berg86e8cf92013-06-19 10:57:22 +02001193struct nl80211_dump_wiphy_state {
1194 s64 filter_wiphy;
1195 long start;
1196 long split_start, band_start, chan_start;
1197 bool split;
1198};
1199
Johannes Berg3713b4e2013-02-14 16:19:38 +01001200static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1201 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001202 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001203{
1204 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001205 struct nlattr *nl_bands, *nl_band;
1206 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001207 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001208 enum ieee80211_band band;
1209 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001210 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001211 const struct ieee80211_txrx_stypes *mgmt_stypes =
1212 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001213 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001214
Eric W. Biederman15e47302012-09-07 20:12:54 +00001215 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001216 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001217 return -ENOBUFS;
1218
Johannes Berg86e8cf92013-06-19 10:57:22 +02001219 if (WARN_ON(!state))
1220 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001221
David S. Miller9360ffd2012-03-29 04:41:26 -04001222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001223 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1224 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001225 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001226 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001227 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001228
Johannes Berg86e8cf92013-06-19 10:57:22 +02001229 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001230 case 0:
1231 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1232 dev->wiphy.retry_short) ||
1233 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1234 dev->wiphy.retry_long) ||
1235 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1236 dev->wiphy.frag_threshold) ||
1237 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1238 dev->wiphy.rts_threshold) ||
1239 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1240 dev->wiphy.coverage_class) ||
1241 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1242 dev->wiphy.max_scan_ssids) ||
1243 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1244 dev->wiphy.max_sched_scan_ssids) ||
1245 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1246 dev->wiphy.max_scan_ie_len) ||
1247 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1248 dev->wiphy.max_sched_scan_ie_len) ||
1249 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1250 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001251 goto nla_put_failure;
1252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1254 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1255 goto nla_put_failure;
1256 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1257 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1258 goto nla_put_failure;
1259 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1260 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1261 goto nla_put_failure;
1262 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1263 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1264 goto nla_put_failure;
1265 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1266 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1267 goto nla_put_failure;
1268 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1269 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001270 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001271 state->split_start++;
1272 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 break;
1274 case 1:
1275 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1276 sizeof(u32) * dev->wiphy.n_cipher_suites,
1277 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001278 goto nla_put_failure;
1279
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1281 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001282 goto nla_put_failure;
1283
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1285 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1286 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001287
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1289 dev->wiphy.available_antennas_tx) ||
1290 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1291 dev->wiphy.available_antennas_rx))
1292 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001293
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1295 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1296 dev->wiphy.probe_resp_offload))
1297 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001298
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 if ((dev->wiphy.available_antennas_tx ||
1300 dev->wiphy.available_antennas_rx) &&
1301 dev->ops->get_antenna) {
1302 u32 tx_ant = 0, rx_ant = 0;
1303 int res;
1304 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1305 if (!res) {
1306 if (nla_put_u32(msg,
1307 NL80211_ATTR_WIPHY_ANTENNA_TX,
1308 tx_ant) ||
1309 nla_put_u32(msg,
1310 NL80211_ATTR_WIPHY_ANTENNA_RX,
1311 rx_ant))
1312 goto nla_put_failure;
1313 }
Johannes Bergee688b002008-01-24 19:38:39 +01001314 }
1315
Johannes Berg86e8cf92013-06-19 10:57:22 +02001316 state->split_start++;
1317 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 break;
1319 case 2:
1320 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1321 dev->wiphy.interface_modes))
1322 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001323 state->split_start++;
1324 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 break;
1326 case 3:
1327 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1328 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001329 goto nla_put_failure;
1330
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 for (band = state->band_start;
1332 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 struct ieee80211_supported_band *sband;
1334
1335 sband = dev->wiphy.bands[band];
1336
1337 if (!sband)
1338 continue;
1339
1340 nl_band = nla_nest_start(msg, band);
1341 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001342 goto nla_put_failure;
1343
Johannes Berg86e8cf92013-06-19 10:57:22 +02001344 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 case 0:
1346 if (nl80211_send_band_rateinfo(msg, sband))
1347 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 state->chan_start++;
1349 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 break;
1351 default:
1352 /* add frequencies */
1353 nl_freqs = nla_nest_start(
1354 msg, NL80211_BAND_ATTR_FREQS);
1355 if (!nl_freqs)
1356 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001357
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 i < sband->n_channels;
1360 i++) {
1361 nl_freq = nla_nest_start(msg, i);
1362 if (!nl_freq)
1363 goto nla_put_failure;
1364
1365 chan = &sband->channels[i];
1366
Johannes Berg86e8cf92013-06-19 10:57:22 +02001367 if (nl80211_msg_put_channel(
1368 msg, chan,
1369 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 goto nla_put_failure;
1371
1372 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 break;
1375 }
1376 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001377 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001380 nla_nest_end(msg, nl_freqs);
1381 }
1382
1383 nla_nest_end(msg, nl_band);
1384
Johannes Berg86e8cf92013-06-19 10:57:22 +02001385 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388 band--;
1389 break;
1390 }
Johannes Bergee688b002008-01-24 19:38:39 +01001391 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001393
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001395 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001396 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001398
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 if (state->band_start == 0 && state->chan_start == 0)
1401 state->split_start++;
1402 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 break;
1404 case 4:
1405 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1406 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001407 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408
1409 i = 0;
1410#define CMD(op, n) \
1411 do { \
1412 if (dev->ops->op) { \
1413 i++; \
1414 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1415 goto nla_put_failure; \
1416 } \
1417 } while (0)
1418
1419 CMD(add_virtual_intf, NEW_INTERFACE);
1420 CMD(change_virtual_intf, SET_INTERFACE);
1421 CMD(add_key, NEW_KEY);
1422 CMD(start_ap, START_AP);
1423 CMD(add_station, NEW_STATION);
1424 CMD(add_mpath, NEW_MPATH);
1425 CMD(update_mesh_config, SET_MESH_CONFIG);
1426 CMD(change_bss, SET_BSS);
1427 CMD(auth, AUTHENTICATE);
1428 CMD(assoc, ASSOCIATE);
1429 CMD(deauth, DEAUTHENTICATE);
1430 CMD(disassoc, DISASSOCIATE);
1431 CMD(join_ibss, JOIN_IBSS);
1432 CMD(join_mesh, JOIN_MESH);
1433 CMD(set_pmksa, SET_PMKSA);
1434 CMD(del_pmksa, DEL_PMKSA);
1435 CMD(flush_pmksa, FLUSH_PMKSA);
1436 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1437 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1438 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1439 CMD(mgmt_tx, FRAME);
1440 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1441 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1442 i++;
1443 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1444 goto nla_put_failure;
1445 }
1446 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1447 dev->ops->join_mesh) {
1448 i++;
1449 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1450 goto nla_put_failure;
1451 }
1452 CMD(set_wds_peer, SET_WDS_PEER);
1453 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1454 CMD(tdls_mgmt, TDLS_MGMT);
1455 CMD(tdls_oper, TDLS_OPER);
1456 }
1457 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1458 CMD(sched_scan_start, START_SCHED_SCAN);
1459 CMD(probe_client, PROBE_CLIENT);
1460 CMD(set_noack_map, SET_NOACK_MAP);
1461 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1462 i++;
1463 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1464 goto nla_put_failure;
1465 }
1466 CMD(start_p2p_device, START_P2P_DEVICE);
1467 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001469 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1470 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001471 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1472 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001473 }
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08001474 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg8fdc6212009-03-14 09:34:01 +01001475
Kalle Valo4745fc02011-11-17 19:06:10 +02001476#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001478#endif
1479
Johannes Berg8fdc6212009-03-14 09:34:01 +01001480#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001481
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 if (dev->ops->connect || dev->ops->auth) {
1483 i++;
1484 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001485 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001486 }
1487
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 if (dev->ops->disconnect || dev->ops->deauth) {
1489 i++;
1490 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1491 goto nla_put_failure;
1492 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001493
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 nla_nest_end(msg, nl_cmds);
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 5:
1499 if (dev->ops->remain_on_channel &&
1500 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1501 nla_put_u32(msg,
1502 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1503 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001504 goto nla_put_failure;
1505
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1507 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1508 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001509
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1511 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001512 state->split_start++;
1513 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 break;
1515 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001516#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001519 state->split_start++;
1520 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001521 break;
1522#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001523 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524#endif
1525 case 7:
1526 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1527 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001528 goto nla_put_failure;
1529
Johannes Berg86e8cf92013-06-19 10:57:22 +02001530 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1531 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001533
Johannes Berg86e8cf92013-06-19 10:57:22 +02001534 state->split_start++;
1535 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 break;
1537 case 8:
1538 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1539 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1540 dev->wiphy.ap_sme_capa))
1541 goto nla_put_failure;
1542
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001543 features = dev->wiphy.features;
1544 /*
1545 * We can only add the per-channel limit information if the
1546 * dump is split, otherwise it makes it too big. Therefore
1547 * only advertise it in that case.
1548 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001549 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001550 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1551 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 goto nla_put_failure;
1553
1554 if (dev->wiphy.ht_capa_mod_mask &&
1555 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1556 sizeof(*dev->wiphy.ht_capa_mod_mask),
1557 dev->wiphy.ht_capa_mod_mask))
1558 goto nla_put_failure;
1559
1560 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1561 dev->wiphy.max_acl_mac_addrs &&
1562 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1563 dev->wiphy.max_acl_mac_addrs))
1564 goto nla_put_failure;
1565
1566 /*
1567 * Any information below this point is only available to
1568 * applications that can deal with it being split. This
1569 * helps ensure that newly added capabilities don't break
1570 * older tools by overrunning their buffers.
1571 *
1572 * We still increment split_start so that in the split
1573 * case we'll continue with more data in the next round,
1574 * but break unconditionally so unsplit data stops here.
1575 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001576 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 break;
1578 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001579 if (dev->wiphy.extended_capabilities &&
1580 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1581 dev->wiphy.extended_capabilities_len,
1582 dev->wiphy.extended_capabilities) ||
1583 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1584 dev->wiphy.extended_capabilities_len,
1585 dev->wiphy.extended_capabilities_mask)))
1586 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587
Johannes Bergee2aca32013-02-21 17:36:01 +01001588 if (dev->wiphy.vht_capa_mod_mask &&
1589 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1590 sizeof(*dev->wiphy.vht_capa_mod_mask),
1591 dev->wiphy.vht_capa_mod_mask))
1592 goto nla_put_failure;
1593
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001594 state->split_start++;
1595 break;
1596 case 10:
1597 if (nl80211_send_coalesce(msg, dev))
1598 goto nla_put_failure;
1599
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001600 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1601 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1602 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1603 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001604
1605 if (dev->wiphy.max_ap_assoc_sta &&
1606 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
1607 dev->wiphy.max_ap_assoc_sta))
1608 goto nla_put_failure;
1609
Johannes Bergad7e7182013-11-13 13:37:47 +01001610 state->split_start++;
1611 break;
1612 case 11:
Johannes Berg567ffc32013-12-18 14:43:31 +01001613 if (dev->wiphy.n_vendor_commands) {
1614 const struct nl80211_vendor_cmd_info *info;
1615 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001616
Johannes Berg567ffc32013-12-18 14:43:31 +01001617 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1618 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001619 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001620
1621 for (i = 0; i < dev->wiphy.n_vendor_commands; i++) {
1622 info = &dev->wiphy.vendor_commands[i].info;
1623 if (nla_put(msg, i + 1, sizeof(*info), info))
1624 goto nla_put_failure;
1625 }
1626 nla_nest_end(msg, nested);
1627 }
1628
1629 if (dev->wiphy.n_vendor_events) {
1630 const struct nl80211_vendor_cmd_info *info;
1631 struct nlattr *nested;
1632
1633 nested = nla_nest_start(msg,
1634 NL80211_ATTR_VENDOR_EVENTS);
1635 if (!nested)
1636 goto nla_put_failure;
1637
1638 for (i = 0; i < dev->wiphy.n_vendor_events; i++) {
1639 info = &dev->wiphy.vendor_events[i];
1640 if (nla_put(msg, i + 1, sizeof(*info), info))
1641 goto nla_put_failure;
1642 }
1643 nla_nest_end(msg, nested);
1644 }
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001645
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001647 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001649 }
Johannes Berg55682962007-09-20 13:09:35 -04001650 return genlmsg_end(msg, hdr);
1651
1652 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001653 genlmsg_cancel(msg, hdr);
1654 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001655}
1656
Johannes Berg86e8cf92013-06-19 10:57:22 +02001657static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1658 struct netlink_callback *cb,
1659 struct nl80211_dump_wiphy_state *state)
1660{
1661 struct nlattr **tb = nl80211_fam.attrbuf;
1662 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1663 tb, nl80211_fam.maxattr, nl80211_policy);
1664 /* ignore parse errors for backward compatibility */
1665 if (ret)
1666 return 0;
1667
1668 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1669 if (tb[NL80211_ATTR_WIPHY])
1670 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1671 if (tb[NL80211_ATTR_WDEV])
1672 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1673 if (tb[NL80211_ATTR_IFINDEX]) {
1674 struct net_device *netdev;
1675 struct cfg80211_registered_device *rdev;
1676 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1677
Ying Xue7f2b8562014-01-15 10:23:45 +08001678 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001679 if (!netdev)
1680 return -ENODEV;
1681 if (netdev->ieee80211_ptr) {
1682 rdev = wiphy_to_dev(
1683 netdev->ieee80211_ptr->wiphy);
1684 state->filter_wiphy = rdev->wiphy_idx;
1685 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001686 }
1687
1688 return 0;
1689}
1690
Johannes Berg55682962007-09-20 13:09:35 -04001691static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1692{
Johannes Berg645e77d2013-03-01 14:03:49 +01001693 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001695 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001696
Johannes Berg5fe231e2013-05-08 21:45:15 +02001697 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001698 if (!state) {
1699 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001700 if (!state) {
1701 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001702 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001704 state->filter_wiphy = -1;
1705 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1706 if (ret) {
1707 kfree(state);
1708 rtnl_unlock();
1709 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001710 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001711 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001712 }
1713
Johannes Berg79c97e92009-07-07 03:56:12 +02001714 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001715 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1716 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001717 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001718 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001719 if (state->filter_wiphy != -1 &&
1720 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001721 continue;
1722 /* attempt to fit multiple wiphy data chunks into the skb */
1723 do {
1724 ret = nl80211_send_wiphy(dev, skb,
1725 NETLINK_CB(cb->skb).portid,
1726 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001728 if (ret < 0) {
1729 /*
1730 * If sending the wiphy data didn't fit (ENOBUFS
1731 * or EMSGSIZE returned), this SKB is still
1732 * empty (so it's not too big because another
1733 * wiphy dataset is already in the skb) and
1734 * we've not tried to adjust the dump allocation
1735 * yet ... then adjust the alloc size to be
1736 * bigger, and return 1 but with the empty skb.
1737 * This results in an empty message being RX'ed
1738 * in userspace, but that is ignored.
1739 *
1740 * We can then retry with the larger buffer.
1741 */
1742 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001743 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001744 cb->min_dump_alloc < 4096) {
1745 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001746 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001747 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001748 return 1;
1749 }
1750 idx--;
1751 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001752 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001753 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001754 break;
Johannes Berg55682962007-09-20 13:09:35 -04001755 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001756 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001757
Johannes Berg86e8cf92013-06-19 10:57:22 +02001758 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001759
1760 return skb->len;
1761}
1762
Johannes Berg86e8cf92013-06-19 10:57:22 +02001763static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1764{
1765 kfree((void *)cb->args[0]);
1766 return 0;
1767}
1768
Johannes Berg55682962007-09-20 13:09:35 -04001769static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1770{
1771 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001772 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001773 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001774
Johannes Berg645e77d2013-03-01 14:03:49 +01001775 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001776 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001777 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001778
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001780 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001781 nlmsg_free(msg);
1782 return -ENOBUFS;
1783 }
Johannes Berg55682962007-09-20 13:09:35 -04001784
Johannes Berg134e6372009-07-10 09:51:34 +00001785 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001786}
1787
Jouni Malinen31888482008-10-30 16:59:24 +02001788static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1789 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1790 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1791 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1792 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1793 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1794};
1795
1796static int parse_txq_params(struct nlattr *tb[],
1797 struct ieee80211_txq_params *txq_params)
1798{
Johannes Berga3304b02012-03-28 11:04:24 +02001799 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001800 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1801 !tb[NL80211_TXQ_ATTR_AIFS])
1802 return -EINVAL;
1803
Johannes Berga3304b02012-03-28 11:04:24 +02001804 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001805 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1806 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1807 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1808 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1809
Johannes Berga3304b02012-03-28 11:04:24 +02001810 if (txq_params->ac >= NL80211_NUM_ACS)
1811 return -EINVAL;
1812
Jouni Malinen31888482008-10-30 16:59:24 +02001813 return 0;
1814}
1815
Johannes Bergf444de02010-05-05 15:25:02 +02001816static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1817{
1818 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001819 * You can only set the channel explicitly for WDS interfaces,
1820 * all others have their channel managed via their respective
1821 * "establish a connection" command (connect, join, ...)
1822 *
1823 * For AP/GO and mesh mode, the channel can be set with the
1824 * channel userspace API, but is only stored and passed to the
1825 * low-level driver when the AP starts or the mesh is joined.
1826 * This is for backward compatibility, userspace can also give
1827 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001828 *
1829 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001830 * whatever else is going on, so they have their own special
1831 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001832 */
1833 return !wdev ||
1834 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001835 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001836 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1837 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001838}
1839
Johannes Berg683b6d32012-11-08 21:25:48 +01001840static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1841 struct genl_info *info,
1842 struct cfg80211_chan_def *chandef)
1843{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301844 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001845
1846 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1847 return -EINVAL;
1848
1849 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1850
1851 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001852 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1853 chandef->center_freq1 = control_freq;
1854 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001855
1856 /* Primary channel not allowed */
1857 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1858 return -EINVAL;
1859
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001860 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1861 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001862
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001863 chantype = nla_get_u32(
1864 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1865
1866 switch (chantype) {
1867 case NL80211_CHAN_NO_HT:
1868 case NL80211_CHAN_HT20:
1869 case NL80211_CHAN_HT40PLUS:
1870 case NL80211_CHAN_HT40MINUS:
1871 cfg80211_chandef_create(chandef, chandef->chan,
1872 chantype);
1873 break;
1874 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001875 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001876 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001877 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1878 chandef->width =
1879 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1880 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1881 chandef->center_freq1 =
1882 nla_get_u32(
1883 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1884 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1885 chandef->center_freq2 =
1886 nla_get_u32(
1887 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1888 }
1889
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001890 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001891 return -EINVAL;
1892
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001893 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1894 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001895 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001896
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001897 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1898 chandef->width == NL80211_CHAN_WIDTH_10) &&
1899 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1900 return -EINVAL;
1901
Johannes Berg683b6d32012-11-08 21:25:48 +01001902 return 0;
1903}
1904
Johannes Bergf444de02010-05-05 15:25:02 +02001905static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1906 struct wireless_dev *wdev,
1907 struct genl_info *info)
1908{
Johannes Berg683b6d32012-11-08 21:25:48 +01001909 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001910 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001911 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1912
1913 if (wdev)
1914 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001915
Johannes Bergf444de02010-05-05 15:25:02 +02001916 if (!nl80211_can_set_dev_channel(wdev))
1917 return -EOPNOTSUPP;
1918
Johannes Berg683b6d32012-11-08 21:25:48 +01001919 result = nl80211_parse_chandef(rdev, info, &chandef);
1920 if (result)
1921 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001922
Johannes Berge8c9bd52012-06-06 08:18:22 +02001923 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001924 case NL80211_IFTYPE_AP:
1925 case NL80211_IFTYPE_P2P_GO:
1926 if (wdev->beacon_interval) {
1927 result = -EBUSY;
1928 break;
1929 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001930 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001931 result = -EINVAL;
1932 break;
1933 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001934 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001935 result = 0;
1936 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001937 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001938 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001939 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001940 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001941 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001942 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001943 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001944 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001945 }
Johannes Bergf444de02010-05-05 15:25:02 +02001946
1947 return result;
1948}
1949
1950static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1951{
Johannes Berg4c476992010-10-04 21:36:35 +02001952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1953 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001954
Johannes Berg4c476992010-10-04 21:36:35 +02001955 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001956}
1957
Bill Jordane8347eb2010-10-01 13:54:28 -04001958static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1959{
Johannes Berg43b19952010-10-07 13:10:30 +02001960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1961 struct net_device *dev = info->user_ptr[1];
1962 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001963 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001964
1965 if (!info->attrs[NL80211_ATTR_MAC])
1966 return -EINVAL;
1967
Johannes Berg43b19952010-10-07 13:10:30 +02001968 if (netif_running(dev))
1969 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001970
Johannes Berg43b19952010-10-07 13:10:30 +02001971 if (!rdev->ops->set_wds_peer)
1972 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001973
Johannes Berg43b19952010-10-07 13:10:30 +02001974 if (wdev->iftype != NL80211_IFTYPE_WDS)
1975 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001976
1977 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001978 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001979}
1980
1981
Johannes Berg55682962007-09-20 13:09:35 -04001982static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1983{
1984 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001985 struct net_device *netdev = NULL;
1986 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001987 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001988 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001989 u32 changed;
1990 u8 retry_short = 0, retry_long = 0;
1991 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001992 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001993
Johannes Berg5fe231e2013-05-08 21:45:15 +02001994 ASSERT_RTNL();
1995
Johannes Bergf444de02010-05-05 15:25:02 +02001996 /*
1997 * Try to find the wiphy and netdev. Normally this
1998 * function shouldn't need the netdev, but this is
1999 * done for backward compatibility -- previously
2000 * setting the channel was done per wiphy, but now
2001 * it is per netdev. Previous userland like hostapd
2002 * also passed a netdev to set_wiphy, so that it is
2003 * possible to let that go to the right netdev!
2004 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002005
Johannes Bergf444de02010-05-05 15:25:02 +02002006 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2007 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2008
Ying Xue7f2b8562014-01-15 10:23:45 +08002009 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002010 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02002011 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002012 else
Johannes Bergf444de02010-05-05 15:25:02 +02002013 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002014 }
2015
Johannes Bergf444de02010-05-05 15:25:02 +02002016 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002017 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2018 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002019 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002020 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002021 wdev = NULL;
2022 netdev = NULL;
2023 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002024 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002025 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002026
2027 /*
2028 * end workaround code, by now the rdev is available
2029 * and locked, and wdev may or may not be NULL.
2030 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002031
2032 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002033 result = cfg80211_dev_rename(
2034 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002035
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002036 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002037 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002038
Jouni Malinen31888482008-10-30 16:59:24 +02002039 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2040 struct ieee80211_txq_params txq_params;
2041 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2042
Ying Xue7f2b8562014-01-15 10:23:45 +08002043 if (!rdev->ops->set_txq_params)
2044 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002045
Ying Xue7f2b8562014-01-15 10:23:45 +08002046 if (!netdev)
2047 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002048
Johannes Berg133a3ff2011-11-03 14:50:13 +01002049 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002050 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2051 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002052
Ying Xue7f2b8562014-01-15 10:23:45 +08002053 if (!netif_running(netdev))
2054 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002055
Jouni Malinen31888482008-10-30 16:59:24 +02002056 nla_for_each_nested(nl_txq_params,
2057 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2058 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002059 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2060 nla_data(nl_txq_params),
2061 nla_len(nl_txq_params),
2062 txq_params_policy);
2063 if (result)
2064 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002065 result = parse_txq_params(tb, &txq_params);
2066 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002067 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002068
Hila Gonene35e4d22012-06-27 17:19:42 +03002069 result = rdev_set_txq_params(rdev, netdev,
2070 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002071 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002072 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002073 }
2074 }
2075
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002076 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002077 result = __nl80211_set_channel(rdev,
2078 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2079 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002080 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002081 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002082 }
2083
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002084 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002085 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002086 enum nl80211_tx_power_setting type;
2087 int idx, mbm = 0;
2088
Johannes Bergc8442112012-10-24 10:17:18 +02002089 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2090 txp_wdev = NULL;
2091
Ying Xue7f2b8562014-01-15 10:23:45 +08002092 if (!rdev->ops->set_tx_power)
2093 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002094
2095 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2096 type = nla_get_u32(info->attrs[idx]);
2097
2098 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002099 (type != NL80211_TX_POWER_AUTOMATIC))
2100 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002101
2102 if (type != NL80211_TX_POWER_AUTOMATIC) {
2103 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2104 mbm = nla_get_u32(info->attrs[idx]);
2105 }
2106
Johannes Bergc8442112012-10-24 10:17:18 +02002107 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002108 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002109 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002110 }
2111
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002112 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2113 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2114 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002115 if ((!rdev->wiphy.available_antennas_tx &&
2116 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002117 !rdev->ops->set_antenna)
2118 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002119
2120 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2121 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2122
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002123 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002124 * available antenna masks, except for the "all" mask */
2125 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002126 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2127 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002128
Bruno Randolf7f531e02010-12-16 11:30:22 +09002129 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2130 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002131
Hila Gonene35e4d22012-06-27 17:19:42 +03002132 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002133 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002134 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002135 }
2136
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002137 changed = 0;
2138
2139 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2140 retry_short = nla_get_u8(
2141 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002142 if (retry_short == 0)
2143 return -EINVAL;
2144
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002145 changed |= WIPHY_PARAM_RETRY_SHORT;
2146 }
2147
2148 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2149 retry_long = nla_get_u8(
2150 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002151 if (retry_long == 0)
2152 return -EINVAL;
2153
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002154 changed |= WIPHY_PARAM_RETRY_LONG;
2155 }
2156
2157 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2158 frag_threshold = nla_get_u32(
2159 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 if (frag_threshold < 256)
2161 return -EINVAL;
2162
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002163 if (frag_threshold != (u32) -1) {
2164 /*
2165 * Fragments (apart from the last one) are required to
2166 * have even length. Make the fragmentation code
2167 * simpler by stripping LSB should someone try to use
2168 * odd threshold value.
2169 */
2170 frag_threshold &= ~0x1;
2171 }
2172 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2173 }
2174
2175 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2176 rts_threshold = nla_get_u32(
2177 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2178 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2179 }
2180
Lukáš Turek81077e82009-12-21 22:50:47 +01002181 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2182 coverage_class = nla_get_u8(
2183 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2184 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2185 }
2186
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002187 if (changed) {
2188 u8 old_retry_short, old_retry_long;
2189 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002190 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002191
Ying Xue7f2b8562014-01-15 10:23:45 +08002192 if (!rdev->ops->set_wiphy_params)
2193 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002194
2195 old_retry_short = rdev->wiphy.retry_short;
2196 old_retry_long = rdev->wiphy.retry_long;
2197 old_frag_threshold = rdev->wiphy.frag_threshold;
2198 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002199 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002200
2201 if (changed & WIPHY_PARAM_RETRY_SHORT)
2202 rdev->wiphy.retry_short = retry_short;
2203 if (changed & WIPHY_PARAM_RETRY_LONG)
2204 rdev->wiphy.retry_long = retry_long;
2205 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2206 rdev->wiphy.frag_threshold = frag_threshold;
2207 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2208 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002209 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2210 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002211
Hila Gonene35e4d22012-06-27 17:19:42 +03002212 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 if (result) {
2214 rdev->wiphy.retry_short = old_retry_short;
2215 rdev->wiphy.retry_long = old_retry_long;
2216 rdev->wiphy.frag_threshold = old_frag_threshold;
2217 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002218 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002219 }
2220 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002221 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002222}
2223
Johannes Berg71bbc992012-06-15 15:30:18 +02002224static inline u64 wdev_id(struct wireless_dev *wdev)
2225{
2226 return (u64)wdev->identifier |
2227 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2228}
Johannes Berg55682962007-09-20 13:09:35 -04002229
Johannes Berg683b6d32012-11-08 21:25:48 +01002230static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002231 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002232{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002233 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002234
Johannes Berg683b6d32012-11-08 21:25:48 +01002235 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2236 chandef->chan->center_freq))
2237 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002238 switch (chandef->width) {
2239 case NL80211_CHAN_WIDTH_20_NOHT:
2240 case NL80211_CHAN_WIDTH_20:
2241 case NL80211_CHAN_WIDTH_40:
2242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2243 cfg80211_get_chandef_type(chandef)))
2244 return -ENOBUFS;
2245 break;
2246 default:
2247 break;
2248 }
2249 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2250 return -ENOBUFS;
2251 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2252 return -ENOBUFS;
2253 if (chandef->center_freq2 &&
2254 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002255 return -ENOBUFS;
2256 return 0;
2257}
2258
Eric W. Biederman15e47302012-09-07 20:12:54 +00002259static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002260 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002261 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002262{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002263 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002264 void *hdr;
2265
Eric W. Biederman15e47302012-09-07 20:12:54 +00002266 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002267 if (!hdr)
2268 return -1;
2269
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002270 if (dev &&
2271 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002272 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002273 goto nla_put_failure;
2274
2275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2276 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002277 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002278 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002279 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2280 rdev->devlist_generation ^
2281 (cfg80211_rdev_list_generation << 2)))
2282 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002283
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002284 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002285 int ret;
2286 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002287
Johannes Berg683b6d32012-11-08 21:25:48 +01002288 ret = rdev_get_channel(rdev, wdev, &chandef);
2289 if (ret == 0) {
2290 if (nl80211_send_chandef(msg, &chandef))
2291 goto nla_put_failure;
2292 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002293 }
2294
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002295 if (wdev->ssid_len) {
2296 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2297 goto nla_put_failure;
2298 }
2299
Johannes Berg55682962007-09-20 13:09:35 -04002300 return genlmsg_end(msg, hdr);
2301
2302 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002303 genlmsg_cancel(msg, hdr);
2304 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002305}
2306
2307static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2308{
2309 int wp_idx = 0;
2310 int if_idx = 0;
2311 int wp_start = cb->args[0];
2312 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002313 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002314 struct wireless_dev *wdev;
2315
Johannes Berg5fe231e2013-05-08 21:45:15 +02002316 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002317 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2318 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002319 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002320 if (wp_idx < wp_start) {
2321 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002322 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002323 }
Johannes Berg55682962007-09-20 13:09:35 -04002324 if_idx = 0;
2325
Johannes Berg89a54e42012-06-15 14:33:17 +02002326 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002327 if (if_idx < if_start) {
2328 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002329 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002330 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002331 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002332 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002333 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002334 goto out;
2335 }
2336 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002337 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002338
2339 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002340 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002341 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002342 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002343
2344 cb->args[0] = wp_idx;
2345 cb->args[1] = if_idx;
2346
2347 return skb->len;
2348}
2349
2350static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2351{
2352 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002353 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002354 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002355
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002357 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002358 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002359
Eric W. Biederman15e47302012-09-07 20:12:54 +00002360 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002361 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002362 nlmsg_free(msg);
2363 return -ENOBUFS;
2364 }
Johannes Berg55682962007-09-20 13:09:35 -04002365
Johannes Berg134e6372009-07-10 09:51:34 +00002366 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002367}
2368
Michael Wu66f7ac52008-01-31 19:48:22 +01002369static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2370 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2371 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2372 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2373 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2374 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002375 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002376};
2377
2378static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2379{
2380 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2381 int flag;
2382
2383 *mntrflags = 0;
2384
2385 if (!nla)
2386 return -EINVAL;
2387
2388 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2389 nla, mntr_flags_policy))
2390 return -EINVAL;
2391
2392 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2393 if (flags[flag])
2394 *mntrflags |= (1<<flag);
2395
2396 return 0;
2397}
2398
Johannes Berg9bc383d2009-11-19 11:55:19 +01002399static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002400 struct net_device *netdev, u8 use_4addr,
2401 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002402{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002403 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002404 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002405 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002406 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002407 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002408
2409 switch (iftype) {
2410 case NL80211_IFTYPE_AP_VLAN:
2411 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2412 return 0;
2413 break;
2414 case NL80211_IFTYPE_STATION:
2415 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2416 return 0;
2417 break;
2418 default:
2419 break;
2420 }
2421
2422 return -EOPNOTSUPP;
2423}
2424
Johannes Berg55682962007-09-20 13:09:35 -04002425static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2426{
Johannes Berg4c476992010-10-04 21:36:35 +02002427 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002428 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002429 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002430 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002431 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002432 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002433 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002434
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002435 memset(&params, 0, sizeof(params));
2436
Johannes Berg04a773a2009-04-19 21:24:32 +02002437 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002438
Johannes Berg723b0382008-09-16 20:22:09 +02002439 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002440 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002441 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002442 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002443 if (ntype > NL80211_IFTYPE_MAX)
2444 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002445 }
2446
Johannes Berg92ffe052008-09-16 20:39:36 +02002447 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002448 struct wireless_dev *wdev = dev->ieee80211_ptr;
2449
Johannes Berg4c476992010-10-04 21:36:35 +02002450 if (ntype != NL80211_IFTYPE_MESH_POINT)
2451 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002452 if (netif_running(dev))
2453 return -EBUSY;
2454
2455 wdev_lock(wdev);
2456 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2457 IEEE80211_MAX_MESH_ID_LEN);
2458 wdev->mesh_id_up_len =
2459 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2460 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2461 wdev->mesh_id_up_len);
2462 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002463 }
2464
Felix Fietkau8b787642009-11-10 18:53:10 +01002465 if (info->attrs[NL80211_ATTR_4ADDR]) {
2466 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2467 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002468 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002469 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002470 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002471 } else {
2472 params.use_4addr = -1;
2473 }
2474
Johannes Berg92ffe052008-09-16 20:39:36 +02002475 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002476 if (ntype != NL80211_IFTYPE_MONITOR)
2477 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002478 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2479 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002480 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002481 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002482
2483 flags = &_flags;
2484 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002485 }
Johannes Berg3b858752009-03-12 09:55:09 +01002486
Luciano Coelho18003292013-08-29 13:26:57 +03002487 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002488 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2489 return -EOPNOTSUPP;
2490
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002491 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002492 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002493 else
2494 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002495
Johannes Berg9bc383d2009-11-19 11:55:19 +01002496 if (!err && params.use_4addr != -1)
2497 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2498
Johannes Berg55682962007-09-20 13:09:35 -04002499 return err;
2500}
2501
2502static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2503{
Johannes Berg4c476992010-10-04 21:36:35 +02002504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002505 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002506 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002507 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002508 int err;
2509 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002510 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002511
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002512 memset(&params, 0, sizeof(params));
2513
Johannes Berg55682962007-09-20 13:09:35 -04002514 if (!info->attrs[NL80211_ATTR_IFNAME])
2515 return -EINVAL;
2516
2517 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2518 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2519 if (type > NL80211_IFTYPE_MAX)
2520 return -EINVAL;
2521 }
2522
Johannes Berg79c97e92009-07-07 03:56:12 +02002523 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002524 !(rdev->wiphy.interface_modes & (1 << type)))
2525 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002526
Arend van Spriel1c18f142013-01-08 10:17:27 +01002527 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2528 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2529 ETH_ALEN);
2530 if (!is_valid_ether_addr(params.macaddr))
2531 return -EADDRNOTAVAIL;
2532 }
2533
Johannes Berg9bc383d2009-11-19 11:55:19 +01002534 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002535 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002536 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002537 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002538 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002539 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002540
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002541 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2542 if (!msg)
2543 return -ENOMEM;
2544
Michael Wu66f7ac52008-01-31 19:48:22 +01002545 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2546 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2547 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002548
Luciano Coelho18003292013-08-29 13:26:57 +03002549 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002550 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2551 return -EOPNOTSUPP;
2552
Hila Gonene35e4d22012-06-27 17:19:42 +03002553 wdev = rdev_add_virtual_intf(rdev,
2554 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2555 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002556 if (IS_ERR(wdev)) {
2557 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002558 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002559 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002560
Johannes Berg98104fde2012-06-16 00:19:54 +02002561 switch (type) {
2562 case NL80211_IFTYPE_MESH_POINT:
2563 if (!info->attrs[NL80211_ATTR_MESH_ID])
2564 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002565 wdev_lock(wdev);
2566 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2567 IEEE80211_MAX_MESH_ID_LEN);
2568 wdev->mesh_id_up_len =
2569 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2570 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2571 wdev->mesh_id_up_len);
2572 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002573 break;
2574 case NL80211_IFTYPE_P2P_DEVICE:
2575 /*
2576 * P2P Device doesn't have a netdev, so doesn't go
2577 * through the netdev notifier and must be added here
2578 */
2579 mutex_init(&wdev->mtx);
2580 INIT_LIST_HEAD(&wdev->event_list);
2581 spin_lock_init(&wdev->event_lock);
2582 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2583 spin_lock_init(&wdev->mgmt_registrations_lock);
2584
Johannes Berg98104fde2012-06-16 00:19:54 +02002585 wdev->identifier = ++rdev->wdev_id;
2586 list_add_rcu(&wdev->list, &rdev->wdev_list);
2587 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002588 break;
2589 default:
2590 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002591 }
2592
Eric W. Biederman15e47302012-09-07 20:12:54 +00002593 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002594 rdev, wdev) < 0) {
2595 nlmsg_free(msg);
2596 return -ENOBUFS;
2597 }
2598
2599 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002600}
2601
2602static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2603{
Johannes Berg4c476992010-10-04 21:36:35 +02002604 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002605 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002606
Johannes Berg4c476992010-10-04 21:36:35 +02002607 if (!rdev->ops->del_virtual_intf)
2608 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002609
Johannes Berg84efbb82012-06-16 00:00:26 +02002610 /*
2611 * If we remove a wireless device without a netdev then clear
2612 * user_ptr[1] so that nl80211_post_doit won't dereference it
2613 * to check if it needs to do dev_put(). Otherwise it crashes
2614 * since the wdev has been freed, unlike with a netdev where
2615 * we need the dev_put() for the netdev to really be freed.
2616 */
2617 if (!wdev->netdev)
2618 info->user_ptr[1] = NULL;
2619
Hila Gonene35e4d22012-06-27 17:19:42 +03002620 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002621}
2622
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002623static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2624{
2625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2626 struct net_device *dev = info->user_ptr[1];
2627 u16 noack_map;
2628
2629 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2630 return -EINVAL;
2631
2632 if (!rdev->ops->set_noack_map)
2633 return -EOPNOTSUPP;
2634
2635 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2636
Hila Gonene35e4d22012-06-27 17:19:42 +03002637 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002638}
2639
Johannes Berg41ade002007-12-19 02:03:29 +01002640struct get_key_cookie {
2641 struct sk_buff *msg;
2642 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002643 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002644};
2645
2646static void get_key_callback(void *c, struct key_params *params)
2647{
Johannes Bergb9454e82009-07-08 13:29:08 +02002648 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002649 struct get_key_cookie *cookie = c;
2650
David S. Miller9360ffd2012-03-29 04:41:26 -04002651 if ((params->key &&
2652 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2653 params->key_len, params->key)) ||
2654 (params->seq &&
2655 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2656 params->seq_len, params->seq)) ||
2657 (params->cipher &&
2658 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2659 params->cipher)))
2660 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002661
Johannes Bergb9454e82009-07-08 13:29:08 +02002662 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2663 if (!key)
2664 goto nla_put_failure;
2665
David S. Miller9360ffd2012-03-29 04:41:26 -04002666 if ((params->key &&
2667 nla_put(cookie->msg, NL80211_KEY_DATA,
2668 params->key_len, params->key)) ||
2669 (params->seq &&
2670 nla_put(cookie->msg, NL80211_KEY_SEQ,
2671 params->seq_len, params->seq)) ||
2672 (params->cipher &&
2673 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2674 params->cipher)))
2675 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002676
David S. Miller9360ffd2012-03-29 04:41:26 -04002677 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2678 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002679
2680 nla_nest_end(cookie->msg, key);
2681
Johannes Berg41ade002007-12-19 02:03:29 +01002682 return;
2683 nla_put_failure:
2684 cookie->error = 1;
2685}
2686
2687static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2688{
Johannes Berg4c476992010-10-04 21:36:35 +02002689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002690 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002691 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002692 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002693 const u8 *mac_addr = NULL;
2694 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002695 struct get_key_cookie cookie = {
2696 .error = 0,
2697 };
2698 void *hdr;
2699 struct sk_buff *msg;
2700
2701 if (info->attrs[NL80211_ATTR_KEY_IDX])
2702 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2703
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002704 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002705 return -EINVAL;
2706
2707 if (info->attrs[NL80211_ATTR_MAC])
2708 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2709
Johannes Berge31b8212010-10-05 19:39:30 +02002710 pairwise = !!mac_addr;
2711 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2712 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2713 if (kt >= NUM_NL80211_KEYTYPES)
2714 return -EINVAL;
2715 if (kt != NL80211_KEYTYPE_GROUP &&
2716 kt != NL80211_KEYTYPE_PAIRWISE)
2717 return -EINVAL;
2718 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2719 }
2720
Johannes Berg4c476992010-10-04 21:36:35 +02002721 if (!rdev->ops->get_key)
2722 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002723
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002725 if (!msg)
2726 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002727
Eric W. Biederman15e47302012-09-07 20:12:54 +00002728 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002729 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002730 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002731 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002732
2733 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002734 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002735
David S. Miller9360ffd2012-03-29 04:41:26 -04002736 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2737 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2738 goto nla_put_failure;
2739 if (mac_addr &&
2740 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2741 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002742
Johannes Berge31b8212010-10-05 19:39:30 +02002743 if (pairwise && mac_addr &&
2744 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2745 return -ENOENT;
2746
Hila Gonene35e4d22012-06-27 17:19:42 +03002747 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2748 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002749
2750 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002751 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002752
2753 if (cookie.error)
2754 goto nla_put_failure;
2755
2756 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002757 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002758
2759 nla_put_failure:
2760 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002761 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002762 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002763 return err;
2764}
2765
2766static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2767{
Johannes Berg4c476992010-10-04 21:36:35 +02002768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002769 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002770 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002771 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002772
Johannes Bergb9454e82009-07-08 13:29:08 +02002773 err = nl80211_parse_key(info, &key);
2774 if (err)
2775 return err;
2776
2777 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002778 return -EINVAL;
2779
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 /* only support setting default key */
2781 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002782 return -EINVAL;
2783
Johannes Bergfffd0932009-07-08 14:22:54 +02002784 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002785
2786 if (key.def) {
2787 if (!rdev->ops->set_default_key) {
2788 err = -EOPNOTSUPP;
2789 goto out;
2790 }
2791
2792 err = nl80211_key_allowed(dev->ieee80211_ptr);
2793 if (err)
2794 goto out;
2795
Hila Gonene35e4d22012-06-27 17:19:42 +03002796 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002797 key.def_uni, key.def_multi);
2798
2799 if (err)
2800 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002801
Johannes Berg3d23e342009-09-29 23:27:28 +02002802#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002803 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002804#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002805 } else {
2806 if (key.def_uni || !key.def_multi) {
2807 err = -EINVAL;
2808 goto out;
2809 }
2810
2811 if (!rdev->ops->set_default_mgmt_key) {
2812 err = -EOPNOTSUPP;
2813 goto out;
2814 }
2815
2816 err = nl80211_key_allowed(dev->ieee80211_ptr);
2817 if (err)
2818 goto out;
2819
Hila Gonene35e4d22012-06-27 17:19:42 +03002820 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002821 if (err)
2822 goto out;
2823
2824#ifdef CONFIG_CFG80211_WEXT
2825 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2826#endif
2827 }
2828
2829 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002830 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002831
Johannes Berg41ade002007-12-19 02:03:29 +01002832 return err;
2833}
2834
2835static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2836{
Johannes Berg4c476992010-10-04 21:36:35 +02002837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002838 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002839 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002840 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002841 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002842
Johannes Bergb9454e82009-07-08 13:29:08 +02002843 err = nl80211_parse_key(info, &key);
2844 if (err)
2845 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002846
Johannes Bergb9454e82009-07-08 13:29:08 +02002847 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002848 return -EINVAL;
2849
Johannes Berg41ade002007-12-19 02:03:29 +01002850 if (info->attrs[NL80211_ATTR_MAC])
2851 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2852
Johannes Berge31b8212010-10-05 19:39:30 +02002853 if (key.type == -1) {
2854 if (mac_addr)
2855 key.type = NL80211_KEYTYPE_PAIRWISE;
2856 else
2857 key.type = NL80211_KEYTYPE_GROUP;
2858 }
2859
2860 /* for now */
2861 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2862 key.type != NL80211_KEYTYPE_GROUP)
2863 return -EINVAL;
2864
Johannes Berg4c476992010-10-04 21:36:35 +02002865 if (!rdev->ops->add_key)
2866 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002867
Johannes Berge31b8212010-10-05 19:39:30 +02002868 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2869 key.type == NL80211_KEYTYPE_PAIRWISE,
2870 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002871 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002872
2873 wdev_lock(dev->ieee80211_ptr);
2874 err = nl80211_key_allowed(dev->ieee80211_ptr);
2875 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002876 err = rdev_add_key(rdev, dev, key.idx,
2877 key.type == NL80211_KEYTYPE_PAIRWISE,
2878 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002879 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002880
Johannes Berg41ade002007-12-19 02:03:29 +01002881 return err;
2882}
2883
2884static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2885{
Johannes Berg4c476992010-10-04 21:36:35 +02002886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002887 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002888 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002889 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002890 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002891
Johannes Bergb9454e82009-07-08 13:29:08 +02002892 err = nl80211_parse_key(info, &key);
2893 if (err)
2894 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002895
2896 if (info->attrs[NL80211_ATTR_MAC])
2897 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2898
Johannes Berge31b8212010-10-05 19:39:30 +02002899 if (key.type == -1) {
2900 if (mac_addr)
2901 key.type = NL80211_KEYTYPE_PAIRWISE;
2902 else
2903 key.type = NL80211_KEYTYPE_GROUP;
2904 }
2905
2906 /* for now */
2907 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2908 key.type != NL80211_KEYTYPE_GROUP)
2909 return -EINVAL;
2910
Johannes Berg4c476992010-10-04 21:36:35 +02002911 if (!rdev->ops->del_key)
2912 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002913
Johannes Bergfffd0932009-07-08 14:22:54 +02002914 wdev_lock(dev->ieee80211_ptr);
2915 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002916
2917 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2918 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2919 err = -ENOENT;
2920
Johannes Bergfffd0932009-07-08 14:22:54 +02002921 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002922 err = rdev_del_key(rdev, dev, key.idx,
2923 key.type == NL80211_KEYTYPE_PAIRWISE,
2924 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002925
Johannes Berg3d23e342009-09-29 23:27:28 +02002926#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002927 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002928 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002929 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002930 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002931 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2932 }
2933#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002934 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002935
Johannes Berg41ade002007-12-19 02:03:29 +01002936 return err;
2937}
2938
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302939/* This function returns an error or the number of nested attributes */
2940static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2941{
2942 struct nlattr *attr;
2943 int n_entries = 0, tmp;
2944
2945 nla_for_each_nested(attr, nl_attr, tmp) {
2946 if (nla_len(attr) != ETH_ALEN)
2947 return -EINVAL;
2948
2949 n_entries++;
2950 }
2951
2952 return n_entries;
2953}
2954
2955/*
2956 * This function parses ACL information and allocates memory for ACL data.
2957 * On successful return, the calling function is responsible to free the
2958 * ACL buffer returned by this function.
2959 */
2960static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2961 struct genl_info *info)
2962{
2963 enum nl80211_acl_policy acl_policy;
2964 struct nlattr *attr;
2965 struct cfg80211_acl_data *acl;
2966 int i = 0, n_entries, tmp;
2967
2968 if (!wiphy->max_acl_mac_addrs)
2969 return ERR_PTR(-EOPNOTSUPP);
2970
2971 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2972 return ERR_PTR(-EINVAL);
2973
2974 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2975 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2976 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2977 return ERR_PTR(-EINVAL);
2978
2979 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2980 return ERR_PTR(-EINVAL);
2981
2982 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2983 if (n_entries < 0)
2984 return ERR_PTR(n_entries);
2985
2986 if (n_entries > wiphy->max_acl_mac_addrs)
2987 return ERR_PTR(-ENOTSUPP);
2988
2989 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2990 GFP_KERNEL);
2991 if (!acl)
2992 return ERR_PTR(-ENOMEM);
2993
2994 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2995 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2996 i++;
2997 }
2998
2999 acl->n_acl_entries = n_entries;
3000 acl->acl_policy = acl_policy;
3001
3002 return acl;
3003}
3004
3005static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3006{
3007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3008 struct net_device *dev = info->user_ptr[1];
3009 struct cfg80211_acl_data *acl;
3010 int err;
3011
3012 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3013 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3014 return -EOPNOTSUPP;
3015
3016 if (!dev->ieee80211_ptr->beacon_interval)
3017 return -EINVAL;
3018
3019 acl = parse_acl_data(&rdev->wiphy, info);
3020 if (IS_ERR(acl))
3021 return PTR_ERR(acl);
3022
3023 err = rdev_set_mac_acl(rdev, dev, acl);
3024
3025 kfree(acl);
3026
3027 return err;
3028}
3029
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003030static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003031 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003032{
Johannes Berg88600202012-02-13 15:17:18 +01003033 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003034
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003035 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3036 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3037 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3038 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003039 return -EINVAL;
3040
Johannes Berg88600202012-02-13 15:17:18 +01003041 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003042
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003043 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3044 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3045 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003046 if (!bcn->head_len)
3047 return -EINVAL;
3048 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003049 }
3050
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003051 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3052 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3053 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003054 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003055 }
3056
Johannes Berg4c476992010-10-04 21:36:35 +02003057 if (!haveinfo)
3058 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003059
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003060 if (attrs[NL80211_ATTR_IE]) {
3061 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3062 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003063 }
3064
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003065 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003066 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003067 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003068 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003069 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003070 }
3071
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003072 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003073 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003074 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003075 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003076 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003077 }
3078
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003079 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3080 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3081 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003082 }
3083
Johannes Berg88600202012-02-13 15:17:18 +01003084 return 0;
3085}
3086
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003087static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3088 struct cfg80211_ap_settings *params)
3089{
3090 struct wireless_dev *wdev;
3091 bool ret = false;
3092
Johannes Berg89a54e42012-06-15 14:33:17 +02003093 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003094 if (wdev->iftype != NL80211_IFTYPE_AP &&
3095 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3096 continue;
3097
Johannes Berg683b6d32012-11-08 21:25:48 +01003098 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003099 continue;
3100
Johannes Berg683b6d32012-11-08 21:25:48 +01003101 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003102 ret = true;
3103 break;
3104 }
3105
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003106 return ret;
3107}
3108
Jouni Malinene39e5b52012-09-30 19:29:39 +03003109static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3110 enum nl80211_auth_type auth_type,
3111 enum nl80211_commands cmd)
3112{
3113 if (auth_type > NL80211_AUTHTYPE_MAX)
3114 return false;
3115
3116 switch (cmd) {
3117 case NL80211_CMD_AUTHENTICATE:
3118 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3119 auth_type == NL80211_AUTHTYPE_SAE)
3120 return false;
3121 return true;
3122 case NL80211_CMD_CONNECT:
3123 case NL80211_CMD_START_AP:
3124 /* SAE not supported yet */
3125 if (auth_type == NL80211_AUTHTYPE_SAE)
3126 return false;
3127 return true;
3128 default:
3129 return false;
3130 }
3131}
3132
Johannes Berg88600202012-02-13 15:17:18 +01003133static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3134{
3135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3136 struct net_device *dev = info->user_ptr[1];
3137 struct wireless_dev *wdev = dev->ieee80211_ptr;
3138 struct cfg80211_ap_settings params;
3139 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003140 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003141
3142 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3143 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3144 return -EOPNOTSUPP;
3145
3146 if (!rdev->ops->start_ap)
3147 return -EOPNOTSUPP;
3148
3149 if (wdev->beacon_interval)
3150 return -EALREADY;
3151
3152 memset(&params, 0, sizeof(params));
3153
3154 /* these are required for START_AP */
3155 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3156 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3157 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3158 return -EINVAL;
3159
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003160 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003161 if (err)
3162 return err;
3163
3164 params.beacon_interval =
3165 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3166 params.dtim_period =
3167 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3168
3169 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3170 if (err)
3171 return err;
3172
3173 /*
3174 * In theory, some of these attributes should be required here
3175 * but since they were not used when the command was originally
3176 * added, keep them optional for old user space programs to let
3177 * them continue to work with drivers that do not need the
3178 * additional information -- drivers must check!
3179 */
3180 if (info->attrs[NL80211_ATTR_SSID]) {
3181 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3182 params.ssid_len =
3183 nla_len(info->attrs[NL80211_ATTR_SSID]);
3184 if (params.ssid_len == 0 ||
3185 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3186 return -EINVAL;
3187 }
3188
3189 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3190 params.hidden_ssid = nla_get_u32(
3191 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3192 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3193 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3194 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3195 return -EINVAL;
3196 }
3197
3198 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3199
3200 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3201 params.auth_type = nla_get_u32(
3202 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003203 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3204 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003205 return -EINVAL;
3206 } else
3207 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3208
3209 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3210 NL80211_MAX_NR_CIPHER_SUITES);
3211 if (err)
3212 return err;
3213
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303214 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3215 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3216 return -EOPNOTSUPP;
3217 params.inactivity_timeout = nla_get_u16(
3218 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3219 }
3220
Johannes Berg53cabad2012-11-14 15:17:28 +01003221 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3222 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3223 return -EINVAL;
3224 params.p2p_ctwindow =
3225 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3226 if (params.p2p_ctwindow > 127)
3227 return -EINVAL;
3228 if (params.p2p_ctwindow != 0 &&
3229 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3230 return -EINVAL;
3231 }
3232
3233 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3234 u8 tmp;
3235
3236 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3237 return -EINVAL;
3238 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3239 if (tmp > 1)
3240 return -EINVAL;
3241 params.p2p_opp_ps = tmp;
3242 if (params.p2p_opp_ps != 0 &&
3243 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3244 return -EINVAL;
3245 }
3246
Johannes Bergaa430da2012-05-16 23:50:18 +02003247 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003248 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3249 if (err)
3250 return err;
3251 } else if (wdev->preset_chandef.chan) {
3252 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003253 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003254 return -EINVAL;
3255
Johannes Berg683b6d32012-11-08 21:25:48 +01003256 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003257 return -EINVAL;
3258
Simon Wunderlich04f39042013-02-08 18:16:19 +01003259 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3260 if (err < 0)
3261 return err;
3262 if (err) {
3263 radar_detect_width = BIT(params.chandef.width);
3264 params.radar_required = true;
3265 }
3266
Simon Wunderlich04f39042013-02-08 18:16:19 +01003267 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3268 params.chandef.chan,
3269 CHAN_MODE_SHARED,
3270 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003271 if (err)
3272 return err;
3273
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303274 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3275 params.acl = parse_acl_data(&rdev->wiphy, info);
3276 if (IS_ERR(params.acl))
3277 return PTR_ERR(params.acl);
3278 }
3279
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003280 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003281 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003282 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003283 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003284 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003285 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003286 wdev->ssid_len = params.ssid_len;
3287 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003288 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003289 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303290
3291 kfree(params.acl);
3292
Johannes Berg56d18932011-05-09 18:41:15 +02003293 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003294}
3295
Johannes Berg88600202012-02-13 15:17:18 +01003296static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3297{
3298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3299 struct net_device *dev = info->user_ptr[1];
3300 struct wireless_dev *wdev = dev->ieee80211_ptr;
3301 struct cfg80211_beacon_data params;
3302 int err;
3303
3304 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3305 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3306 return -EOPNOTSUPP;
3307
3308 if (!rdev->ops->change_beacon)
3309 return -EOPNOTSUPP;
3310
3311 if (!wdev->beacon_interval)
3312 return -EINVAL;
3313
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003314 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003315 if (err)
3316 return err;
3317
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003318 wdev_lock(wdev);
3319 err = rdev_change_beacon(rdev, dev, &params);
3320 wdev_unlock(wdev);
3321
3322 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003323}
3324
3325static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003326{
Johannes Berg4c476992010-10-04 21:36:35 +02003327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3328 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003329
Michal Kazior60771782012-06-29 12:46:56 +02003330 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003331}
3332
Johannes Berg5727ef12007-12-19 02:03:34 +01003333static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3334 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3335 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3336 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003337 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003338 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003339 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003340};
3341
Johannes Bergeccb8e82009-05-11 21:57:56 +03003342static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003343 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003344 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003345{
3346 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003347 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003348 int flag;
3349
Johannes Bergeccb8e82009-05-11 21:57:56 +03003350 /*
3351 * Try parsing the new attribute first so userspace
3352 * can specify both for older kernels.
3353 */
3354 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3355 if (nla) {
3356 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003357
Johannes Bergeccb8e82009-05-11 21:57:56 +03003358 sta_flags = nla_data(nla);
3359 params->sta_flags_mask = sta_flags->mask;
3360 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003361 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003362 if ((params->sta_flags_mask |
3363 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3364 return -EINVAL;
3365 return 0;
3366 }
3367
3368 /* if present, parse the old attribute */
3369
3370 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003371 if (!nla)
3372 return 0;
3373
3374 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3375 nla, sta_flags_policy))
3376 return -EINVAL;
3377
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003378 /*
3379 * Only allow certain flags for interface types so that
3380 * other attributes are silently ignored. Remember that
3381 * this is backward compatibility code with old userspace
3382 * and shouldn't be hit in other cases anyway.
3383 */
3384 switch (iftype) {
3385 case NL80211_IFTYPE_AP:
3386 case NL80211_IFTYPE_AP_VLAN:
3387 case NL80211_IFTYPE_P2P_GO:
3388 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3389 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3390 BIT(NL80211_STA_FLAG_WME) |
3391 BIT(NL80211_STA_FLAG_MFP);
3392 break;
3393 case NL80211_IFTYPE_P2P_CLIENT:
3394 case NL80211_IFTYPE_STATION:
3395 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3396 BIT(NL80211_STA_FLAG_TDLS_PEER);
3397 break;
3398 case NL80211_IFTYPE_MESH_POINT:
3399 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3400 BIT(NL80211_STA_FLAG_MFP) |
3401 BIT(NL80211_STA_FLAG_AUTHORIZED);
3402 default:
3403 return -EINVAL;
3404 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003405
Johannes Berg3383b5a2012-05-10 20:14:43 +02003406 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3407 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003408 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003409
Johannes Berg3383b5a2012-05-10 20:14:43 +02003410 /* no longer support new API additions in old API */
3411 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3412 return -EINVAL;
3413 }
3414 }
3415
Johannes Berg5727ef12007-12-19 02:03:34 +01003416 return 0;
3417}
3418
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003419static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3420 int attr)
3421{
3422 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003423 u32 bitrate;
3424 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003425
3426 rate = nla_nest_start(msg, attr);
3427 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003428 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003429
3430 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3431 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003432 /* report 16-bit bitrate only if we can */
3433 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003434 if (bitrate > 0 &&
3435 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3436 return false;
3437 if (bitrate_compat > 0 &&
3438 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3439 return false;
3440
3441 if (info->flags & RATE_INFO_FLAGS_MCS) {
3442 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3443 return false;
3444 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3445 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3446 return false;
3447 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3448 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3449 return false;
3450 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3451 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3452 return false;
3453 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3454 return false;
3455 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3456 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3457 return false;
3458 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3459 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3460 return false;
3461 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3462 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3463 return false;
3464 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3465 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3466 return false;
3467 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3468 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3469 return false;
3470 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003471
3472 nla_nest_end(msg, rate);
3473 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003474}
3475
Felix Fietkau119363c2013-04-22 16:29:30 +02003476static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3477 int id)
3478{
3479 void *attr;
3480 int i = 0;
3481
3482 if (!mask)
3483 return true;
3484
3485 attr = nla_nest_start(msg, id);
3486 if (!attr)
3487 return false;
3488
3489 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3490 if (!(mask & BIT(i)))
3491 continue;
3492
3493 if (nla_put_u8(msg, i, signal[i]))
3494 return false;
3495 }
3496
3497 nla_nest_end(msg, attr);
3498
3499 return true;
3500}
3501
Eric W. Biederman15e47302012-09-07 20:12:54 +00003502static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003503 int flags,
3504 struct cfg80211_registered_device *rdev,
3505 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003506 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003507{
3508 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003509 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003510
Eric W. Biederman15e47302012-09-07 20:12:54 +00003511 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003512 if (!hdr)
3513 return -1;
3514
David S. Miller9360ffd2012-03-29 04:41:26 -04003515 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3516 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3517 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3518 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003519
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003520 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3521 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003522 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003523 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3524 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3525 sinfo->connected_time))
3526 goto nla_put_failure;
3527 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3528 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3529 sinfo->inactive_time))
3530 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003531 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3532 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003533 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003534 (u32)sinfo->rx_bytes))
3535 goto nla_put_failure;
3536 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003537 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003538 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3539 (u32)sinfo->tx_bytes))
3540 goto nla_put_failure;
3541 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3542 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003543 sinfo->rx_bytes))
3544 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003545 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3546 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003547 sinfo->tx_bytes))
3548 goto nla_put_failure;
3549 if ((sinfo->filled & STATION_INFO_LLID) &&
3550 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3551 goto nla_put_failure;
3552 if ((sinfo->filled & STATION_INFO_PLID) &&
3553 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3554 goto nla_put_failure;
3555 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3556 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3557 sinfo->plink_state))
3558 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003559 switch (rdev->wiphy.signal_type) {
3560 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003561 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3562 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3563 sinfo->signal))
3564 goto nla_put_failure;
3565 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3566 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3567 sinfo->signal_avg))
3568 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003569 break;
3570 default:
3571 break;
3572 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003573 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3574 if (!nl80211_put_signal(msg, sinfo->chains,
3575 sinfo->chain_signal,
3576 NL80211_STA_INFO_CHAIN_SIGNAL))
3577 goto nla_put_failure;
3578 }
3579 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3580 if (!nl80211_put_signal(msg, sinfo->chains,
3581 sinfo->chain_signal_avg,
3582 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3583 goto nla_put_failure;
3584 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003585 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003586 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3587 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003588 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003589 }
3590 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3591 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3592 NL80211_STA_INFO_RX_BITRATE))
3593 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003594 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003595 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3596 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3597 sinfo->rx_packets))
3598 goto nla_put_failure;
3599 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3600 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3601 sinfo->tx_packets))
3602 goto nla_put_failure;
3603 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3604 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3605 sinfo->tx_retries))
3606 goto nla_put_failure;
3607 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3608 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3609 sinfo->tx_failed))
3610 goto nla_put_failure;
3611 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3612 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3613 sinfo->beacon_loss_count))
3614 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003615 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3616 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3617 sinfo->local_pm))
3618 goto nla_put_failure;
3619 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3620 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3621 sinfo->peer_pm))
3622 goto nla_put_failure;
3623 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3624 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3625 sinfo->nonpeer_pm))
3626 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003627 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3628 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3629 if (!bss_param)
3630 goto nla_put_failure;
3631
David S. Miller9360ffd2012-03-29 04:41:26 -04003632 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3633 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3634 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3635 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3636 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3637 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3638 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3639 sinfo->bss_param.dtim_period) ||
3640 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3641 sinfo->bss_param.beacon_interval))
3642 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003643
3644 nla_nest_end(msg, bss_param);
3645 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003646 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3647 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3648 sizeof(struct nl80211_sta_flag_update),
3649 &sinfo->sta_flags))
3650 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003651 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3652 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3653 sinfo->t_offset))
3654 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003655 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003656
David S. Miller9360ffd2012-03-29 04:41:26 -04003657 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3658 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3659 sinfo->assoc_req_ies))
3660 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003661
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003662 return genlmsg_end(msg, hdr);
3663
3664 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003665 genlmsg_cancel(msg, hdr);
3666 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003667}
3668
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003669static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003670 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003671{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003672 struct station_info sinfo;
3673 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003674 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003675 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003676 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003677 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003678
Johannes Berg97990a02013-04-19 01:02:55 +02003679 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003680 if (err)
3681 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003682
Johannes Berg97990a02013-04-19 01:02:55 +02003683 if (!wdev->netdev) {
3684 err = -EINVAL;
3685 goto out_err;
3686 }
3687
Johannes Bergbba95fe2008-07-29 13:22:51 +02003688 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003689 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003690 goto out_err;
3691 }
3692
Johannes Bergbba95fe2008-07-29 13:22:51 +02003693 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003694 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003695 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003696 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003697 if (err == -ENOENT)
3698 break;
3699 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003700 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003701
3702 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003703 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003704 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003705 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003706 &sinfo) < 0)
3707 goto out;
3708
3709 sta_idx++;
3710 }
3711
3712
3713 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003714 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003715 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003716 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003717 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003718
3719 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003720}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003721
Johannes Berg5727ef12007-12-19 02:03:34 +01003722static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3723{
Johannes Berg4c476992010-10-04 21:36:35 +02003724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3725 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003726 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003727 struct sk_buff *msg;
3728 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003729 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003730
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003731 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003732
3733 if (!info->attrs[NL80211_ATTR_MAC])
3734 return -EINVAL;
3735
3736 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3737
Johannes Berg4c476992010-10-04 21:36:35 +02003738 if (!rdev->ops->get_station)
3739 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003740
Hila Gonene35e4d22012-06-27 17:19:42 +03003741 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003742 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003743 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003744
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003745 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003746 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003747 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003748
Eric W. Biederman15e47302012-09-07 20:12:54 +00003749 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003750 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003751 nlmsg_free(msg);
3752 return -ENOBUFS;
3753 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003754
Johannes Berg4c476992010-10-04 21:36:35 +02003755 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003756}
3757
Johannes Berg77ee7c82013-02-15 00:48:33 +01003758int cfg80211_check_station_change(struct wiphy *wiphy,
3759 struct station_parameters *params,
3760 enum cfg80211_station_type statype)
3761{
3762 if (params->listen_interval != -1)
3763 return -EINVAL;
3764 if (params->aid)
3765 return -EINVAL;
3766
3767 /* When you run into this, adjust the code below for the new flag */
3768 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3769
3770 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003771 case CFG80211_STA_MESH_PEER_KERNEL:
3772 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003773 /*
3774 * No ignoring the TDLS flag here -- the userspace mesh
3775 * code doesn't have the bug of including TDLS in the
3776 * mask everywhere.
3777 */
3778 if (params->sta_flags_mask &
3779 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3780 BIT(NL80211_STA_FLAG_MFP) |
3781 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3782 return -EINVAL;
3783 break;
3784 case CFG80211_STA_TDLS_PEER_SETUP:
3785 case CFG80211_STA_TDLS_PEER_ACTIVE:
3786 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3787 return -EINVAL;
3788 /* ignore since it can't change */
3789 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3790 break;
3791 default:
3792 /* disallow mesh-specific things */
3793 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3794 return -EINVAL;
3795 if (params->local_pm)
3796 return -EINVAL;
3797 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3798 return -EINVAL;
3799 }
3800
3801 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3802 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3803 /* TDLS can't be set, ... */
3804 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3805 return -EINVAL;
3806 /*
3807 * ... but don't bother the driver with it. This works around
3808 * a hostapd/wpa_supplicant issue -- it always includes the
3809 * TLDS_PEER flag in the mask even for AP mode.
3810 */
3811 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3812 }
3813
3814 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3815 /* reject other things that can't change */
3816 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3817 return -EINVAL;
3818 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3819 return -EINVAL;
3820 if (params->supported_rates)
3821 return -EINVAL;
3822 if (params->ext_capab || params->ht_capa || params->vht_capa)
3823 return -EINVAL;
3824 }
3825
3826 if (statype != CFG80211_STA_AP_CLIENT) {
3827 if (params->vlan)
3828 return -EINVAL;
3829 }
3830
3831 switch (statype) {
3832 case CFG80211_STA_AP_MLME_CLIENT:
3833 /* Use this only for authorizing/unauthorizing a station */
3834 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3835 return -EOPNOTSUPP;
3836 break;
3837 case CFG80211_STA_AP_CLIENT:
3838 /* accept only the listed bits */
3839 if (params->sta_flags_mask &
3840 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3841 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3842 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3843 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3844 BIT(NL80211_STA_FLAG_WME) |
3845 BIT(NL80211_STA_FLAG_MFP)))
3846 return -EINVAL;
3847
3848 /* but authenticated/associated only if driver handles it */
3849 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3850 params->sta_flags_mask &
3851 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3852 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3853 return -EINVAL;
3854 break;
3855 case CFG80211_STA_IBSS:
3856 case CFG80211_STA_AP_STA:
3857 /* reject any changes other than AUTHORIZED */
3858 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3859 return -EINVAL;
3860 break;
3861 case CFG80211_STA_TDLS_PEER_SETUP:
3862 /* reject any changes other than AUTHORIZED or WME */
3863 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3864 BIT(NL80211_STA_FLAG_WME)))
3865 return -EINVAL;
3866 /* force (at least) rates when authorizing */
3867 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3868 !params->supported_rates)
3869 return -EINVAL;
3870 break;
3871 case CFG80211_STA_TDLS_PEER_ACTIVE:
3872 /* reject any changes */
3873 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003874 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003875 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3876 return -EINVAL;
3877 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003878 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003879 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3880 return -EINVAL;
3881 break;
3882 }
3883
3884 return 0;
3885}
3886EXPORT_SYMBOL(cfg80211_check_station_change);
3887
Johannes Berg5727ef12007-12-19 02:03:34 +01003888/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003889 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003890 */
Johannes Berg80b99892011-11-18 16:23:01 +01003891static struct net_device *get_vlan(struct genl_info *info,
3892 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003893{
Johannes Berg463d0182009-07-14 00:33:35 +02003894 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003895 struct net_device *v;
3896 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003897
Johannes Berg80b99892011-11-18 16:23:01 +01003898 if (!vlanattr)
3899 return NULL;
3900
3901 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3902 if (!v)
3903 return ERR_PTR(-ENODEV);
3904
3905 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3906 ret = -EINVAL;
3907 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003908 }
Johannes Berg80b99892011-11-18 16:23:01 +01003909
Johannes Berg77ee7c82013-02-15 00:48:33 +01003910 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3911 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3912 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3913 ret = -EINVAL;
3914 goto error;
3915 }
3916
Johannes Berg80b99892011-11-18 16:23:01 +01003917 if (!netif_running(v)) {
3918 ret = -ENETDOWN;
3919 goto error;
3920 }
3921
3922 return v;
3923 error:
3924 dev_put(v);
3925 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003926}
3927
Johannes Berg94e860f2014-01-20 23:58:15 +01003928static const struct nla_policy
3929nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003930 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3931 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3932};
3933
Johannes Bergff276692013-02-15 00:09:01 +01003934static int nl80211_parse_sta_wme(struct genl_info *info,
3935 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003936{
Jouni Malinendf881292013-02-14 21:10:54 +02003937 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3938 struct nlattr *nla;
3939 int err;
3940
Jouni Malinendf881292013-02-14 21:10:54 +02003941 /* parse WME attributes if present */
3942 if (!info->attrs[NL80211_ATTR_STA_WME])
3943 return 0;
3944
3945 nla = info->attrs[NL80211_ATTR_STA_WME];
3946 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3947 nl80211_sta_wme_policy);
3948 if (err)
3949 return err;
3950
3951 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3952 params->uapsd_queues = nla_get_u8(
3953 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3954 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3955 return -EINVAL;
3956
3957 if (tb[NL80211_STA_WME_MAX_SP])
3958 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3959
3960 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3961 return -EINVAL;
3962
3963 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3964
3965 return 0;
3966}
3967
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303968static int nl80211_parse_sta_channel_info(struct genl_info *info,
3969 struct station_parameters *params)
3970{
3971 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3972 params->supported_channels =
3973 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3974 params->supported_channels_len =
3975 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3976 /*
3977 * Need to include at least one (first channel, number of
3978 * channels) tuple for each subband, and must have proper
3979 * tuples for the rest of the data as well.
3980 */
3981 if (params->supported_channels_len < 2)
3982 return -EINVAL;
3983 if (params->supported_channels_len % 2)
3984 return -EINVAL;
3985 }
3986
3987 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3988 params->supported_oper_classes =
3989 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3990 params->supported_oper_classes_len =
3991 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3992 /*
3993 * The value of the Length field of the Supported Operating
3994 * Classes element is between 2 and 253.
3995 */
3996 if (params->supported_oper_classes_len < 2 ||
3997 params->supported_oper_classes_len > 253)
3998 return -EINVAL;
3999 }
4000 return 0;
4001}
4002
Johannes Bergff276692013-02-15 00:09:01 +01004003static int nl80211_set_station_tdls(struct genl_info *info,
4004 struct station_parameters *params)
4005{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304006 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004007 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004008 if (info->attrs[NL80211_ATTR_PEER_AID])
4009 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004010 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4011 params->ht_capa =
4012 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4014 params->vht_capa =
4015 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4016
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304017 err = nl80211_parse_sta_channel_info(info, params);
4018 if (err)
4019 return err;
4020
Johannes Bergff276692013-02-15 00:09:01 +01004021 return nl80211_parse_sta_wme(info, params);
4022}
4023
Johannes Berg5727ef12007-12-19 02:03:34 +01004024static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4025{
Johannes Berg4c476992010-10-04 21:36:35 +02004026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004027 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004028 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004029 u8 *mac_addr;
4030 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004031
4032 memset(&params, 0, sizeof(params));
4033
4034 params.listen_interval = -1;
4035
Johannes Berg77ee7c82013-02-15 00:48:33 +01004036 if (!rdev->ops->change_station)
4037 return -EOPNOTSUPP;
4038
Johannes Berg5727ef12007-12-19 02:03:34 +01004039 if (info->attrs[NL80211_ATTR_STA_AID])
4040 return -EINVAL;
4041
4042 if (!info->attrs[NL80211_ATTR_MAC])
4043 return -EINVAL;
4044
4045 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4046
4047 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4048 params.supported_rates =
4049 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4050 params.supported_rates_len =
4051 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4052 }
4053
Jouni Malinen9d62a982013-02-14 21:10:13 +02004054 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4055 params.capability =
4056 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4057 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4058 }
4059
4060 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4061 params.ext_capab =
4062 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4063 params.ext_capab_len =
4064 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4065 }
4066
Jouni Malinendf881292013-02-14 21:10:54 +02004067 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004068 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004069
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004070 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004071 return -EINVAL;
4072
Johannes Bergf8bacc22013-02-14 23:27:01 +01004073 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004074 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004075 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4076 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4077 return -EINVAL;
4078 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004079
Johannes Bergf8bacc22013-02-14 23:27:01 +01004080 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004081 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004082 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4083 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4084 return -EINVAL;
4085 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4086 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004087
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004088 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4089 enum nl80211_mesh_power_mode pm = nla_get_u32(
4090 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4091
4092 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4093 pm > NL80211_MESH_POWER_MAX)
4094 return -EINVAL;
4095
4096 params.local_pm = pm;
4097 }
4098
Johannes Berg77ee7c82013-02-15 00:48:33 +01004099 /* Include parameters for TDLS peer (will check later) */
4100 err = nl80211_set_station_tdls(info, &params);
4101 if (err)
4102 return err;
4103
4104 params.vlan = get_vlan(info, rdev);
4105 if (IS_ERR(params.vlan))
4106 return PTR_ERR(params.vlan);
4107
Johannes Berga97f4422009-06-18 17:23:43 +02004108 switch (dev->ieee80211_ptr->iftype) {
4109 case NL80211_IFTYPE_AP:
4110 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004111 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004112 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004113 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004114 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004115 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004116 break;
4117 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004118 err = -EOPNOTSUPP;
4119 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004120 }
4121
Johannes Berg77ee7c82013-02-15 00:48:33 +01004122 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004123 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004124
Johannes Berg77ee7c82013-02-15 00:48:33 +01004125 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004126 if (params.vlan)
4127 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004128
Johannes Berg5727ef12007-12-19 02:03:34 +01004129 return err;
4130}
4131
4132static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4133{
Johannes Berg4c476992010-10-04 21:36:35 +02004134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004135 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004136 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004137 struct station_parameters params;
4138 u8 *mac_addr = NULL;
4139
4140 memset(&params, 0, sizeof(params));
4141
Johannes Berg984c3112013-02-14 23:43:25 +01004142 if (!rdev->ops->add_station)
4143 return -EOPNOTSUPP;
4144
Johannes Berg5727ef12007-12-19 02:03:34 +01004145 if (!info->attrs[NL80211_ATTR_MAC])
4146 return -EINVAL;
4147
Johannes Berg5727ef12007-12-19 02:03:34 +01004148 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4149 return -EINVAL;
4150
4151 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4152 return -EINVAL;
4153
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004154 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4155 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004156 return -EINVAL;
4157
Johannes Berg5727ef12007-12-19 02:03:34 +01004158 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4159 params.supported_rates =
4160 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4161 params.supported_rates_len =
4162 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4163 params.listen_interval =
4164 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004165
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004166 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004167 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004168 else
4169 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004170 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4171 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004172
Jouni Malinen9d62a982013-02-14 21:10:13 +02004173 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4174 params.capability =
4175 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4176 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4177 }
4178
4179 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4180 params.ext_capab =
4181 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4182 params.ext_capab_len =
4183 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4184 }
4185
Jouni Malinen36aedc92008-08-25 11:58:58 +03004186 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4187 params.ht_capa =
4188 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004189
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004190 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4191 params.vht_capa =
4192 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4193
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004194 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4195 params.opmode_notif_used = true;
4196 params.opmode_notif =
4197 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4198 }
4199
Johannes Bergf8bacc22013-02-14 23:27:01 +01004200 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004201 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004202 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4203 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4204 return -EINVAL;
4205 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004206
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304207 err = nl80211_parse_sta_channel_info(info, &params);
4208 if (err)
4209 return err;
4210
Johannes Bergff276692013-02-15 00:09:01 +01004211 err = nl80211_parse_sta_wme(info, &params);
4212 if (err)
4213 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004214
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004215 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004216 return -EINVAL;
4217
Johannes Berg77ee7c82013-02-15 00:48:33 +01004218 /* When you run into this, adjust the code below for the new flag */
4219 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4220
Johannes Bergbdd90d52011-12-14 12:20:27 +01004221 switch (dev->ieee80211_ptr->iftype) {
4222 case NL80211_IFTYPE_AP:
4223 case NL80211_IFTYPE_AP_VLAN:
4224 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004225 /* ignore WME attributes if iface/sta is not capable */
4226 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4227 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4228 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004229
Johannes Bergbdd90d52011-12-14 12:20:27 +01004230 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004231 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4232 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004233 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004234 /* but don't bother the driver with it */
4235 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004236
Johannes Bergd582cff2012-10-26 17:53:44 +02004237 /* allow authenticated/associated only if driver handles it */
4238 if (!(rdev->wiphy.features &
4239 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4240 params.sta_flags_mask &
4241 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4242 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4243 return -EINVAL;
4244
Johannes Bergbdd90d52011-12-14 12:20:27 +01004245 /* must be last in here for error handling */
4246 params.vlan = get_vlan(info, rdev);
4247 if (IS_ERR(params.vlan))
4248 return PTR_ERR(params.vlan);
4249 break;
4250 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004251 /* ignore uAPSD data */
4252 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4253
Johannes Bergd582cff2012-10-26 17:53:44 +02004254 /* associated is disallowed */
4255 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4256 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004257 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004258 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4259 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004260 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004261 break;
4262 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004263 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004264 /* ignore uAPSD data */
4265 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4266
Johannes Berg77ee7c82013-02-15 00:48:33 +01004267 /* these are disallowed */
4268 if (params.sta_flags_mask &
4269 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4270 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004271 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004272 /* Only TDLS peers can be added */
4273 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4274 return -EINVAL;
4275 /* Can only add if TDLS ... */
4276 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4277 return -EOPNOTSUPP;
4278 /* ... with external setup is supported */
4279 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4280 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004281 /*
4282 * Older wpa_supplicant versions always mark the TDLS peer
4283 * as authorized, but it shouldn't yet be.
4284 */
4285 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004286 break;
4287 default:
4288 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004289 }
4290
Johannes Bergbdd90d52011-12-14 12:20:27 +01004291 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004292
Hila Gonene35e4d22012-06-27 17:19:42 +03004293 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004294
Johannes Berg5727ef12007-12-19 02:03:34 +01004295 if (params.vlan)
4296 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004297 return err;
4298}
4299
4300static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4301{
Johannes Berg4c476992010-10-04 21:36:35 +02004302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4303 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004304 u8 *mac_addr = NULL;
4305
4306 if (info->attrs[NL80211_ATTR_MAC])
4307 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4308
Johannes Berge80cf852009-05-11 14:43:13 +02004309 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004310 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004311 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004312 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4313 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004314
Johannes Berg4c476992010-10-04 21:36:35 +02004315 if (!rdev->ops->del_station)
4316 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004317
Hila Gonene35e4d22012-06-27 17:19:42 +03004318 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004319}
4320
Eric W. Biederman15e47302012-09-07 20:12:54 +00004321static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004322 int flags, struct net_device *dev,
4323 u8 *dst, u8 *next_hop,
4324 struct mpath_info *pinfo)
4325{
4326 void *hdr;
4327 struct nlattr *pinfoattr;
4328
Eric W. Biederman15e47302012-09-07 20:12:54 +00004329 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004330 if (!hdr)
4331 return -1;
4332
David S. Miller9360ffd2012-03-29 04:41:26 -04004333 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4334 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4335 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4336 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4337 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004338
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004339 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4340 if (!pinfoattr)
4341 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004342 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4343 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4344 pinfo->frame_qlen))
4345 goto nla_put_failure;
4346 if (((pinfo->filled & MPATH_INFO_SN) &&
4347 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4348 ((pinfo->filled & MPATH_INFO_METRIC) &&
4349 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4350 pinfo->metric)) ||
4351 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4352 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4353 pinfo->exptime)) ||
4354 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4355 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4356 pinfo->flags)) ||
4357 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4358 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4359 pinfo->discovery_timeout)) ||
4360 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4361 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4362 pinfo->discovery_retries)))
4363 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004364
4365 nla_nest_end(msg, pinfoattr);
4366
4367 return genlmsg_end(msg, hdr);
4368
4369 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004370 genlmsg_cancel(msg, hdr);
4371 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004372}
4373
4374static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004375 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004377 struct mpath_info pinfo;
4378 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004379 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004380 u8 dst[ETH_ALEN];
4381 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004382 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004384
Johannes Berg97990a02013-04-19 01:02:55 +02004385 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004386 if (err)
4387 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004388
4389 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004390 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004391 goto out_err;
4392 }
4393
Johannes Berg97990a02013-04-19 01:02:55 +02004394 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004395 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004396 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004397 }
4398
Johannes Bergbba95fe2008-07-29 13:22:51 +02004399 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004400 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4401 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004402 if (err == -ENOENT)
4403 break;
4404 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004405 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004406
Eric W. Biederman15e47302012-09-07 20:12:54 +00004407 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004408 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004409 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004410 &pinfo) < 0)
4411 goto out;
4412
4413 path_idx++;
4414 }
4415
4416
4417 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004418 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004419 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004420 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004421 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004422 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004423}
4424
4425static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4426{
Johannes Berg4c476992010-10-04 21:36:35 +02004427 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004428 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004429 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004430 struct mpath_info pinfo;
4431 struct sk_buff *msg;
4432 u8 *dst = NULL;
4433 u8 next_hop[ETH_ALEN];
4434
4435 memset(&pinfo, 0, sizeof(pinfo));
4436
4437 if (!info->attrs[NL80211_ATTR_MAC])
4438 return -EINVAL;
4439
4440 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4441
Johannes Berg4c476992010-10-04 21:36:35 +02004442 if (!rdev->ops->get_mpath)
4443 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004444
Johannes Berg4c476992010-10-04 21:36:35 +02004445 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4446 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004447
Hila Gonene35e4d22012-06-27 17:19:42 +03004448 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004449 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004450 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004451
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004452 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004453 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004454 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004455
Eric W. Biederman15e47302012-09-07 20:12:54 +00004456 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004457 dev, dst, next_hop, &pinfo) < 0) {
4458 nlmsg_free(msg);
4459 return -ENOBUFS;
4460 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004461
Johannes Berg4c476992010-10-04 21:36:35 +02004462 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004463}
4464
4465static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4466{
Johannes Berg4c476992010-10-04 21:36:35 +02004467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4468 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004469 u8 *dst = NULL;
4470 u8 *next_hop = NULL;
4471
4472 if (!info->attrs[NL80211_ATTR_MAC])
4473 return -EINVAL;
4474
4475 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4476 return -EINVAL;
4477
4478 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4479 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4480
Johannes Berg4c476992010-10-04 21:36:35 +02004481 if (!rdev->ops->change_mpath)
4482 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004483
Johannes Berg4c476992010-10-04 21:36:35 +02004484 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4485 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004486
Hila Gonene35e4d22012-06-27 17:19:42 +03004487 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004488}
Johannes Berg4c476992010-10-04 21:36:35 +02004489
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004490static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4491{
Johannes Berg4c476992010-10-04 21:36:35 +02004492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4493 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004494 u8 *dst = NULL;
4495 u8 *next_hop = NULL;
4496
4497 if (!info->attrs[NL80211_ATTR_MAC])
4498 return -EINVAL;
4499
4500 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4501 return -EINVAL;
4502
4503 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4504 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4505
Johannes Berg4c476992010-10-04 21:36:35 +02004506 if (!rdev->ops->add_mpath)
4507 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004508
Johannes Berg4c476992010-10-04 21:36:35 +02004509 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4510 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004511
Hila Gonene35e4d22012-06-27 17:19:42 +03004512 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004513}
4514
4515static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4516{
Johannes Berg4c476992010-10-04 21:36:35 +02004517 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4518 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004519 u8 *dst = NULL;
4520
4521 if (info->attrs[NL80211_ATTR_MAC])
4522 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4523
Johannes Berg4c476992010-10-04 21:36:35 +02004524 if (!rdev->ops->del_mpath)
4525 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004526
Hila Gonene35e4d22012-06-27 17:19:42 +03004527 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004528}
4529
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004530static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4531{
Johannes Berg4c476992010-10-04 21:36:35 +02004532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4533 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004534 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004535 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004536 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004537
4538 memset(&params, 0, sizeof(params));
4539 /* default to not changing parameters */
4540 params.use_cts_prot = -1;
4541 params.use_short_preamble = -1;
4542 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004543 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004544 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004545 params.p2p_ctwindow = -1;
4546 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004547
4548 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4549 params.use_cts_prot =
4550 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4551 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4552 params.use_short_preamble =
4553 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4554 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4555 params.use_short_slot_time =
4556 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004557 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4558 params.basic_rates =
4559 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4560 params.basic_rates_len =
4561 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4562 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004563 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4564 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004565 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4566 params.ht_opmode =
4567 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004568
Johannes Berg53cabad2012-11-14 15:17:28 +01004569 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4570 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4571 return -EINVAL;
4572 params.p2p_ctwindow =
4573 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4574 if (params.p2p_ctwindow < 0)
4575 return -EINVAL;
4576 if (params.p2p_ctwindow != 0 &&
4577 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4578 return -EINVAL;
4579 }
4580
4581 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4582 u8 tmp;
4583
4584 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4585 return -EINVAL;
4586 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4587 if (tmp > 1)
4588 return -EINVAL;
4589 params.p2p_opp_ps = tmp;
4590 if (params.p2p_opp_ps &&
4591 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4592 return -EINVAL;
4593 }
4594
Johannes Berg4c476992010-10-04 21:36:35 +02004595 if (!rdev->ops->change_bss)
4596 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004597
Johannes Berg074ac8d2010-09-16 14:58:22 +02004598 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004599 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4600 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004601
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004602 wdev_lock(wdev);
4603 err = rdev_change_bss(rdev, dev, &params);
4604 wdev_unlock(wdev);
4605
4606 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004607}
4608
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004609static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004610 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4611 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4612 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4613 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4614 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4615 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4616};
4617
4618static int parse_reg_rule(struct nlattr *tb[],
4619 struct ieee80211_reg_rule *reg_rule)
4620{
4621 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4622 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4623
4624 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4625 return -EINVAL;
4626 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4627 return -EINVAL;
4628 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4629 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004630 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4631 return -EINVAL;
4632
4633 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4634
4635 freq_range->start_freq_khz =
4636 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4637 freq_range->end_freq_khz =
4638 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzic97524822014-01-30 09:52:20 +01004639 if (tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4640 freq_range->max_bandwidth_khz =
4641 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004642
4643 power_rule->max_eirp =
4644 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4645
4646 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4647 power_rule->max_antenna_gain =
4648 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4649
4650 return 0;
4651}
4652
4653static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4654{
4655 int r;
4656 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004657 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004658
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004659 /*
4660 * You should only get this when cfg80211 hasn't yet initialized
4661 * completely when built-in to the kernel right between the time
4662 * window between nl80211_init() and regulatory_init(), if that is
4663 * even possible.
4664 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004665 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004666 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004667
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004668 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4669 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004670
4671 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4672
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004673 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4674 user_reg_hint_type =
4675 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4676 else
4677 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4678
4679 switch (user_reg_hint_type) {
4680 case NL80211_USER_REG_HINT_USER:
4681 case NL80211_USER_REG_HINT_CELL_BASE:
4682 break;
4683 default:
4684 return -EINVAL;
4685 }
4686
4687 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004688
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004689 return r;
4690}
4691
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004692static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004693 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004694{
Johannes Berg4c476992010-10-04 21:36:35 +02004695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004696 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004697 struct wireless_dev *wdev = dev->ieee80211_ptr;
4698 struct mesh_config cur_params;
4699 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004700 void *hdr;
4701 struct nlattr *pinfoattr;
4702 struct sk_buff *msg;
4703
Johannes Berg29cbe682010-12-03 09:20:44 +01004704 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4705 return -EOPNOTSUPP;
4706
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004707 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004708 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004709
Johannes Berg29cbe682010-12-03 09:20:44 +01004710 wdev_lock(wdev);
4711 /* If not connected, get default parameters */
4712 if (!wdev->mesh_id_len)
4713 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4714 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004715 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004716 wdev_unlock(wdev);
4717
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004719 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004720
4721 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004723 if (!msg)
4724 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004725 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004726 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004727 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004728 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004729 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004730 if (!pinfoattr)
4731 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004732 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4733 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4734 cur_params.dot11MeshRetryTimeout) ||
4735 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4736 cur_params.dot11MeshConfirmTimeout) ||
4737 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4738 cur_params.dot11MeshHoldingTimeout) ||
4739 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4740 cur_params.dot11MeshMaxPeerLinks) ||
4741 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4742 cur_params.dot11MeshMaxRetries) ||
4743 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4744 cur_params.dot11MeshTTL) ||
4745 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4746 cur_params.element_ttl) ||
4747 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4748 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004749 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4750 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004751 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4752 cur_params.dot11MeshHWMPmaxPREQretries) ||
4753 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4754 cur_params.path_refresh_time) ||
4755 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4756 cur_params.min_discovery_timeout) ||
4757 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4758 cur_params.dot11MeshHWMPactivePathTimeout) ||
4759 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4760 cur_params.dot11MeshHWMPpreqMinInterval) ||
4761 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4762 cur_params.dot11MeshHWMPperrMinInterval) ||
4763 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4764 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4765 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4766 cur_params.dot11MeshHWMPRootMode) ||
4767 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4768 cur_params.dot11MeshHWMPRannInterval) ||
4769 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4770 cur_params.dot11MeshGateAnnouncementProtocol) ||
4771 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4772 cur_params.dot11MeshForwarding) ||
4773 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004774 cur_params.rssi_threshold) ||
4775 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004776 cur_params.ht_opmode) ||
4777 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4778 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4779 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004780 cur_params.dot11MeshHWMProotInterval) ||
4781 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004782 cur_params.dot11MeshHWMPconfirmationInterval) ||
4783 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4784 cur_params.power_mode) ||
4785 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004786 cur_params.dot11MeshAwakeWindowDuration) ||
4787 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4788 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004789 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 nla_nest_end(msg, pinfoattr);
4791 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004792 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004793
Johannes Berg3b858752009-03-12 09:55:09 +01004794 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004795 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004796 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004797 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004798 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004799}
4800
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004801static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004802 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4803 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4804 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4805 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4806 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4807 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004808 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004809 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004810 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004811 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4812 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4813 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4814 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4815 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004816 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004817 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004818 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004819 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004820 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004821 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004822 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4823 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004824 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4825 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004826 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004827 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4828 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004829 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004830};
4831
Javier Cardonac80d5452010-12-16 17:37:49 -08004832static const struct nla_policy
4833 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004834 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004835 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4836 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004837 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004838 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004839 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004840 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004841 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004842 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004843};
4844
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004845static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004846 struct mesh_config *cfg,
4847 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004848{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004850 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004851
Marco Porschea54fba2013-01-07 16:04:48 +01004852#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4853do { \
4854 if (tb[attr]) { \
4855 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4856 return -EINVAL; \
4857 cfg->param = fn(tb[attr]); \
4858 mask |= (1 << (attr - 1)); \
4859 } \
4860} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004861
4862
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004863 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004864 return -EINVAL;
4865 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004866 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004867 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004868 return -EINVAL;
4869
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004870 /* This makes sure that there aren't more than 32 mesh config
4871 * parameters (otherwise our bitfield scheme would not work.) */
4872 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4873
4874 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004875 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004876 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4877 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004878 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004879 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4880 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004882 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4883 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004885 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4886 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004888 mask, NL80211_MESHCONF_MAX_RETRIES,
4889 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004891 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004892 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004893 mask, NL80211_MESHCONF_ELEMENT_TTL,
4894 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004895 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004896 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4897 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004898 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4899 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004900 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4901 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004903 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4904 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004905 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004906 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4907 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004908 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004909 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4910 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004911 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4912 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004913 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4914 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004915 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004916 1, 65535, mask,
4917 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004918 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004919 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004920 1, 65535, mask,
4921 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004922 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004924 dot11MeshHWMPnetDiameterTraversalTime,
4925 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004926 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4927 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4929 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4930 nla_get_u8);
4931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4932 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004933 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004934 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004935 dot11MeshGateAnnouncementProtocol, 0, 1,
4936 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004937 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004939 mask, NL80211_MESHCONF_FORWARDING,
4940 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004942 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004943 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004945 mask, NL80211_MESHCONF_HT_OPMODE,
4946 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004948 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004949 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4950 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004951 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004952 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4953 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004954 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004955 dot11MeshHWMPconfirmationInterval,
4956 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004957 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4958 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4960 NL80211_MESH_POWER_ACTIVE,
4961 NL80211_MESH_POWER_MAX,
4962 mask, NL80211_MESHCONF_POWER_MODE,
4963 nla_get_u32);
4964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4965 0, 65535, mask,
4966 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4968 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4969 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004970 if (mask_out)
4971 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004972
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004973 return 0;
4974
4975#undef FILL_IN_MESH_PARAM_IF_SET
4976}
4977
Javier Cardonac80d5452010-12-16 17:37:49 -08004978static int nl80211_parse_mesh_setup(struct genl_info *info,
4979 struct mesh_setup *setup)
4980{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004982 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4983
4984 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4985 return -EINVAL;
4986 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4987 info->attrs[NL80211_ATTR_MESH_SETUP],
4988 nl80211_mesh_setup_params_policy))
4989 return -EINVAL;
4990
Javier Cardonad299a1f2012-03-31 11:31:33 -07004991 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4992 setup->sync_method =
4993 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4994 IEEE80211_SYNC_METHOD_VENDOR :
4995 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4996
Javier Cardonac80d5452010-12-16 17:37:49 -08004997 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4998 setup->path_sel_proto =
4999 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5000 IEEE80211_PATH_PROTOCOL_VENDOR :
5001 IEEE80211_PATH_PROTOCOL_HWMP;
5002
5003 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5004 setup->path_metric =
5005 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5006 IEEE80211_PATH_METRIC_VENDOR :
5007 IEEE80211_PATH_METRIC_AIRTIME;
5008
Javier Cardona581a8b02011-04-07 15:08:27 -07005009
5010 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005011 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005012 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005013 if (!is_valid_ie_attr(ieattr))
5014 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005015 setup->ie = nla_data(ieattr);
5016 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005017 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005018 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5019 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5020 return -EINVAL;
5021 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005022 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5023 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005024 if (setup->is_secure)
5025 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005026
Colleen Twitty6e16d902013-05-08 11:45:59 -07005027 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5028 if (!setup->user_mpm)
5029 return -EINVAL;
5030 setup->auth_id =
5031 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5032 }
5033
Javier Cardonac80d5452010-12-16 17:37:49 -08005034 return 0;
5035}
5036
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005037static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005038 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005039{
5040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5041 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005042 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005043 struct mesh_config cfg;
5044 u32 mask;
5045 int err;
5046
Johannes Berg29cbe682010-12-03 09:20:44 +01005047 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5048 return -EOPNOTSUPP;
5049
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005050 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005051 return -EOPNOTSUPP;
5052
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005053 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005054 if (err)
5055 return err;
5056
Johannes Berg29cbe682010-12-03 09:20:44 +01005057 wdev_lock(wdev);
5058 if (!wdev->mesh_id_len)
5059 err = -ENOLINK;
5060
5061 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005062 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005063
5064 wdev_unlock(wdev);
5065
5066 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005067}
5068
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005069static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5070{
Johannes Berg458f4f92012-12-06 15:47:38 +01005071 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005072 struct sk_buff *msg;
5073 void *hdr = NULL;
5074 struct nlattr *nl_reg_rules;
5075 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005076
5077 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005078 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005079
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005081 if (!msg)
5082 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005083
Eric W. Biederman15e47302012-09-07 20:12:54 +00005084 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005085 NL80211_CMD_GET_REG);
5086 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005087 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005088
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005089 if (reg_last_request_cell_base() &&
5090 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5091 NL80211_USER_REG_HINT_CELL_BASE))
5092 goto nla_put_failure;
5093
Johannes Berg458f4f92012-12-06 15:47:38 +01005094 rcu_read_lock();
5095 regdom = rcu_dereference(cfg80211_regdomain);
5096
5097 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5098 (regdom->dfs_region &&
5099 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5100 goto nla_put_failure_rcu;
5101
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005102 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5103 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005104 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005105
Johannes Berg458f4f92012-12-06 15:47:38 +01005106 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005107 struct nlattr *nl_reg_rule;
5108 const struct ieee80211_reg_rule *reg_rule;
5109 const struct ieee80211_freq_range *freq_range;
5110 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005111 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005112
Johannes Berg458f4f92012-12-06 15:47:38 +01005113 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005114 freq_range = &reg_rule->freq_range;
5115 power_rule = &reg_rule->power_rule;
5116
5117 nl_reg_rule = nla_nest_start(msg, i);
5118 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005119 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005120
Janusz Dziedzic97524822014-01-30 09:52:20 +01005121 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5122 if (!max_bandwidth_khz)
5123 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5124 reg_rule);
5125
David S. Miller9360ffd2012-03-29 04:41:26 -04005126 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5127 reg_rule->flags) ||
5128 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5129 freq_range->start_freq_khz) ||
5130 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5131 freq_range->end_freq_khz) ||
5132 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005133 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005134 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5135 power_rule->max_antenna_gain) ||
5136 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5137 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005138 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005139
5140 nla_nest_end(msg, nl_reg_rule);
5141 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005142 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005143
5144 nla_nest_end(msg, nl_reg_rules);
5145
5146 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005147 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005148
Johannes Berg458f4f92012-12-06 15:47:38 +01005149nla_put_failure_rcu:
5150 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005151nla_put_failure:
5152 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005153put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005154 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005155 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005156}
5157
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005158static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5159{
5160 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5161 struct nlattr *nl_reg_rule;
5162 char *alpha2 = NULL;
5163 int rem_reg_rules = 0, r = 0;
5164 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005165 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005166 struct ieee80211_regdomain *rd = NULL;
5167
5168 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5169 return -EINVAL;
5170
5171 if (!info->attrs[NL80211_ATTR_REG_RULES])
5172 return -EINVAL;
5173
5174 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5175
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005176 if (info->attrs[NL80211_ATTR_DFS_REGION])
5177 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5178
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005179 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005180 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005181 num_rules++;
5182 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005183 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005184 }
5185
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005186 if (!reg_is_valid_request(alpha2))
5187 return -EINVAL;
5188
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005189 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005190 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005191
5192 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005193 if (!rd)
5194 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005195
5196 rd->n_reg_rules = num_rules;
5197 rd->alpha2[0] = alpha2[0];
5198 rd->alpha2[1] = alpha2[1];
5199
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005200 /*
5201 * Disable DFS master mode if the DFS region was
5202 * not supported or known on this kernel.
5203 */
5204 if (reg_supported_dfs_region(dfs_region))
5205 rd->dfs_region = dfs_region;
5206
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005207 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005208 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005209 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5210 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5211 reg_rule_policy);
5212 if (r)
5213 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005214 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5215 if (r)
5216 goto bad_reg;
5217
5218 rule_idx++;
5219
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005220 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5221 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005222 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005223 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005224 }
5225
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005226 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005227 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005228 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005229
Johannes Bergd2372b32008-10-24 20:32:20 +02005230 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005231 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005232 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005233}
5234
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005235static int validate_scan_freqs(struct nlattr *freqs)
5236{
5237 struct nlattr *attr1, *attr2;
5238 int n_channels = 0, tmp1, tmp2;
5239
5240 nla_for_each_nested(attr1, freqs, tmp1) {
5241 n_channels++;
5242 /*
5243 * Some hardware has a limited channel list for
5244 * scanning, and it is pretty much nonsensical
5245 * to scan for a channel twice, so disallow that
5246 * and don't require drivers to check that the
5247 * channel list they get isn't longer than what
5248 * they can scan, as long as they can scan all
5249 * the channels they registered at once.
5250 */
5251 nla_for_each_nested(attr2, freqs, tmp2)
5252 if (attr1 != attr2 &&
5253 nla_get_u32(attr1) == nla_get_u32(attr2))
5254 return 0;
5255 }
5256
5257 return n_channels;
5258}
5259
Johannes Berg2a519312009-02-10 21:25:55 +01005260static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5261{
Johannes Berg4c476992010-10-04 21:36:35 +02005262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005263 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005264 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005265 struct nlattr *attr;
5266 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005267 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005268 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005269
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005270 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5271 return -EINVAL;
5272
Johannes Berg79c97e92009-07-07 03:56:12 +02005273 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005274
Johannes Berg4c476992010-10-04 21:36:35 +02005275 if (!rdev->ops->scan)
5276 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005277
Johannes Bergf9d15d12014-01-22 11:14:19 +02005278 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005279 err = -EBUSY;
5280 goto unlock;
5281 }
Johannes Berg2a519312009-02-10 21:25:55 +01005282
5283 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005284 n_channels = validate_scan_freqs(
5285 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005286 if (!n_channels) {
5287 err = -EINVAL;
5288 goto unlock;
5289 }
Johannes Berg2a519312009-02-10 21:25:55 +01005290 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005291 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005292 }
5293
5294 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5295 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5296 n_ssids++;
5297
Johannes Bergf9f47522013-03-19 15:04:07 +01005298 if (n_ssids > wiphy->max_scan_ssids) {
5299 err = -EINVAL;
5300 goto unlock;
5301 }
Johannes Berg2a519312009-02-10 21:25:55 +01005302
Jouni Malinen70692ad2009-02-16 19:39:13 +02005303 if (info->attrs[NL80211_ATTR_IE])
5304 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5305 else
5306 ie_len = 0;
5307
Johannes Bergf9f47522013-03-19 15:04:07 +01005308 if (ie_len > wiphy->max_scan_ie_len) {
5309 err = -EINVAL;
5310 goto unlock;
5311 }
Johannes Berg18a83652009-03-31 12:12:05 +02005312
Johannes Berg2a519312009-02-10 21:25:55 +01005313 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005314 + sizeof(*request->ssids) * n_ssids
5315 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005316 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005317 if (!request) {
5318 err = -ENOMEM;
5319 goto unlock;
5320 }
Johannes Berg2a519312009-02-10 21:25:55 +01005321
Johannes Berg2a519312009-02-10 21:25:55 +01005322 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005323 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005324 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005325 if (ie_len) {
5326 if (request->ssids)
5327 request->ie = (void *)(request->ssids + n_ssids);
5328 else
5329 request->ie = (void *)(request->channels + n_channels);
5330 }
Johannes Berg2a519312009-02-10 21:25:55 +01005331
Johannes Berg584991d2009-11-02 13:32:03 +01005332 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005333 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5334 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005335 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005336 struct ieee80211_channel *chan;
5337
5338 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5339
5340 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005341 err = -EINVAL;
5342 goto out_free;
5343 }
Johannes Berg584991d2009-11-02 13:32:03 +01005344
5345 /* ignore disabled channels */
5346 if (chan->flags & IEEE80211_CHAN_DISABLED)
5347 continue;
5348
5349 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005350 i++;
5351 }
5352 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005353 enum ieee80211_band band;
5354
Johannes Berg2a519312009-02-10 21:25:55 +01005355 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005356 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5357 int j;
5358 if (!wiphy->bands[band])
5359 continue;
5360 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005361 struct ieee80211_channel *chan;
5362
5363 chan = &wiphy->bands[band]->channels[j];
5364
5365 if (chan->flags & IEEE80211_CHAN_DISABLED)
5366 continue;
5367
5368 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005369 i++;
5370 }
5371 }
5372 }
5373
Johannes Berg584991d2009-11-02 13:32:03 +01005374 if (!i) {
5375 err = -EINVAL;
5376 goto out_free;
5377 }
5378
5379 request->n_channels = i;
5380
Johannes Berg2a519312009-02-10 21:25:55 +01005381 i = 0;
5382 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5383 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005384 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005385 err = -EINVAL;
5386 goto out_free;
5387 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005388 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005389 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005390 i++;
5391 }
5392 }
5393
Jouni Malinen70692ad2009-02-16 19:39:13 +02005394 if (info->attrs[NL80211_ATTR_IE]) {
5395 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005396 memcpy((void *)request->ie,
5397 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005398 request->ie_len);
5399 }
5400
Johannes Berg34850ab2011-07-18 18:08:35 +02005401 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005402 if (wiphy->bands[i])
5403 request->rates[i] =
5404 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005405
5406 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5407 nla_for_each_nested(attr,
5408 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5409 tmp) {
5410 enum ieee80211_band band = nla_type(attr);
5411
Dan Carpenter84404622011-07-29 11:52:18 +03005412 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005413 err = -EINVAL;
5414 goto out_free;
5415 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005416
5417 if (!wiphy->bands[band])
5418 continue;
5419
Johannes Berg34850ab2011-07-18 18:08:35 +02005420 err = ieee80211_get_ratemask(wiphy->bands[band],
5421 nla_data(attr),
5422 nla_len(attr),
5423 &request->rates[band]);
5424 if (err)
5425 goto out_free;
5426 }
5427 }
5428
Sam Leffler46856bb2012-10-11 21:03:32 -07005429 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005430 request->flags = nla_get_u32(
5431 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005432 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5433 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005434 err = -EOPNOTSUPP;
5435 goto out_free;
5436 }
5437 }
Sam Lefflered4737712012-10-11 21:03:31 -07005438
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305439 request->no_cck =
5440 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5441
Johannes Bergfd014282012-06-18 19:17:03 +02005442 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005443 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005444 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005445
Johannes Berg79c97e92009-07-07 03:56:12 +02005446 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005447 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005448
Johannes Berg463d0182009-07-14 00:33:35 +02005449 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005450 nl80211_send_scan_start(rdev, wdev);
5451 if (wdev->netdev)
5452 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005453 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005454 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005455 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005456 kfree(request);
5457 }
Johannes Berg3b858752009-03-12 09:55:09 +01005458
Johannes Bergf9f47522013-03-19 15:04:07 +01005459 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005460 return err;
5461}
5462
Luciano Coelho807f8a82011-05-11 17:09:35 +03005463static int nl80211_start_sched_scan(struct sk_buff *skb,
5464 struct genl_info *info)
5465{
5466 struct cfg80211_sched_scan_request *request;
5467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5468 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005469 struct nlattr *attr;
5470 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005471 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005472 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005473 enum ieee80211_band band;
5474 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005475 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005476 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005477
5478 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5479 !rdev->ops->sched_scan_start)
5480 return -EOPNOTSUPP;
5481
5482 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5483 return -EINVAL;
5484
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005485 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5486 return -EINVAL;
5487
5488 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5489 if (interval == 0)
5490 return -EINVAL;
5491
Luciano Coelho807f8a82011-05-11 17:09:35 +03005492 wiphy = &rdev->wiphy;
5493
5494 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5495 n_channels = validate_scan_freqs(
5496 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5497 if (!n_channels)
5498 return -EINVAL;
5499 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005500 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005501 }
5502
5503 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5504 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5505 tmp)
5506 n_ssids++;
5507
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005508 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005509 return -EINVAL;
5510
Johannes Bergea73cbc2014-01-24 10:53:53 +01005511 /*
5512 * First, count the number of 'real' matchsets. Due to an issue with
5513 * the old implementation, matchsets containing only the RSSI attribute
5514 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5515 * RSSI for all matchsets, rather than their own matchset for reporting
5516 * all APs with a strong RSSI. This is needed to be compatible with
5517 * older userspace that treated a matchset with only the RSSI as the
5518 * global RSSI for all other matchsets - if there are other matchsets.
5519 */
5520 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005521 nla_for_each_nested(attr,
5522 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005523 tmp) {
5524 struct nlattr *rssi;
5525
5526 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5527 nla_data(attr), nla_len(attr),
5528 nl80211_match_policy);
5529 if (err)
5530 return err;
5531 /* add other standalone attributes here */
5532 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5533 n_match_sets++;
5534 continue;
5535 }
5536 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5537 if (rssi)
5538 default_match_rssi = nla_get_s32(rssi);
5539 }
5540 }
5541
5542 /* However, if there's no other matchset, add the RSSI one */
5543 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5544 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005545
5546 if (n_match_sets > wiphy->max_match_sets)
5547 return -EINVAL;
5548
Luciano Coelho807f8a82011-05-11 17:09:35 +03005549 if (info->attrs[NL80211_ATTR_IE])
5550 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5551 else
5552 ie_len = 0;
5553
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005554 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005555 return -EINVAL;
5556
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005557 if (rdev->sched_scan_req) {
5558 err = -EINPROGRESS;
5559 goto out;
5560 }
5561
Luciano Coelho807f8a82011-05-11 17:09:35 +03005562 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005563 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005564 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005565 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005566 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005567 if (!request) {
5568 err = -ENOMEM;
5569 goto out;
5570 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005571
5572 if (n_ssids)
5573 request->ssids = (void *)&request->channels[n_channels];
5574 request->n_ssids = n_ssids;
5575 if (ie_len) {
5576 if (request->ssids)
5577 request->ie = (void *)(request->ssids + n_ssids);
5578 else
5579 request->ie = (void *)(request->channels + n_channels);
5580 }
5581
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005582 if (n_match_sets) {
5583 if (request->ie)
5584 request->match_sets = (void *)(request->ie + ie_len);
5585 else if (request->ssids)
5586 request->match_sets =
5587 (void *)(request->ssids + n_ssids);
5588 else
5589 request->match_sets =
5590 (void *)(request->channels + n_channels);
5591 }
5592 request->n_match_sets = n_match_sets;
5593
Luciano Coelho807f8a82011-05-11 17:09:35 +03005594 i = 0;
5595 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5596 /* user specified, bail out if channel not found */
5597 nla_for_each_nested(attr,
5598 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5599 tmp) {
5600 struct ieee80211_channel *chan;
5601
5602 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5603
5604 if (!chan) {
5605 err = -EINVAL;
5606 goto out_free;
5607 }
5608
5609 /* ignore disabled channels */
5610 if (chan->flags & IEEE80211_CHAN_DISABLED)
5611 continue;
5612
5613 request->channels[i] = chan;
5614 i++;
5615 }
5616 } else {
5617 /* all channels */
5618 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5619 int j;
5620 if (!wiphy->bands[band])
5621 continue;
5622 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5623 struct ieee80211_channel *chan;
5624
5625 chan = &wiphy->bands[band]->channels[j];
5626
5627 if (chan->flags & IEEE80211_CHAN_DISABLED)
5628 continue;
5629
5630 request->channels[i] = chan;
5631 i++;
5632 }
5633 }
5634 }
5635
5636 if (!i) {
5637 err = -EINVAL;
5638 goto out_free;
5639 }
5640
5641 request->n_channels = i;
5642
5643 i = 0;
5644 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5645 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5646 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005647 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005648 err = -EINVAL;
5649 goto out_free;
5650 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005651 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005652 memcpy(request->ssids[i].ssid, nla_data(attr),
5653 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005654 i++;
5655 }
5656 }
5657
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005658 i = 0;
5659 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5660 nla_for_each_nested(attr,
5661 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5662 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005663 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005664
Johannes Bergae811e22014-01-24 10:17:47 +01005665 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5666 nla_data(attr), nla_len(attr),
5667 nl80211_match_policy);
5668 if (err)
5669 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005670 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005671 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005672 if (WARN_ON(i >= n_match_sets)) {
5673 /* this indicates a programming error,
5674 * the loop above should have verified
5675 * things properly
5676 */
5677 err = -EINVAL;
5678 goto out_free;
5679 }
5680
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005681 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5682 err = -EINVAL;
5683 goto out_free;
5684 }
5685 memcpy(request->match_sets[i].ssid.ssid,
5686 nla_data(ssid), nla_len(ssid));
5687 request->match_sets[i].ssid.ssid_len =
5688 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005689 /* special attribute - old implemenation w/a */
5690 request->match_sets[i].rssi_thold =
5691 default_match_rssi;
5692 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5693 if (rssi)
5694 request->match_sets[i].rssi_thold =
5695 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005696 }
5697 i++;
5698 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005699
5700 /* there was no other matchset, so the RSSI one is alone */
5701 if (i == 0)
5702 request->match_sets[0].rssi_thold = default_match_rssi;
5703
5704 request->min_rssi_thold = INT_MAX;
5705 for (i = 0; i < n_match_sets; i++)
5706 request->min_rssi_thold =
5707 min(request->match_sets[i].rssi_thold,
5708 request->min_rssi_thold);
5709 } else {
5710 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005711 }
5712
Luciano Coelho807f8a82011-05-11 17:09:35 +03005713 if (info->attrs[NL80211_ATTR_IE]) {
5714 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5715 memcpy((void *)request->ie,
5716 nla_data(info->attrs[NL80211_ATTR_IE]),
5717 request->ie_len);
5718 }
5719
Sam Leffler46856bb2012-10-11 21:03:32 -07005720 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005721 request->flags = nla_get_u32(
5722 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005723 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5724 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005725 err = -EOPNOTSUPP;
5726 goto out_free;
5727 }
5728 }
Sam Lefflered4737712012-10-11 21:03:31 -07005729
Luciano Coelho807f8a82011-05-11 17:09:35 +03005730 request->dev = dev;
5731 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005732 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005733 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005734
Hila Gonene35e4d22012-06-27 17:19:42 +03005735 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005736 if (!err) {
5737 rdev->sched_scan_req = request;
5738 nl80211_send_sched_scan(rdev, dev,
5739 NL80211_CMD_START_SCHED_SCAN);
5740 goto out;
5741 }
5742
5743out_free:
5744 kfree(request);
5745out:
5746 return err;
5747}
5748
5749static int nl80211_stop_sched_scan(struct sk_buff *skb,
5750 struct genl_info *info)
5751{
5752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5753
5754 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5755 !rdev->ops->sched_scan_stop)
5756 return -EOPNOTSUPP;
5757
Johannes Berg5fe231e2013-05-08 21:45:15 +02005758 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005759}
5760
Simon Wunderlich04f39042013-02-08 18:16:19 +01005761static int nl80211_start_radar_detection(struct sk_buff *skb,
5762 struct genl_info *info)
5763{
5764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5765 struct net_device *dev = info->user_ptr[1];
5766 struct wireless_dev *wdev = dev->ieee80211_ptr;
5767 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005768 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005769 int err;
5770
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005771 dfs_region = reg_get_dfs_region(wdev->wiphy);
5772 if (dfs_region == NL80211_DFS_UNSET)
5773 return -EINVAL;
5774
Simon Wunderlich04f39042013-02-08 18:16:19 +01005775 err = nl80211_parse_chandef(rdev, info, &chandef);
5776 if (err)
5777 return err;
5778
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005779 if (netif_carrier_ok(dev))
5780 return -EBUSY;
5781
Simon Wunderlich04f39042013-02-08 18:16:19 +01005782 if (wdev->cac_started)
5783 return -EBUSY;
5784
5785 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5786 if (err < 0)
5787 return err;
5788
5789 if (err == 0)
5790 return -EINVAL;
5791
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005792 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005793 return -EINVAL;
5794
5795 if (!rdev->ops->start_radar_detection)
5796 return -EOPNOTSUPP;
5797
Simon Wunderlich04f39042013-02-08 18:16:19 +01005798 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5799 chandef.chan, CHAN_MODE_SHARED,
5800 BIT(chandef.width));
5801 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005802 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005803
5804 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5805 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005806 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005807 wdev->cac_started = true;
5808 wdev->cac_start_time = jiffies;
5809 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005810 return err;
5811}
5812
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005813static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5814{
5815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5816 struct net_device *dev = info->user_ptr[1];
5817 struct wireless_dev *wdev = dev->ieee80211_ptr;
5818 struct cfg80211_csa_settings params;
5819 /* csa_attrs is defined static to avoid waste of stack size - this
5820 * function is called under RTNL lock, so this should not be a problem.
5821 */
5822 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5823 u8 radar_detect_width = 0;
5824 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005825 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005826
5827 if (!rdev->ops->channel_switch ||
5828 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5829 return -EOPNOTSUPP;
5830
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005831 switch (dev->ieee80211_ptr->iftype) {
5832 case NL80211_IFTYPE_AP:
5833 case NL80211_IFTYPE_P2P_GO:
5834 need_new_beacon = true;
5835
5836 /* useless if AP is not running */
5837 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005838 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005839 break;
5840 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005841 if (!wdev->ssid_len)
5842 return -ENOTCONN;
5843 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005844 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005845 if (!wdev->mesh_id_len)
5846 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005847 break;
5848 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005849 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005850 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005851
5852 memset(&params, 0, sizeof(params));
5853
5854 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5855 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5856 return -EINVAL;
5857
5858 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005859 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005860 return -EINVAL;
5861
5862 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5863
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005864 if (!need_new_beacon)
5865 goto skip_beacons;
5866
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005867 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5868 if (err)
5869 return err;
5870
5871 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5872 info->attrs[NL80211_ATTR_CSA_IES],
5873 nl80211_policy);
5874 if (err)
5875 return err;
5876
5877 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5878 if (err)
5879 return err;
5880
5881 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5882 return -EINVAL;
5883
5884 params.counter_offset_beacon =
5885 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5886 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5887 return -EINVAL;
5888
5889 /* sanity check - counters should be the same */
5890 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5891 params.count)
5892 return -EINVAL;
5893
5894 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5895 params.counter_offset_presp =
5896 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5897 if (params.counter_offset_presp >=
5898 params.beacon_csa.probe_resp_len)
5899 return -EINVAL;
5900
5901 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5902 params.count)
5903 return -EINVAL;
5904 }
5905
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005906skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005907 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5908 if (err)
5909 return err;
5910
5911 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5912 return -EINVAL;
5913
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005914 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005915 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5916 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005917 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5918 &params.chandef);
5919 if (err < 0) {
5920 return err;
5921 } else if (err) {
5922 radar_detect_width = BIT(params.chandef.width);
5923 params.radar_required = true;
5924 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005925 }
5926
5927 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5928 params.chandef.chan,
5929 CHAN_MODE_SHARED,
5930 radar_detect_width);
5931 if (err)
5932 return err;
5933
5934 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5935 params.block_tx = true;
5936
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005937 wdev_lock(wdev);
5938 err = rdev_channel_switch(rdev, dev, &params);
5939 wdev_unlock(wdev);
5940
5941 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005942}
5943
Johannes Berg9720bb32011-06-21 09:45:33 +02005944static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5945 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005946 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005947 struct wireless_dev *wdev,
5948 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005949{
Johannes Berg48ab9052009-07-10 18:42:31 +02005950 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005951 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005952 void *hdr;
5953 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005954 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005955
5956 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005957
Eric W. Biederman15e47302012-09-07 20:12:54 +00005958 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005959 NL80211_CMD_NEW_SCAN_RESULTS);
5960 if (!hdr)
5961 return -1;
5962
Johannes Berg9720bb32011-06-21 09:45:33 +02005963 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5964
Johannes Berg97990a02013-04-19 01:02:55 +02005965 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5966 goto nla_put_failure;
5967 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005968 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5969 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005970 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5971 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005972
5973 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5974 if (!bss)
5975 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005976 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005977 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005978 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005979
5980 rcu_read_lock();
5981 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005982 if (ies) {
5983 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5984 goto fail_unlock_rcu;
5985 tsf = true;
5986 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5987 ies->len, ies->data))
5988 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005989 }
5990 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005991 if (ies) {
5992 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5993 goto fail_unlock_rcu;
5994 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5995 ies->len, ies->data))
5996 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005997 }
5998 rcu_read_unlock();
5999
David S. Miller9360ffd2012-03-29 04:41:26 -04006000 if (res->beacon_interval &&
6001 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6002 goto nla_put_failure;
6003 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6004 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006005 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006006 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6007 jiffies_to_msecs(jiffies - intbss->ts)))
6008 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006009
Johannes Berg77965c92009-02-18 18:45:06 +01006010 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006011 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006012 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6013 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006014 break;
6015 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006016 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6017 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006018 break;
6019 default:
6020 break;
6021 }
6022
Johannes Berg48ab9052009-07-10 18:42:31 +02006023 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006024 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006025 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006026 if (intbss == wdev->current_bss &&
6027 nla_put_u32(msg, NL80211_BSS_STATUS,
6028 NL80211_BSS_STATUS_ASSOCIATED))
6029 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006030 break;
6031 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006032 if (intbss == wdev->current_bss &&
6033 nla_put_u32(msg, NL80211_BSS_STATUS,
6034 NL80211_BSS_STATUS_IBSS_JOINED))
6035 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006036 break;
6037 default:
6038 break;
6039 }
6040
Johannes Berg2a519312009-02-10 21:25:55 +01006041 nla_nest_end(msg, bss);
6042
6043 return genlmsg_end(msg, hdr);
6044
Johannes Berg8cef2c92013-02-05 16:54:31 +01006045 fail_unlock_rcu:
6046 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006047 nla_put_failure:
6048 genlmsg_cancel(msg, hdr);
6049 return -EMSGSIZE;
6050}
6051
Johannes Berg97990a02013-04-19 01:02:55 +02006052static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006053{
Johannes Berg48ab9052009-07-10 18:42:31 +02006054 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006055 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006056 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006057 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006058 int err;
6059
Johannes Berg97990a02013-04-19 01:02:55 +02006060 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006061 if (err)
6062 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006063
Johannes Berg48ab9052009-07-10 18:42:31 +02006064 wdev_lock(wdev);
6065 spin_lock_bh(&rdev->bss_lock);
6066 cfg80211_bss_expire(rdev);
6067
Johannes Berg9720bb32011-06-21 09:45:33 +02006068 cb->seq = rdev->bss_generation;
6069
Johannes Berg48ab9052009-07-10 18:42:31 +02006070 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006071 if (++idx <= start)
6072 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006073 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006074 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006075 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006076 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006077 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006078 }
6079 }
6080
Johannes Berg48ab9052009-07-10 18:42:31 +02006081 spin_unlock_bh(&rdev->bss_lock);
6082 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006083
Johannes Berg97990a02013-04-19 01:02:55 +02006084 cb->args[2] = idx;
6085 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006086
Johannes Berg67748892010-10-04 21:14:06 +02006087 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006088}
6089
Eric W. Biederman15e47302012-09-07 20:12:54 +00006090static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006091 int flags, struct net_device *dev,
6092 struct survey_info *survey)
6093{
6094 void *hdr;
6095 struct nlattr *infoattr;
6096
Eric W. Biederman15e47302012-09-07 20:12:54 +00006097 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006098 NL80211_CMD_NEW_SURVEY_RESULTS);
6099 if (!hdr)
6100 return -ENOMEM;
6101
David S. Miller9360ffd2012-03-29 04:41:26 -04006102 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6103 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006104
6105 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6106 if (!infoattr)
6107 goto nla_put_failure;
6108
David S. Miller9360ffd2012-03-29 04:41:26 -04006109 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6110 survey->channel->center_freq))
6111 goto nla_put_failure;
6112
6113 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6114 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6115 goto nla_put_failure;
6116 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6117 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6118 goto nla_put_failure;
6119 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6120 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6121 survey->channel_time))
6122 goto nla_put_failure;
6123 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6124 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6125 survey->channel_time_busy))
6126 goto nla_put_failure;
6127 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6128 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6129 survey->channel_time_ext_busy))
6130 goto nla_put_failure;
6131 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6132 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6133 survey->channel_time_rx))
6134 goto nla_put_failure;
6135 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6136 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6137 survey->channel_time_tx))
6138 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006139
6140 nla_nest_end(msg, infoattr);
6141
6142 return genlmsg_end(msg, hdr);
6143
6144 nla_put_failure:
6145 genlmsg_cancel(msg, hdr);
6146 return -EMSGSIZE;
6147}
6148
6149static int nl80211_dump_survey(struct sk_buff *skb,
6150 struct netlink_callback *cb)
6151{
6152 struct survey_info survey;
6153 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006154 struct wireless_dev *wdev;
6155 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006156 int res;
6157
Johannes Berg97990a02013-04-19 01:02:55 +02006158 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006159 if (res)
6160 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006161
Johannes Berg97990a02013-04-19 01:02:55 +02006162 if (!wdev->netdev) {
6163 res = -EINVAL;
6164 goto out_err;
6165 }
6166
Holger Schurig61fa7132009-11-11 12:25:40 +01006167 if (!dev->ops->dump_survey) {
6168 res = -EOPNOTSUPP;
6169 goto out_err;
6170 }
6171
6172 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006173 struct ieee80211_channel *chan;
6174
Johannes Berg97990a02013-04-19 01:02:55 +02006175 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006176 if (res == -ENOENT)
6177 break;
6178 if (res)
6179 goto out_err;
6180
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006181 /* Survey without a channel doesn't make sense */
6182 if (!survey.channel) {
6183 res = -EINVAL;
6184 goto out;
6185 }
6186
6187 chan = ieee80211_get_channel(&dev->wiphy,
6188 survey.channel->center_freq);
6189 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6190 survey_idx++;
6191 continue;
6192 }
6193
Holger Schurig61fa7132009-11-11 12:25:40 +01006194 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006195 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006196 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006197 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006198 goto out;
6199 survey_idx++;
6200 }
6201
6202 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006203 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006204 res = skb->len;
6205 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006206 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006207 return res;
6208}
6209
Samuel Ortizb23aa672009-07-01 21:26:54 +02006210static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6211{
6212 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6213 NL80211_WPA_VERSION_2));
6214}
6215
Jouni Malinen636a5d32009-03-19 13:39:22 +02006216static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6217{
Johannes Berg4c476992010-10-04 21:36:35 +02006218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6219 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006220 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006221 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6222 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006223 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006224 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006225 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006226
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006227 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6228 return -EINVAL;
6229
6230 if (!info->attrs[NL80211_ATTR_MAC])
6231 return -EINVAL;
6232
Jouni Malinen17780922009-03-27 20:52:47 +02006233 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6234 return -EINVAL;
6235
Johannes Berg19957bb2009-07-02 17:20:43 +02006236 if (!info->attrs[NL80211_ATTR_SSID])
6237 return -EINVAL;
6238
6239 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6240 return -EINVAL;
6241
Johannes Bergfffd0932009-07-08 14:22:54 +02006242 err = nl80211_parse_key(info, &key);
6243 if (err)
6244 return err;
6245
6246 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006247 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6248 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006249 if (!key.p.key || !key.p.key_len)
6250 return -EINVAL;
6251 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6252 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6253 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6254 key.p.key_len != WLAN_KEY_LEN_WEP104))
6255 return -EINVAL;
6256 if (key.idx > 4)
6257 return -EINVAL;
6258 } else {
6259 key.p.key_len = 0;
6260 key.p.key = NULL;
6261 }
6262
Johannes Bergafea0b72010-08-10 09:46:42 +02006263 if (key.idx >= 0) {
6264 int i;
6265 bool ok = false;
6266 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6267 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6268 ok = true;
6269 break;
6270 }
6271 }
Johannes Berg4c476992010-10-04 21:36:35 +02006272 if (!ok)
6273 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006274 }
6275
Johannes Berg4c476992010-10-04 21:36:35 +02006276 if (!rdev->ops->auth)
6277 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006278
Johannes Berg074ac8d2010-09-16 14:58:22 +02006279 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006280 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6281 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006282
Johannes Berg19957bb2009-07-02 17:20:43 +02006283 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006284 chan = nl80211_get_valid_chan(&rdev->wiphy,
6285 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6286 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006287 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006288
Johannes Berg19957bb2009-07-02 17:20:43 +02006289 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6290 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6291
6292 if (info->attrs[NL80211_ATTR_IE]) {
6293 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6294 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6295 }
6296
6297 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006298 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006299 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006300
Jouni Malinene39e5b52012-09-30 19:29:39 +03006301 if (auth_type == NL80211_AUTHTYPE_SAE &&
6302 !info->attrs[NL80211_ATTR_SAE_DATA])
6303 return -EINVAL;
6304
6305 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6306 if (auth_type != NL80211_AUTHTYPE_SAE)
6307 return -EINVAL;
6308 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6309 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6310 /* need to include at least Auth Transaction and Status Code */
6311 if (sae_data_len < 4)
6312 return -EINVAL;
6313 }
6314
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006315 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6316
Johannes Berg95de8172012-01-20 13:55:25 +01006317 /*
6318 * Since we no longer track auth state, ignore
6319 * requests to only change local state.
6320 */
6321 if (local_state_change)
6322 return 0;
6323
Johannes Berg91bf9b22013-05-15 17:44:01 +02006324 wdev_lock(dev->ieee80211_ptr);
6325 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6326 ssid, ssid_len, ie, ie_len,
6327 key.p.key, key.p.key_len, key.idx,
6328 sae_data, sae_data_len);
6329 wdev_unlock(dev->ieee80211_ptr);
6330 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006331}
6332
Johannes Bergc0692b82010-08-27 14:26:53 +03006333static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6334 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006335 struct cfg80211_crypto_settings *settings,
6336 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006337{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006338 memset(settings, 0, sizeof(*settings));
6339
Samuel Ortizb23aa672009-07-01 21:26:54 +02006340 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6341
Johannes Bergc0692b82010-08-27 14:26:53 +03006342 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6343 u16 proto;
6344 proto = nla_get_u16(
6345 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6346 settings->control_port_ethertype = cpu_to_be16(proto);
6347 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6348 proto != ETH_P_PAE)
6349 return -EINVAL;
6350 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6351 settings->control_port_no_encrypt = true;
6352 } else
6353 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6354
Samuel Ortizb23aa672009-07-01 21:26:54 +02006355 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6356 void *data;
6357 int len, i;
6358
6359 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6360 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6361 settings->n_ciphers_pairwise = len / sizeof(u32);
6362
6363 if (len % sizeof(u32))
6364 return -EINVAL;
6365
Johannes Berg3dc27d22009-07-02 21:36:37 +02006366 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006367 return -EINVAL;
6368
6369 memcpy(settings->ciphers_pairwise, data, len);
6370
6371 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006372 if (!cfg80211_supported_cipher_suite(
6373 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006374 settings->ciphers_pairwise[i]))
6375 return -EINVAL;
6376 }
6377
6378 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6379 settings->cipher_group =
6380 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006381 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6382 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006383 return -EINVAL;
6384 }
6385
6386 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6387 settings->wpa_versions =
6388 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6389 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6390 return -EINVAL;
6391 }
6392
6393 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6394 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006395 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006396
6397 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6398 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6399 settings->n_akm_suites = len / sizeof(u32);
6400
6401 if (len % sizeof(u32))
6402 return -EINVAL;
6403
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006404 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6405 return -EINVAL;
6406
Samuel Ortizb23aa672009-07-01 21:26:54 +02006407 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006408 }
6409
6410 return 0;
6411}
6412
Jouni Malinen636a5d32009-03-19 13:39:22 +02006413static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6414{
Johannes Berg4c476992010-10-04 21:36:35 +02006415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6416 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006417 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006418 struct cfg80211_assoc_request req = {};
6419 const u8 *bssid, *ssid;
6420 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006421
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006422 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6423 return -EINVAL;
6424
6425 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006426 !info->attrs[NL80211_ATTR_SSID] ||
6427 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006428 return -EINVAL;
6429
Johannes Berg4c476992010-10-04 21:36:35 +02006430 if (!rdev->ops->assoc)
6431 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006432
Johannes Berg074ac8d2010-09-16 14:58:22 +02006433 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006434 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6435 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006436
Johannes Berg19957bb2009-07-02 17:20:43 +02006437 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006438
Jouni Malinen664834d2014-01-15 00:01:44 +02006439 chan = nl80211_get_valid_chan(&rdev->wiphy,
6440 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6441 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006442 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006443
Johannes Berg19957bb2009-07-02 17:20:43 +02006444 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6445 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006446
6447 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006448 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6449 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006450 }
6451
Jouni Malinendc6382c2009-05-06 22:09:37 +03006452 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006453 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006454 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006455 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006456 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006457 else if (mfp != NL80211_MFP_NO)
6458 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006459 }
6460
Johannes Berg3e5d7642009-07-07 14:37:26 +02006461 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006462 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006463
Ben Greear7e7c8922011-11-18 11:31:59 -08006464 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006465 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006466
6467 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006468 memcpy(&req.ht_capa_mask,
6469 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6470 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006471
6472 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006473 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006474 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006475 memcpy(&req.ht_capa,
6476 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6477 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006478 }
6479
Johannes Bergee2aca32013-02-21 17:36:01 +01006480 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006481 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006482
6483 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006484 memcpy(&req.vht_capa_mask,
6485 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6486 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006487
6488 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006489 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006490 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006491 memcpy(&req.vht_capa,
6492 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6493 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006494 }
6495
Johannes Bergf62fab72013-02-21 20:09:09 +01006496 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006497 if (!err) {
6498 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006499 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6500 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006501 wdev_unlock(dev->ieee80211_ptr);
6502 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006503
Jouni Malinen636a5d32009-03-19 13:39:22 +02006504 return err;
6505}
6506
6507static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6508{
Johannes Berg4c476992010-10-04 21:36:35 +02006509 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6510 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006511 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006512 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006513 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006514 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006515
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006516 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6517 return -EINVAL;
6518
6519 if (!info->attrs[NL80211_ATTR_MAC])
6520 return -EINVAL;
6521
6522 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6523 return -EINVAL;
6524
Johannes Berg4c476992010-10-04 21:36:35 +02006525 if (!rdev->ops->deauth)
6526 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006527
Johannes Berg074ac8d2010-09-16 14:58:22 +02006528 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006529 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6530 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006531
Johannes Berg19957bb2009-07-02 17:20:43 +02006532 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006533
Johannes Berg19957bb2009-07-02 17:20:43 +02006534 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6535 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006536 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006537 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006538 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006539
6540 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006541 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6542 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006543 }
6544
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006545 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6546
Johannes Berg91bf9b22013-05-15 17:44:01 +02006547 wdev_lock(dev->ieee80211_ptr);
6548 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6549 local_state_change);
6550 wdev_unlock(dev->ieee80211_ptr);
6551 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006552}
6553
6554static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6555{
Johannes Berg4c476992010-10-04 21:36:35 +02006556 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6557 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006558 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006559 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006560 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006561 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006562
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006563 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6564 return -EINVAL;
6565
6566 if (!info->attrs[NL80211_ATTR_MAC])
6567 return -EINVAL;
6568
6569 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6570 return -EINVAL;
6571
Johannes Berg4c476992010-10-04 21:36:35 +02006572 if (!rdev->ops->disassoc)
6573 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006574
Johannes Berg074ac8d2010-09-16 14:58:22 +02006575 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006576 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6577 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006578
Johannes Berg19957bb2009-07-02 17:20:43 +02006579 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006580
Johannes Berg19957bb2009-07-02 17:20:43 +02006581 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6582 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006583 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006584 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006585 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006586
6587 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006588 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6589 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006590 }
6591
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006592 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6593
Johannes Berg91bf9b22013-05-15 17:44:01 +02006594 wdev_lock(dev->ieee80211_ptr);
6595 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6596 local_state_change);
6597 wdev_unlock(dev->ieee80211_ptr);
6598 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006599}
6600
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006601static bool
6602nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6603 int mcast_rate[IEEE80211_NUM_BANDS],
6604 int rateval)
6605{
6606 struct wiphy *wiphy = &rdev->wiphy;
6607 bool found = false;
6608 int band, i;
6609
6610 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6611 struct ieee80211_supported_band *sband;
6612
6613 sband = wiphy->bands[band];
6614 if (!sband)
6615 continue;
6616
6617 for (i = 0; i < sband->n_bitrates; i++) {
6618 if (sband->bitrates[i].bitrate == rateval) {
6619 mcast_rate[band] = i + 1;
6620 found = true;
6621 break;
6622 }
6623 }
6624 }
6625
6626 return found;
6627}
6628
Johannes Berg04a773a2009-04-19 21:24:32 +02006629static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6630{
Johannes Berg4c476992010-10-04 21:36:35 +02006631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6632 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006633 struct cfg80211_ibss_params ibss;
6634 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006635 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006636 int err;
6637
Johannes Berg8e30bc52009-04-22 17:45:38 +02006638 memset(&ibss, 0, sizeof(ibss));
6639
Johannes Berg04a773a2009-04-19 21:24:32 +02006640 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6641 return -EINVAL;
6642
Johannes Berg683b6d32012-11-08 21:25:48 +01006643 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006644 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6645 return -EINVAL;
6646
Johannes Berg8e30bc52009-04-22 17:45:38 +02006647 ibss.beacon_interval = 100;
6648
6649 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6650 ibss.beacon_interval =
6651 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6652 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6653 return -EINVAL;
6654 }
6655
Johannes Berg4c476992010-10-04 21:36:35 +02006656 if (!rdev->ops->join_ibss)
6657 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006658
Johannes Berg4c476992010-10-04 21:36:35 +02006659 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6660 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006661
Johannes Berg79c97e92009-07-07 03:56:12 +02006662 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006663
Johannes Berg39193492011-09-16 13:45:25 +02006664 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006665 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006666
6667 if (!is_valid_ether_addr(ibss.bssid))
6668 return -EINVAL;
6669 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006670 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6671 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6672
6673 if (info->attrs[NL80211_ATTR_IE]) {
6674 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6675 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6676 }
6677
Johannes Berg683b6d32012-11-08 21:25:48 +01006678 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6679 if (err)
6680 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006681
Johannes Berg683b6d32012-11-08 21:25:48 +01006682 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006683 return -EINVAL;
6684
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006685 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006686 case NL80211_CHAN_WIDTH_5:
6687 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006688 case NL80211_CHAN_WIDTH_20_NOHT:
6689 break;
6690 case NL80211_CHAN_WIDTH_20:
6691 case NL80211_CHAN_WIDTH_40:
6692 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6693 break;
6694 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006695 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006696 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006697
Johannes Berg04a773a2009-04-19 21:24:32 +02006698 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006699 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006700
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006701 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6702 u8 *rates =
6703 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6704 int n_rates =
6705 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6706 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006707 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006708
Johannes Berg34850ab2011-07-18 18:08:35 +02006709 err = ieee80211_get_ratemask(sband, rates, n_rates,
6710 &ibss.basic_rates);
6711 if (err)
6712 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006713 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006714
Simon Wunderlich803768f2013-06-28 10:39:58 +02006715 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6716 memcpy(&ibss.ht_capa_mask,
6717 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6718 sizeof(ibss.ht_capa_mask));
6719
6720 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6721 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6722 return -EINVAL;
6723 memcpy(&ibss.ht_capa,
6724 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6725 sizeof(ibss.ht_capa));
6726 }
6727
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006728 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6729 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6730 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6731 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006732
Johannes Berg4c476992010-10-04 21:36:35 +02006733 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306734 bool no_ht = false;
6735
Johannes Berg4c476992010-10-04 21:36:35 +02006736 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306737 info->attrs[NL80211_ATTR_KEYS],
6738 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006739 if (IS_ERR(connkeys))
6740 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306741
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006742 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6743 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306744 kfree(connkeys);
6745 return -EINVAL;
6746 }
Johannes Berg4c476992010-10-04 21:36:35 +02006747 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006748
Antonio Quartulli267335d2012-01-31 20:25:47 +01006749 ibss.control_port =
6750 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6751
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006752 ibss.userspace_handles_dfs =
6753 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6754
Johannes Berg4c476992010-10-04 21:36:35 +02006755 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006756 if (err)
6757 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006758 return err;
6759}
6760
6761static int nl80211_leave_ibss(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];
6764 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006765
Johannes Berg4c476992010-10-04 21:36:35 +02006766 if (!rdev->ops->leave_ibss)
6767 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006768
Johannes Berg4c476992010-10-04 21:36:35 +02006769 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6770 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006771
Johannes Berg4c476992010-10-04 21:36:35 +02006772 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006773}
6774
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006775static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6776{
6777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6778 struct net_device *dev = info->user_ptr[1];
6779 int mcast_rate[IEEE80211_NUM_BANDS];
6780 u32 nla_rate;
6781 int err;
6782
6783 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6784 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6785 return -EOPNOTSUPP;
6786
6787 if (!rdev->ops->set_mcast_rate)
6788 return -EOPNOTSUPP;
6789
6790 memset(mcast_rate, 0, sizeof(mcast_rate));
6791
6792 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6793 return -EINVAL;
6794
6795 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6796 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6797 return -EINVAL;
6798
6799 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6800
6801 return err;
6802}
6803
Johannes Bergad7e7182013-11-13 13:37:47 +01006804static struct sk_buff *
6805__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6806 int approxlen, u32 portid, u32 seq,
6807 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006808 enum nl80211_attrs attr,
6809 const struct nl80211_vendor_cmd_info *info,
6810 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006811{
6812 struct sk_buff *skb;
6813 void *hdr;
6814 struct nlattr *data;
6815
6816 skb = nlmsg_new(approxlen + 100, gfp);
6817 if (!skb)
6818 return NULL;
6819
6820 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6821 if (!hdr) {
6822 kfree_skb(skb);
6823 return NULL;
6824 }
6825
6826 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6827 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006828
6829 if (info) {
6830 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6831 info->vendor_id))
6832 goto nla_put_failure;
6833 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6834 info->subcmd))
6835 goto nla_put_failure;
6836 }
6837
Johannes Bergad7e7182013-11-13 13:37:47 +01006838 data = nla_nest_start(skb, attr);
6839
6840 ((void **)skb->cb)[0] = rdev;
6841 ((void **)skb->cb)[1] = hdr;
6842 ((void **)skb->cb)[2] = data;
6843
6844 return skb;
6845
6846 nla_put_failure:
6847 kfree_skb(skb);
6848 return NULL;
6849}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006850
Johannes Berge03ad6e2014-01-01 17:22:30 +01006851struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6852 enum nl80211_commands cmd,
6853 enum nl80211_attrs attr,
6854 int vendor_event_idx,
6855 int approxlen, gfp_t gfp)
6856{
6857 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6858 const struct nl80211_vendor_cmd_info *info;
6859
6860 switch (cmd) {
6861 case NL80211_CMD_TESTMODE:
6862 if (WARN_ON(vendor_event_idx != -1))
6863 return NULL;
6864 info = NULL;
6865 break;
6866 case NL80211_CMD_VENDOR:
6867 if (WARN_ON(vendor_event_idx < 0 ||
6868 vendor_event_idx >= wiphy->n_vendor_events))
6869 return NULL;
6870 info = &wiphy->vendor_events[vendor_event_idx];
6871 break;
6872 default:
6873 WARN_ON(1);
6874 return NULL;
6875 }
6876
6877 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6878 cmd, attr, info, gfp);
6879}
6880EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6881
6882void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6883{
6884 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6885 void *hdr = ((void **)skb->cb)[1];
6886 struct nlattr *data = ((void **)skb->cb)[2];
6887 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6888
6889 nla_nest_end(skb, data);
6890 genlmsg_end(skb, hdr);
6891
6892 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6893 mcgrp = NL80211_MCGRP_VENDOR;
6894
6895 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6896 mcgrp, gfp);
6897}
6898EXPORT_SYMBOL(__cfg80211_send_event_skb);
6899
Johannes Bergaff89a92009-07-01 21:26:51 +02006900#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006901static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6902{
Johannes Berg4c476992010-10-04 21:36:35 +02006903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006904 struct wireless_dev *wdev =
6905 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006906 int err;
6907
David Spinadelfc73f112013-07-31 18:04:15 +03006908 if (!rdev->ops->testmode_cmd)
6909 return -EOPNOTSUPP;
6910
6911 if (IS_ERR(wdev)) {
6912 err = PTR_ERR(wdev);
6913 if (err != -EINVAL)
6914 return err;
6915 wdev = NULL;
6916 } else if (wdev->wiphy != &rdev->wiphy) {
6917 return -EINVAL;
6918 }
6919
Johannes Bergaff89a92009-07-01 21:26:51 +02006920 if (!info->attrs[NL80211_ATTR_TESTDATA])
6921 return -EINVAL;
6922
Johannes Bergad7e7182013-11-13 13:37:47 +01006923 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006924 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006925 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6926 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006927 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006928
Johannes Bergaff89a92009-07-01 21:26:51 +02006929 return err;
6930}
6931
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006932static int nl80211_testmode_dump(struct sk_buff *skb,
6933 struct netlink_callback *cb)
6934{
Johannes Berg00918d32011-12-13 17:22:05 +01006935 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006936 int err;
6937 long phy_idx;
6938 void *data = NULL;
6939 int data_len = 0;
6940
Johannes Berg5fe231e2013-05-08 21:45:15 +02006941 rtnl_lock();
6942
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006943 if (cb->args[0]) {
6944 /*
6945 * 0 is a valid index, but not valid for args[0],
6946 * so we need to offset by 1.
6947 */
6948 phy_idx = cb->args[0] - 1;
6949 } else {
6950 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6951 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6952 nl80211_policy);
6953 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006954 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006955
Johannes Berg2bd7e352012-06-15 14:23:16 +02006956 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6957 nl80211_fam.attrbuf);
6958 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006959 err = PTR_ERR(rdev);
6960 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006961 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006962 phy_idx = rdev->wiphy_idx;
6963 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006964
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006965 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6966 cb->args[1] =
6967 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6968 }
6969
6970 if (cb->args[1]) {
6971 data = nla_data((void *)cb->args[1]);
6972 data_len = nla_len((void *)cb->args[1]);
6973 }
6974
Johannes Berg00918d32011-12-13 17:22:05 +01006975 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6976 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006977 err = -ENOENT;
6978 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006979 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006980
Johannes Berg00918d32011-12-13 17:22:05 +01006981 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006982 err = -EOPNOTSUPP;
6983 goto out_err;
6984 }
6985
6986 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006987 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006988 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6989 NL80211_CMD_TESTMODE);
6990 struct nlattr *tmdata;
6991
Dan Carpentercb35fba2013-08-14 14:50:01 +03006992 if (!hdr)
6993 break;
6994
David S. Miller9360ffd2012-03-29 04:41:26 -04006995 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006996 genlmsg_cancel(skb, hdr);
6997 break;
6998 }
6999
7000 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7001 if (!tmdata) {
7002 genlmsg_cancel(skb, hdr);
7003 break;
7004 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007005 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007006 nla_nest_end(skb, tmdata);
7007
7008 if (err == -ENOBUFS || err == -ENOENT) {
7009 genlmsg_cancel(skb, hdr);
7010 break;
7011 } else if (err) {
7012 genlmsg_cancel(skb, hdr);
7013 goto out_err;
7014 }
7015
7016 genlmsg_end(skb, hdr);
7017 }
7018
7019 err = skb->len;
7020 /* see above */
7021 cb->args[0] = phy_idx + 1;
7022 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007023 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007024 return err;
7025}
Johannes Bergaff89a92009-07-01 21:26:51 +02007026#endif
7027
Samuel Ortizb23aa672009-07-01 21:26:54 +02007028static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7029{
Johannes Berg4c476992010-10-04 21:36:35 +02007030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7031 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007032 struct cfg80211_connect_params connect;
7033 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007034 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007035 int err;
7036
7037 memset(&connect, 0, sizeof(connect));
7038
7039 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7040 return -EINVAL;
7041
7042 if (!info->attrs[NL80211_ATTR_SSID] ||
7043 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7044 return -EINVAL;
7045
7046 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7047 connect.auth_type =
7048 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007049 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7050 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007051 return -EINVAL;
7052 } else
7053 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7054
7055 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7056
Johannes Bergc0692b82010-08-27 14:26:53 +03007057 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007058 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007059 if (err)
7060 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007061
Johannes Berg074ac8d2010-09-16 14:58:22 +02007062 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007063 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7064 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007065
Johannes Berg79c97e92009-07-07 03:56:12 +02007066 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007067
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307068 connect.bg_scan_period = -1;
7069 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7070 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7071 connect.bg_scan_period =
7072 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7073 }
7074
Samuel Ortizb23aa672009-07-01 21:26:54 +02007075 if (info->attrs[NL80211_ATTR_MAC])
7076 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007077 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7078 connect.bssid_hint =
7079 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007080 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7081 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7082
7083 if (info->attrs[NL80211_ATTR_IE]) {
7084 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7085 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7086 }
7087
Jouni Malinencee00a92013-01-15 17:15:57 +02007088 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7089 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7090 if (connect.mfp != NL80211_MFP_REQUIRED &&
7091 connect.mfp != NL80211_MFP_NO)
7092 return -EINVAL;
7093 } else {
7094 connect.mfp = NL80211_MFP_NO;
7095 }
7096
Samuel Ortizb23aa672009-07-01 21:26:54 +02007097 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007098 connect.channel = nl80211_get_valid_chan(
7099 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7100 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007101 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007102 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007103 connect.channel_hint = nl80211_get_valid_chan(
7104 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7105 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007106 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007107 }
7108
Johannes Bergfffd0932009-07-08 14:22:54 +02007109 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7110 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307111 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007112 if (IS_ERR(connkeys))
7113 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007114 }
7115
Ben Greear7e7c8922011-11-18 11:31:59 -08007116 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7117 connect.flags |= ASSOC_REQ_DISABLE_HT;
7118
7119 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7120 memcpy(&connect.ht_capa_mask,
7121 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7122 sizeof(connect.ht_capa_mask));
7123
7124 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007125 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7126 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007127 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007128 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007129 memcpy(&connect.ht_capa,
7130 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7131 sizeof(connect.ht_capa));
7132 }
7133
Johannes Bergee2aca32013-02-21 17:36:01 +01007134 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7135 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7136
7137 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7138 memcpy(&connect.vht_capa_mask,
7139 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7140 sizeof(connect.vht_capa_mask));
7141
7142 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7143 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7144 kfree(connkeys);
7145 return -EINVAL;
7146 }
7147 memcpy(&connect.vht_capa,
7148 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7149 sizeof(connect.vht_capa));
7150 }
7151
Johannes Berg83739b02013-05-15 17:44:01 +02007152 wdev_lock(dev->ieee80211_ptr);
7153 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7154 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007155 if (err)
7156 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007157 return err;
7158}
7159
7160static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7161{
Johannes Berg4c476992010-10-04 21:36:35 +02007162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7163 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007164 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007165 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007166
7167 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7168 reason = WLAN_REASON_DEAUTH_LEAVING;
7169 else
7170 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7171
7172 if (reason == 0)
7173 return -EINVAL;
7174
Johannes Berg074ac8d2010-09-16 14:58:22 +02007175 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007176 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7177 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007178
Johannes Berg83739b02013-05-15 17:44:01 +02007179 wdev_lock(dev->ieee80211_ptr);
7180 ret = cfg80211_disconnect(rdev, dev, reason, true);
7181 wdev_unlock(dev->ieee80211_ptr);
7182 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007183}
7184
Johannes Berg463d0182009-07-14 00:33:35 +02007185static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7186{
Johannes Berg4c476992010-10-04 21:36:35 +02007187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007188 struct net *net;
7189 int err;
7190 u32 pid;
7191
7192 if (!info->attrs[NL80211_ATTR_PID])
7193 return -EINVAL;
7194
7195 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7196
Johannes Berg463d0182009-07-14 00:33:35 +02007197 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007198 if (IS_ERR(net))
7199 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007200
7201 err = 0;
7202
7203 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007204 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7205 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007206
Johannes Berg463d0182009-07-14 00:33:35 +02007207 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007208 return err;
7209}
7210
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007211static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7212{
Johannes Berg4c476992010-10-04 21:36:35 +02007213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007214 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7215 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007216 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007217 struct cfg80211_pmksa pmksa;
7218
7219 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7220
7221 if (!info->attrs[NL80211_ATTR_MAC])
7222 return -EINVAL;
7223
7224 if (!info->attrs[NL80211_ATTR_PMKID])
7225 return -EINVAL;
7226
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007227 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7228 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7229
Johannes Berg074ac8d2010-09-16 14:58:22 +02007230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007231 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7232 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007233
7234 switch (info->genlhdr->cmd) {
7235 case NL80211_CMD_SET_PMKSA:
7236 rdev_ops = rdev->ops->set_pmksa;
7237 break;
7238 case NL80211_CMD_DEL_PMKSA:
7239 rdev_ops = rdev->ops->del_pmksa;
7240 break;
7241 default:
7242 WARN_ON(1);
7243 break;
7244 }
7245
Johannes Berg4c476992010-10-04 21:36:35 +02007246 if (!rdev_ops)
7247 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007248
Johannes Berg4c476992010-10-04 21:36:35 +02007249 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007250}
7251
7252static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7253{
Johannes Berg4c476992010-10-04 21:36:35 +02007254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7255 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007256
Johannes Berg074ac8d2010-09-16 14:58:22 +02007257 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007258 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7259 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007260
Johannes Berg4c476992010-10-04 21:36:35 +02007261 if (!rdev->ops->flush_pmksa)
7262 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007263
Hila Gonene35e4d22012-06-27 17:19:42 +03007264 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007265}
7266
Arik Nemtsov109086c2011-09-28 14:12:50 +03007267static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7268{
7269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7270 struct net_device *dev = info->user_ptr[1];
7271 u8 action_code, dialog_token;
7272 u16 status_code;
7273 u8 *peer;
7274
7275 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7276 !rdev->ops->tdls_mgmt)
7277 return -EOPNOTSUPP;
7278
7279 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7280 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7281 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7282 !info->attrs[NL80211_ATTR_IE] ||
7283 !info->attrs[NL80211_ATTR_MAC])
7284 return -EINVAL;
7285
7286 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7287 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7288 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7289 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7290
Hila Gonene35e4d22012-06-27 17:19:42 +03007291 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7292 dialog_token, status_code,
7293 nla_data(info->attrs[NL80211_ATTR_IE]),
7294 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007295}
7296
7297static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7298{
7299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7300 struct net_device *dev = info->user_ptr[1];
7301 enum nl80211_tdls_operation operation;
7302 u8 *peer;
7303
7304 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7305 !rdev->ops->tdls_oper)
7306 return -EOPNOTSUPP;
7307
7308 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7309 !info->attrs[NL80211_ATTR_MAC])
7310 return -EINVAL;
7311
7312 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7313 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7314
Hila Gonene35e4d22012-06-27 17:19:42 +03007315 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007316}
7317
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007318static int nl80211_remain_on_channel(struct sk_buff *skb,
7319 struct genl_info *info)
7320{
Johannes Berg4c476992010-10-04 21:36:35 +02007321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007322 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007323 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007324 struct sk_buff *msg;
7325 void *hdr;
7326 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007327 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007328 int err;
7329
7330 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7331 !info->attrs[NL80211_ATTR_DURATION])
7332 return -EINVAL;
7333
7334 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7335
Johannes Berg7c4ef712011-11-18 15:33:48 +01007336 if (!rdev->ops->remain_on_channel ||
7337 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007338 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007339
Johannes Bergebf348f2012-06-01 12:50:54 +02007340 /*
7341 * We should be on that channel for at least a minimum amount of
7342 * time (10ms) but no longer than the driver supports.
7343 */
7344 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7345 duration > rdev->wiphy.max_remain_on_channel_duration)
7346 return -EINVAL;
7347
Johannes Berg683b6d32012-11-08 21:25:48 +01007348 err = nl80211_parse_chandef(rdev, info, &chandef);
7349 if (err)
7350 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007351
7352 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007353 if (!msg)
7354 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007355
Eric W. Biederman15e47302012-09-07 20:12:54 +00007356 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007357 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007358 if (!hdr) {
7359 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007360 goto free_msg;
7361 }
7362
Johannes Berg683b6d32012-11-08 21:25:48 +01007363 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7364 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007365
7366 if (err)
7367 goto free_msg;
7368
David S. Miller9360ffd2012-03-29 04:41:26 -04007369 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7370 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007371
7372 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007373
7374 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007375
7376 nla_put_failure:
7377 err = -ENOBUFS;
7378 free_msg:
7379 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007380 return err;
7381}
7382
7383static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7384 struct genl_info *info)
7385{
Johannes Berg4c476992010-10-04 21:36:35 +02007386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007387 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007388 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007389
7390 if (!info->attrs[NL80211_ATTR_COOKIE])
7391 return -EINVAL;
7392
Johannes Berg4c476992010-10-04 21:36:35 +02007393 if (!rdev->ops->cancel_remain_on_channel)
7394 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007395
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007396 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7397
Hila Gonene35e4d22012-06-27 17:19:42 +03007398 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007399}
7400
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007401static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7402 u8 *rates, u8 rates_len)
7403{
7404 u8 i;
7405 u32 mask = 0;
7406
7407 for (i = 0; i < rates_len; i++) {
7408 int rate = (rates[i] & 0x7f) * 5;
7409 int ridx;
7410 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7411 struct ieee80211_rate *srate =
7412 &sband->bitrates[ridx];
7413 if (rate == srate->bitrate) {
7414 mask |= 1 << ridx;
7415 break;
7416 }
7417 }
7418 if (ridx == sband->n_bitrates)
7419 return 0; /* rate not found */
7420 }
7421
7422 return mask;
7423}
7424
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007425static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7426 u8 *rates, u8 rates_len,
7427 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7428{
7429 u8 i;
7430
7431 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7432
7433 for (i = 0; i < rates_len; i++) {
7434 int ridx, rbit;
7435
7436 ridx = rates[i] / 8;
7437 rbit = BIT(rates[i] % 8);
7438
7439 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007440 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007441 return false;
7442
7443 /* check availability */
7444 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7445 mcs[ridx] |= rbit;
7446 else
7447 return false;
7448 }
7449
7450 return true;
7451}
7452
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007453static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7454{
7455 u16 mcs_mask = 0;
7456
7457 switch (vht_mcs_map) {
7458 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7459 break;
7460 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7461 mcs_mask = 0x00FF;
7462 break;
7463 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7464 mcs_mask = 0x01FF;
7465 break;
7466 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7467 mcs_mask = 0x03FF;
7468 break;
7469 default:
7470 break;
7471 }
7472
7473 return mcs_mask;
7474}
7475
7476static void vht_build_mcs_mask(u16 vht_mcs_map,
7477 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7478{
7479 u8 nss;
7480
7481 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7482 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7483 vht_mcs_map >>= 2;
7484 }
7485}
7486
7487static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7488 struct nl80211_txrate_vht *txrate,
7489 u16 mcs[NL80211_VHT_NSS_MAX])
7490{
7491 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7492 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7493 u8 i;
7494
7495 if (!sband->vht_cap.vht_supported)
7496 return false;
7497
7498 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7499
7500 /* Build vht_mcs_mask from VHT capabilities */
7501 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7502
7503 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7504 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7505 mcs[i] = txrate->mcs[i];
7506 else
7507 return false;
7508 }
7509
7510 return true;
7511}
7512
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007513static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007514 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7515 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007516 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7517 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007518 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007519 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007520};
7521
7522static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7523 struct genl_info *info)
7524{
7525 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007527 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007528 int rem, i;
7529 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007530 struct nlattr *tx_rates;
7531 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007532 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007533
Johannes Berg4c476992010-10-04 21:36:35 +02007534 if (!rdev->ops->set_bitrate_mask)
7535 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007536
7537 memset(&mask, 0, sizeof(mask));
7538 /* Default to all rates enabled */
7539 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7540 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007541
7542 if (!sband)
7543 continue;
7544
7545 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007546 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007547 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007548 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007549
7550 if (!sband->vht_cap.vht_supported)
7551 continue;
7552
7553 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7554 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007555 }
7556
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007557 /* if no rates are given set it back to the defaults */
7558 if (!info->attrs[NL80211_ATTR_TX_RATES])
7559 goto out;
7560
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007561 /*
7562 * The nested attribute uses enum nl80211_band as the index. This maps
7563 * directly to the enum ieee80211_band values used in cfg80211.
7564 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007565 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007566 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007567 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007568 int err;
7569
Johannes Berg4c476992010-10-04 21:36:35 +02007570 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7571 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007572 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007573 if (sband == NULL)
7574 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007575 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7576 nla_len(tx_rates), nl80211_txattr_policy);
7577 if (err)
7578 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007579 if (tb[NL80211_TXRATE_LEGACY]) {
7580 mask.control[band].legacy = rateset_to_mask(
7581 sband,
7582 nla_data(tb[NL80211_TXRATE_LEGACY]),
7583 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307584 if ((mask.control[band].legacy == 0) &&
7585 nla_len(tb[NL80211_TXRATE_LEGACY]))
7586 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007587 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007588 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007589 if (!ht_rateset_to_mask(
7590 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007591 nla_data(tb[NL80211_TXRATE_HT]),
7592 nla_len(tb[NL80211_TXRATE_HT]),
7593 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007594 return -EINVAL;
7595 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007596 if (tb[NL80211_TXRATE_VHT]) {
7597 if (!vht_set_mcs_mask(
7598 sband,
7599 nla_data(tb[NL80211_TXRATE_VHT]),
7600 mask.control[band].vht_mcs))
7601 return -EINVAL;
7602 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007603 if (tb[NL80211_TXRATE_GI]) {
7604 mask.control[band].gi =
7605 nla_get_u8(tb[NL80211_TXRATE_GI]);
7606 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7607 return -EINVAL;
7608 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007609
7610 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007611 /* don't allow empty legacy rates if HT or VHT
7612 * are not even supported.
7613 */
7614 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7615 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007616 return -EINVAL;
7617
7618 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007619 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007620 goto out;
7621
7622 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7623 if (mask.control[band].vht_mcs[i])
7624 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007625
7626 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007627 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007628 }
7629 }
7630
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007631out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007632 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007633}
7634
Johannes Berg2e161f72010-08-12 15:38:38 +02007635static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007636{
Johannes Berg4c476992010-10-04 21:36:35 +02007637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007638 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007639 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007640
7641 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7642 return -EINVAL;
7643
Johannes Berg2e161f72010-08-12 15:38:38 +02007644 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7645 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007646
Johannes Berg71bbc992012-06-15 15:30:18 +02007647 switch (wdev->iftype) {
7648 case NL80211_IFTYPE_STATION:
7649 case NL80211_IFTYPE_ADHOC:
7650 case NL80211_IFTYPE_P2P_CLIENT:
7651 case NL80211_IFTYPE_AP:
7652 case NL80211_IFTYPE_AP_VLAN:
7653 case NL80211_IFTYPE_MESH_POINT:
7654 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007655 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007656 break;
7657 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007658 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007659 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007660
7661 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007662 if (!rdev->ops->mgmt_tx)
7663 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007664
Eric W. Biederman15e47302012-09-07 20:12:54 +00007665 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007666 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7667 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007668}
7669
Johannes Berg2e161f72010-08-12 15:38:38 +02007670static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007671{
Johannes Berg4c476992010-10-04 21:36:35 +02007672 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007673 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007674 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007675 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007676 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007677 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007678 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007679 struct cfg80211_mgmt_tx_params params = {
7680 .dont_wait_for_ack =
7681 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7682 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007683
Johannes Berg683b6d32012-11-08 21:25:48 +01007684 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007685 return -EINVAL;
7686
Johannes Berg4c476992010-10-04 21:36:35 +02007687 if (!rdev->ops->mgmt_tx)
7688 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007689
Johannes Berg71bbc992012-06-15 15:30:18 +02007690 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007691 case NL80211_IFTYPE_P2P_DEVICE:
7692 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7693 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007694 case NL80211_IFTYPE_STATION:
7695 case NL80211_IFTYPE_ADHOC:
7696 case NL80211_IFTYPE_P2P_CLIENT:
7697 case NL80211_IFTYPE_AP:
7698 case NL80211_IFTYPE_AP_VLAN:
7699 case NL80211_IFTYPE_MESH_POINT:
7700 case NL80211_IFTYPE_P2P_GO:
7701 break;
7702 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007703 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007704 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007705
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007706 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007707 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007708 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007709 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007710
7711 /*
7712 * We should wait on the channel for at least a minimum amount
7713 * of time (10ms) but no longer than the driver supports.
7714 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007715 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7716 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007717 return -EINVAL;
7718
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007719 }
7720
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007721 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007722
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007723 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007724 return -EINVAL;
7725
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007726 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307727
Antonio Quartulliea141b752013-06-11 14:20:03 +02007728 /* get the channel if any has been specified, otherwise pass NULL to
7729 * the driver. The latter will use the current one
7730 */
7731 chandef.chan = NULL;
7732 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7733 err = nl80211_parse_chandef(rdev, info, &chandef);
7734 if (err)
7735 return err;
7736 }
7737
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007738 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007739 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007740
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007741 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7743 if (!msg)
7744 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007745
Eric W. Biederman15e47302012-09-07 20:12:54 +00007746 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007747 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007748 if (!hdr) {
7749 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007750 goto free_msg;
7751 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007752 }
Johannes Berge247bd902011-11-04 11:18:21 +01007753
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007754 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7755 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7756 params.chan = chandef.chan;
7757 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007758 if (err)
7759 goto free_msg;
7760
Johannes Berge247bd902011-11-04 11:18:21 +01007761 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007762 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7763 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007764
Johannes Berge247bd902011-11-04 11:18:21 +01007765 genlmsg_end(msg, hdr);
7766 return genlmsg_reply(msg, info);
7767 }
7768
7769 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007770
7771 nla_put_failure:
7772 err = -ENOBUFS;
7773 free_msg:
7774 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007775 return err;
7776}
7777
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007778static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7779{
7780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007781 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007782 u64 cookie;
7783
7784 if (!info->attrs[NL80211_ATTR_COOKIE])
7785 return -EINVAL;
7786
7787 if (!rdev->ops->mgmt_tx_cancel_wait)
7788 return -EOPNOTSUPP;
7789
Johannes Berg71bbc992012-06-15 15:30:18 +02007790 switch (wdev->iftype) {
7791 case NL80211_IFTYPE_STATION:
7792 case NL80211_IFTYPE_ADHOC:
7793 case NL80211_IFTYPE_P2P_CLIENT:
7794 case NL80211_IFTYPE_AP:
7795 case NL80211_IFTYPE_AP_VLAN:
7796 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007797 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007798 break;
7799 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007800 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007801 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007802
7803 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7804
Hila Gonene35e4d22012-06-27 17:19:42 +03007805 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007806}
7807
Kalle Valoffb9eb32010-02-17 17:58:10 +02007808static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7809{
Johannes Berg4c476992010-10-04 21:36:35 +02007810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007811 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007812 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007813 u8 ps_state;
7814 bool state;
7815 int err;
7816
Johannes Berg4c476992010-10-04 21:36:35 +02007817 if (!info->attrs[NL80211_ATTR_PS_STATE])
7818 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007819
7820 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7821
Johannes Berg4c476992010-10-04 21:36:35 +02007822 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7823 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007824
7825 wdev = dev->ieee80211_ptr;
7826
Johannes Berg4c476992010-10-04 21:36:35 +02007827 if (!rdev->ops->set_power_mgmt)
7828 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007829
7830 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7831
7832 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007833 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007834
Hila Gonene35e4d22012-06-27 17:19:42 +03007835 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007836 if (!err)
7837 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007838 return err;
7839}
7840
7841static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7842{
Johannes Berg4c476992010-10-04 21:36:35 +02007843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007844 enum nl80211_ps_state ps_state;
7845 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007846 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007847 struct sk_buff *msg;
7848 void *hdr;
7849 int err;
7850
Kalle Valoffb9eb32010-02-17 17:58:10 +02007851 wdev = dev->ieee80211_ptr;
7852
Johannes Berg4c476992010-10-04 21:36:35 +02007853 if (!rdev->ops->set_power_mgmt)
7854 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007855
7856 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007857 if (!msg)
7858 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007859
Eric W. Biederman15e47302012-09-07 20:12:54 +00007860 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007861 NL80211_CMD_GET_POWER_SAVE);
7862 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007863 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007864 goto free_msg;
7865 }
7866
7867 if (wdev->ps)
7868 ps_state = NL80211_PS_ENABLED;
7869 else
7870 ps_state = NL80211_PS_DISABLED;
7871
David S. Miller9360ffd2012-03-29 04:41:26 -04007872 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7873 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007874
7875 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007876 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007877
Johannes Berg4c476992010-10-04 21:36:35 +02007878 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007879 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007880 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007881 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007882 return err;
7883}
7884
Johannes Berg94e860f2014-01-20 23:58:15 +01007885static const struct nla_policy
7886nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007887 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7888 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7889 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007890 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7891 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7892 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007893};
7894
Thomas Pedersen84f10702012-07-12 16:17:33 -07007895static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007896 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007897{
7898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007899 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007900 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007901
Johannes Bergd9d8b012012-11-26 12:51:52 +01007902 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007903 return -EINVAL;
7904
Thomas Pedersen84f10702012-07-12 16:17:33 -07007905 if (!rdev->ops->set_cqm_txe_config)
7906 return -EOPNOTSUPP;
7907
7908 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7909 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7910 return -EOPNOTSUPP;
7911
Hila Gonene35e4d22012-06-27 17:19:42 +03007912 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007913}
7914
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007915static int nl80211_set_cqm_rssi(struct genl_info *info,
7916 s32 threshold, u32 hysteresis)
7917{
Johannes Berg4c476992010-10-04 21:36:35 +02007918 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007919 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007920 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007921
7922 if (threshold > 0)
7923 return -EINVAL;
7924
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007925 /* disabling - hysteresis should also be zero then */
7926 if (threshold == 0)
7927 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007928
Johannes Berg4c476992010-10-04 21:36:35 +02007929 if (!rdev->ops->set_cqm_rssi_config)
7930 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007931
Johannes Berg074ac8d2010-09-16 14:58:22 +02007932 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007933 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7934 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007935
Hila Gonene35e4d22012-06-27 17:19:42 +03007936 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007937}
7938
7939static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7940{
7941 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7942 struct nlattr *cqm;
7943 int err;
7944
7945 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007946 if (!cqm)
7947 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007948
7949 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7950 nl80211_attr_cqm_policy);
7951 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007952 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007953
7954 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7955 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007956 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7957 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007958
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007959 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7960 }
7961
7962 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7963 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7964 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7965 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7966 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7967 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7968
7969 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7970 }
7971
7972 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007973}
7974
Johannes Berg29cbe682010-12-03 09:20:44 +01007975static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7976{
7977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7978 struct net_device *dev = info->user_ptr[1];
7979 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007980 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007981 int err;
7982
7983 /* start with default */
7984 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007985 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007986
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007987 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007988 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007989 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007990 if (err)
7991 return err;
7992 }
7993
7994 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7995 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7996 return -EINVAL;
7997
Javier Cardonac80d5452010-12-16 17:37:49 -08007998 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7999 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8000
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008001 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8002 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8003 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8004 return -EINVAL;
8005
Marco Porsch9bdbf042013-01-07 16:04:51 +01008006 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8007 setup.beacon_interval =
8008 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8009 if (setup.beacon_interval < 10 ||
8010 setup.beacon_interval > 10000)
8011 return -EINVAL;
8012 }
8013
8014 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8015 setup.dtim_period =
8016 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8017 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8018 return -EINVAL;
8019 }
8020
Javier Cardonac80d5452010-12-16 17:37:49 -08008021 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8022 /* parse additional setup parameters if given */
8023 err = nl80211_parse_mesh_setup(info, &setup);
8024 if (err)
8025 return err;
8026 }
8027
Thomas Pedersend37bb182013-03-04 13:06:13 -08008028 if (setup.user_mpm)
8029 cfg.auto_open_plinks = false;
8030
Johannes Bergcc1d2802012-05-16 23:50:20 +02008031 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008032 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8033 if (err)
8034 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008035 } else {
8036 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008037 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008038 }
8039
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008040 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8041 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8042 int n_rates =
8043 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8044 struct ieee80211_supported_band *sband;
8045
8046 if (!setup.chandef.chan)
8047 return -EINVAL;
8048
8049 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8050
8051 err = ieee80211_get_ratemask(sband, rates, n_rates,
8052 &setup.basic_rates);
8053 if (err)
8054 return err;
8055 }
8056
Javier Cardonac80d5452010-12-16 17:37:49 -08008057 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008058}
8059
8060static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8061{
8062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8063 struct net_device *dev = info->user_ptr[1];
8064
8065 return cfg80211_leave_mesh(rdev, dev);
8066}
8067
Johannes Bergdfb89c52012-06-27 09:23:48 +02008068#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008069static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8070 struct cfg80211_registered_device *rdev)
8071{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008072 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008073 struct nlattr *nl_pats, *nl_pat;
8074 int i, pat_len;
8075
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008076 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008077 return 0;
8078
8079 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8080 if (!nl_pats)
8081 return -ENOBUFS;
8082
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008083 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008084 nl_pat = nla_nest_start(msg, i + 1);
8085 if (!nl_pat)
8086 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008087 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008088 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008089 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008090 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8091 wowlan->patterns[i].pattern) ||
8092 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008093 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008094 return -ENOBUFS;
8095 nla_nest_end(msg, nl_pat);
8096 }
8097 nla_nest_end(msg, nl_pats);
8098
8099 return 0;
8100}
8101
Johannes Berg2a0e0472013-01-23 22:57:40 +01008102static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8103 struct cfg80211_wowlan_tcp *tcp)
8104{
8105 struct nlattr *nl_tcp;
8106
8107 if (!tcp)
8108 return 0;
8109
8110 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8111 if (!nl_tcp)
8112 return -ENOBUFS;
8113
8114 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8115 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8116 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8117 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8118 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8119 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8120 tcp->payload_len, tcp->payload) ||
8121 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8122 tcp->data_interval) ||
8123 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8124 tcp->wake_len, tcp->wake_data) ||
8125 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8126 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8127 return -ENOBUFS;
8128
8129 if (tcp->payload_seq.len &&
8130 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8131 sizeof(tcp->payload_seq), &tcp->payload_seq))
8132 return -ENOBUFS;
8133
8134 if (tcp->payload_tok.len &&
8135 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8136 sizeof(tcp->payload_tok) + tcp->tokens_size,
8137 &tcp->payload_tok))
8138 return -ENOBUFS;
8139
Johannes Berge248ad32013-05-16 10:24:28 +02008140 nla_nest_end(msg, nl_tcp);
8141
Johannes Berg2a0e0472013-01-23 22:57:40 +01008142 return 0;
8143}
8144
Johannes Bergff1b6e62011-05-04 15:37:28 +02008145static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8146{
8147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8148 struct sk_buff *msg;
8149 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008150 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008151
Johannes Berg964dc9e2013-06-03 17:25:34 +02008152 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008153 return -EOPNOTSUPP;
8154
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008155 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008156 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008157 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8158 rdev->wiphy.wowlan_config->tcp->payload_len +
8159 rdev->wiphy.wowlan_config->tcp->wake_len +
8160 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008161 }
8162
8163 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008164 if (!msg)
8165 return -ENOMEM;
8166
Eric W. Biederman15e47302012-09-07 20:12:54 +00008167 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008168 NL80211_CMD_GET_WOWLAN);
8169 if (!hdr)
8170 goto nla_put_failure;
8171
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008172 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008173 struct nlattr *nl_wowlan;
8174
8175 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8176 if (!nl_wowlan)
8177 goto nla_put_failure;
8178
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008179 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008180 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008181 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008182 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008183 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008184 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008185 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008186 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008187 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008188 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008189 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008190 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008191 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008192 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8193 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008194
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008195 if (nl80211_send_wowlan_patterns(msg, rdev))
8196 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008197
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008198 if (nl80211_send_wowlan_tcp(msg,
8199 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008200 goto nla_put_failure;
8201
Johannes Bergff1b6e62011-05-04 15:37:28 +02008202 nla_nest_end(msg, nl_wowlan);
8203 }
8204
8205 genlmsg_end(msg, hdr);
8206 return genlmsg_reply(msg, info);
8207
8208nla_put_failure:
8209 nlmsg_free(msg);
8210 return -ENOBUFS;
8211}
8212
Johannes Berg2a0e0472013-01-23 22:57:40 +01008213static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8214 struct nlattr *attr,
8215 struct cfg80211_wowlan *trig)
8216{
8217 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8218 struct cfg80211_wowlan_tcp *cfg;
8219 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8220 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8221 u32 size;
8222 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8223 int err, port;
8224
Johannes Berg964dc9e2013-06-03 17:25:34 +02008225 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008226 return -EINVAL;
8227
8228 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8229 nla_data(attr), nla_len(attr),
8230 nl80211_wowlan_tcp_policy);
8231 if (err)
8232 return err;
8233
8234 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8235 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8236 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8237 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8238 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8239 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8240 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8241 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8242 return -EINVAL;
8243
8244 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008245 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008246 return -EINVAL;
8247
8248 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008249 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008250 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008251 return -EINVAL;
8252
8253 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008254 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008255 return -EINVAL;
8256
8257 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8258 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8259 return -EINVAL;
8260
8261 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8262 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8263
8264 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8265 tokens_size = tokln - sizeof(*tok);
8266
8267 if (!tok->len || tokens_size % tok->len)
8268 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008269 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008270 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008271 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008272 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008273 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008274 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008275 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008276 return -EINVAL;
8277 if (tok->offset + tok->len > data_size)
8278 return -EINVAL;
8279 }
8280
8281 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8282 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008283 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008284 return -EINVAL;
8285 if (seq->len == 0 || seq->len > 4)
8286 return -EINVAL;
8287 if (seq->len + seq->offset > data_size)
8288 return -EINVAL;
8289 }
8290
8291 size = sizeof(*cfg);
8292 size += data_size;
8293 size += wake_size + wake_mask_size;
8294 size += tokens_size;
8295
8296 cfg = kzalloc(size, GFP_KERNEL);
8297 if (!cfg)
8298 return -ENOMEM;
8299 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8300 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8301 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8302 ETH_ALEN);
8303 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8304 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8305 else
8306 port = 0;
8307#ifdef CONFIG_INET
8308 /* allocate a socket and port for it and use it */
8309 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8310 IPPROTO_TCP, &cfg->sock, 1);
8311 if (err) {
8312 kfree(cfg);
8313 return err;
8314 }
8315 if (inet_csk_get_port(cfg->sock->sk, port)) {
8316 sock_release(cfg->sock);
8317 kfree(cfg);
8318 return -EADDRINUSE;
8319 }
8320 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8321#else
8322 if (!port) {
8323 kfree(cfg);
8324 return -EINVAL;
8325 }
8326 cfg->src_port = port;
8327#endif
8328
8329 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8330 cfg->payload_len = data_size;
8331 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8332 memcpy((void *)cfg->payload,
8333 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8334 data_size);
8335 if (seq)
8336 cfg->payload_seq = *seq;
8337 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8338 cfg->wake_len = wake_size;
8339 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8340 memcpy((void *)cfg->wake_data,
8341 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8342 wake_size);
8343 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8344 data_size + wake_size;
8345 memcpy((void *)cfg->wake_mask,
8346 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8347 wake_mask_size);
8348 if (tok) {
8349 cfg->tokens_size = tokens_size;
8350 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8351 }
8352
8353 trig->tcp = cfg;
8354
8355 return 0;
8356}
8357
Johannes Bergff1b6e62011-05-04 15:37:28 +02008358static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8359{
8360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8361 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008362 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008363 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008364 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008365 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008366 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008367
Johannes Berg964dc9e2013-06-03 17:25:34 +02008368 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008369 return -EOPNOTSUPP;
8370
Johannes Bergae33bd82012-07-12 16:25:02 +02008371 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8372 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008373 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008374 goto set_wakeup;
8375 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008376
8377 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8378 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8379 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8380 nl80211_wowlan_policy);
8381 if (err)
8382 return err;
8383
8384 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8385 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8386 return -EINVAL;
8387 new_triggers.any = true;
8388 }
8389
8390 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8391 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8392 return -EINVAL;
8393 new_triggers.disconnect = true;
8394 }
8395
8396 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8397 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8398 return -EINVAL;
8399 new_triggers.magic_pkt = true;
8400 }
8401
Johannes Berg77dbbb12011-07-13 10:48:55 +02008402 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8403 return -EINVAL;
8404
8405 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8406 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8407 return -EINVAL;
8408 new_triggers.gtk_rekey_failure = true;
8409 }
8410
8411 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8412 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8413 return -EINVAL;
8414 new_triggers.eap_identity_req = true;
8415 }
8416
8417 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8418 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8419 return -EINVAL;
8420 new_triggers.four_way_handshake = true;
8421 }
8422
8423 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8424 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8425 return -EINVAL;
8426 new_triggers.rfkill_release = true;
8427 }
8428
Johannes Bergff1b6e62011-05-04 15:37:28 +02008429 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8430 struct nlattr *pat;
8431 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008432 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008433 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008434
8435 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8436 rem)
8437 n_patterns++;
8438 if (n_patterns > wowlan->n_patterns)
8439 return -EINVAL;
8440
8441 new_triggers.patterns = kcalloc(n_patterns,
8442 sizeof(new_triggers.patterns[0]),
8443 GFP_KERNEL);
8444 if (!new_triggers.patterns)
8445 return -ENOMEM;
8446
8447 new_triggers.n_patterns = n_patterns;
8448 i = 0;
8449
8450 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8451 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008452 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8453 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008454 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008455 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8456 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008457 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008458 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008459 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008460 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008461 goto error;
8462 if (pat_len > wowlan->pattern_max_len ||
8463 pat_len < wowlan->pattern_min_len)
8464 goto error;
8465
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008466 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008467 pkt_offset = 0;
8468 else
8469 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008470 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008471 if (pkt_offset > wowlan->max_pkt_offset)
8472 goto error;
8473 new_triggers.patterns[i].pkt_offset = pkt_offset;
8474
Johannes Bergff1b6e62011-05-04 15:37:28 +02008475 new_triggers.patterns[i].mask =
8476 kmalloc(mask_len + pat_len, GFP_KERNEL);
8477 if (!new_triggers.patterns[i].mask) {
8478 err = -ENOMEM;
8479 goto error;
8480 }
8481 new_triggers.patterns[i].pattern =
8482 new_triggers.patterns[i].mask + mask_len;
8483 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008484 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008485 mask_len);
8486 new_triggers.patterns[i].pattern_len = pat_len;
8487 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008488 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008489 pat_len);
8490 i++;
8491 }
8492 }
8493
Johannes Berg2a0e0472013-01-23 22:57:40 +01008494 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8495 err = nl80211_parse_wowlan_tcp(
8496 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8497 &new_triggers);
8498 if (err)
8499 goto error;
8500 }
8501
Johannes Bergae33bd82012-07-12 16:25:02 +02008502 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8503 if (!ntrig) {
8504 err = -ENOMEM;
8505 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008506 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008507 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008508 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008509
Johannes Bergae33bd82012-07-12 16:25:02 +02008510 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008511 if (rdev->ops->set_wakeup &&
8512 prev_enabled != !!rdev->wiphy.wowlan_config)
8513 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008514
Johannes Bergff1b6e62011-05-04 15:37:28 +02008515 return 0;
8516 error:
8517 for (i = 0; i < new_triggers.n_patterns; i++)
8518 kfree(new_triggers.patterns[i].mask);
8519 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008520 if (new_triggers.tcp && new_triggers.tcp->sock)
8521 sock_release(new_triggers.tcp->sock);
8522 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008523 return err;
8524}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008525#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008526
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008527static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8528 struct cfg80211_registered_device *rdev)
8529{
8530 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8531 int i, j, pat_len;
8532 struct cfg80211_coalesce_rules *rule;
8533
8534 if (!rdev->coalesce->n_rules)
8535 return 0;
8536
8537 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8538 if (!nl_rules)
8539 return -ENOBUFS;
8540
8541 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8542 nl_rule = nla_nest_start(msg, i + 1);
8543 if (!nl_rule)
8544 return -ENOBUFS;
8545
8546 rule = &rdev->coalesce->rules[i];
8547 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8548 rule->delay))
8549 return -ENOBUFS;
8550
8551 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8552 rule->condition))
8553 return -ENOBUFS;
8554
8555 nl_pats = nla_nest_start(msg,
8556 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8557 if (!nl_pats)
8558 return -ENOBUFS;
8559
8560 for (j = 0; j < rule->n_patterns; j++) {
8561 nl_pat = nla_nest_start(msg, j + 1);
8562 if (!nl_pat)
8563 return -ENOBUFS;
8564 pat_len = rule->patterns[j].pattern_len;
8565 if (nla_put(msg, NL80211_PKTPAT_MASK,
8566 DIV_ROUND_UP(pat_len, 8),
8567 rule->patterns[j].mask) ||
8568 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8569 rule->patterns[j].pattern) ||
8570 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8571 rule->patterns[j].pkt_offset))
8572 return -ENOBUFS;
8573 nla_nest_end(msg, nl_pat);
8574 }
8575 nla_nest_end(msg, nl_pats);
8576 nla_nest_end(msg, nl_rule);
8577 }
8578 nla_nest_end(msg, nl_rules);
8579
8580 return 0;
8581}
8582
8583static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8584{
8585 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8586 struct sk_buff *msg;
8587 void *hdr;
8588
8589 if (!rdev->wiphy.coalesce)
8590 return -EOPNOTSUPP;
8591
8592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8593 if (!msg)
8594 return -ENOMEM;
8595
8596 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8597 NL80211_CMD_GET_COALESCE);
8598 if (!hdr)
8599 goto nla_put_failure;
8600
8601 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8602 goto nla_put_failure;
8603
8604 genlmsg_end(msg, hdr);
8605 return genlmsg_reply(msg, info);
8606
8607nla_put_failure:
8608 nlmsg_free(msg);
8609 return -ENOBUFS;
8610}
8611
8612void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8613{
8614 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8615 int i, j;
8616 struct cfg80211_coalesce_rules *rule;
8617
8618 if (!coalesce)
8619 return;
8620
8621 for (i = 0; i < coalesce->n_rules; i++) {
8622 rule = &coalesce->rules[i];
8623 for (j = 0; j < rule->n_patterns; j++)
8624 kfree(rule->patterns[j].mask);
8625 kfree(rule->patterns);
8626 }
8627 kfree(coalesce->rules);
8628 kfree(coalesce);
8629 rdev->coalesce = NULL;
8630}
8631
8632static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8633 struct nlattr *rule,
8634 struct cfg80211_coalesce_rules *new_rule)
8635{
8636 int err, i;
8637 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8638 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8639 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8640 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8641
8642 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8643 nla_len(rule), nl80211_coalesce_policy);
8644 if (err)
8645 return err;
8646
8647 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8648 new_rule->delay =
8649 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8650 if (new_rule->delay > coalesce->max_delay)
8651 return -EINVAL;
8652
8653 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8654 new_rule->condition =
8655 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8656 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8657 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8658 return -EINVAL;
8659
8660 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8661 return -EINVAL;
8662
8663 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8664 rem)
8665 n_patterns++;
8666 if (n_patterns > coalesce->n_patterns)
8667 return -EINVAL;
8668
8669 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8670 GFP_KERNEL);
8671 if (!new_rule->patterns)
8672 return -ENOMEM;
8673
8674 new_rule->n_patterns = n_patterns;
8675 i = 0;
8676
8677 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8678 rem) {
8679 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8680 nla_len(pat), NULL);
8681 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8682 !pat_tb[NL80211_PKTPAT_PATTERN])
8683 return -EINVAL;
8684 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8685 mask_len = DIV_ROUND_UP(pat_len, 8);
8686 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8687 return -EINVAL;
8688 if (pat_len > coalesce->pattern_max_len ||
8689 pat_len < coalesce->pattern_min_len)
8690 return -EINVAL;
8691
8692 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8693 pkt_offset = 0;
8694 else
8695 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8696 if (pkt_offset > coalesce->max_pkt_offset)
8697 return -EINVAL;
8698 new_rule->patterns[i].pkt_offset = pkt_offset;
8699
8700 new_rule->patterns[i].mask =
8701 kmalloc(mask_len + pat_len, GFP_KERNEL);
8702 if (!new_rule->patterns[i].mask)
8703 return -ENOMEM;
8704 new_rule->patterns[i].pattern =
8705 new_rule->patterns[i].mask + mask_len;
8706 memcpy(new_rule->patterns[i].mask,
8707 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8708 new_rule->patterns[i].pattern_len = pat_len;
8709 memcpy(new_rule->patterns[i].pattern,
8710 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8711 i++;
8712 }
8713
8714 return 0;
8715}
8716
8717static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8718{
8719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8720 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8721 struct cfg80211_coalesce new_coalesce = {};
8722 struct cfg80211_coalesce *n_coalesce;
8723 int err, rem_rule, n_rules = 0, i, j;
8724 struct nlattr *rule;
8725 struct cfg80211_coalesce_rules *tmp_rule;
8726
8727 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8728 return -EOPNOTSUPP;
8729
8730 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8731 cfg80211_rdev_free_coalesce(rdev);
8732 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8733 return 0;
8734 }
8735
8736 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8737 rem_rule)
8738 n_rules++;
8739 if (n_rules > coalesce->n_rules)
8740 return -EINVAL;
8741
8742 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8743 GFP_KERNEL);
8744 if (!new_coalesce.rules)
8745 return -ENOMEM;
8746
8747 new_coalesce.n_rules = n_rules;
8748 i = 0;
8749
8750 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8751 rem_rule) {
8752 err = nl80211_parse_coalesce_rule(rdev, rule,
8753 &new_coalesce.rules[i]);
8754 if (err)
8755 goto error;
8756
8757 i++;
8758 }
8759
8760 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8761 if (err)
8762 goto error;
8763
8764 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8765 if (!n_coalesce) {
8766 err = -ENOMEM;
8767 goto error;
8768 }
8769 cfg80211_rdev_free_coalesce(rdev);
8770 rdev->coalesce = n_coalesce;
8771
8772 return 0;
8773error:
8774 for (i = 0; i < new_coalesce.n_rules; i++) {
8775 tmp_rule = &new_coalesce.rules[i];
8776 for (j = 0; j < tmp_rule->n_patterns; j++)
8777 kfree(tmp_rule->patterns[j].mask);
8778 kfree(tmp_rule->patterns);
8779 }
8780 kfree(new_coalesce.rules);
8781
8782 return err;
8783}
8784
Johannes Berge5497d72011-07-05 16:35:40 +02008785static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8786{
8787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8788 struct net_device *dev = info->user_ptr[1];
8789 struct wireless_dev *wdev = dev->ieee80211_ptr;
8790 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8791 struct cfg80211_gtk_rekey_data rekey_data;
8792 int err;
8793
8794 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8795 return -EINVAL;
8796
8797 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8798 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8799 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8800 nl80211_rekey_policy);
8801 if (err)
8802 return err;
8803
8804 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8805 return -ERANGE;
8806 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8807 return -ERANGE;
8808 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8809 return -ERANGE;
8810
8811 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8812 NL80211_KEK_LEN);
8813 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8814 NL80211_KCK_LEN);
8815 memcpy(rekey_data.replay_ctr,
8816 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8817 NL80211_REPLAY_CTR_LEN);
8818
8819 wdev_lock(wdev);
8820 if (!wdev->current_bss) {
8821 err = -ENOTCONN;
8822 goto out;
8823 }
8824
8825 if (!rdev->ops->set_rekey_data) {
8826 err = -EOPNOTSUPP;
8827 goto out;
8828 }
8829
Hila Gonene35e4d22012-06-27 17:19:42 +03008830 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008831 out:
8832 wdev_unlock(wdev);
8833 return err;
8834}
8835
Johannes Berg28946da2011-11-04 11:18:12 +01008836static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8837 struct genl_info *info)
8838{
8839 struct net_device *dev = info->user_ptr[1];
8840 struct wireless_dev *wdev = dev->ieee80211_ptr;
8841
8842 if (wdev->iftype != NL80211_IFTYPE_AP &&
8843 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8844 return -EINVAL;
8845
Eric W. Biederman15e47302012-09-07 20:12:54 +00008846 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008847 return -EBUSY;
8848
Eric W. Biederman15e47302012-09-07 20:12:54 +00008849 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008850 return 0;
8851}
8852
Johannes Berg7f6cf312011-11-04 11:18:15 +01008853static int nl80211_probe_client(struct sk_buff *skb,
8854 struct genl_info *info)
8855{
8856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8857 struct net_device *dev = info->user_ptr[1];
8858 struct wireless_dev *wdev = dev->ieee80211_ptr;
8859 struct sk_buff *msg;
8860 void *hdr;
8861 const u8 *addr;
8862 u64 cookie;
8863 int err;
8864
8865 if (wdev->iftype != NL80211_IFTYPE_AP &&
8866 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8867 return -EOPNOTSUPP;
8868
8869 if (!info->attrs[NL80211_ATTR_MAC])
8870 return -EINVAL;
8871
8872 if (!rdev->ops->probe_client)
8873 return -EOPNOTSUPP;
8874
8875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8876 if (!msg)
8877 return -ENOMEM;
8878
Eric W. Biederman15e47302012-09-07 20:12:54 +00008879 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008880 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008881 if (!hdr) {
8882 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008883 goto free_msg;
8884 }
8885
8886 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8887
Hila Gonene35e4d22012-06-27 17:19:42 +03008888 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008889 if (err)
8890 goto free_msg;
8891
David S. Miller9360ffd2012-03-29 04:41:26 -04008892 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8893 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008894
8895 genlmsg_end(msg, hdr);
8896
8897 return genlmsg_reply(msg, info);
8898
8899 nla_put_failure:
8900 err = -ENOBUFS;
8901 free_msg:
8902 nlmsg_free(msg);
8903 return err;
8904}
8905
Johannes Berg5e760232011-11-04 11:18:17 +01008906static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8907{
8908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008909 struct cfg80211_beacon_registration *reg, *nreg;
8910 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008911
8912 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8913 return -EOPNOTSUPP;
8914
Ben Greear37c73b52012-10-26 14:49:25 -07008915 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8916 if (!nreg)
8917 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008918
Ben Greear37c73b52012-10-26 14:49:25 -07008919 /* First, check if already registered. */
8920 spin_lock_bh(&rdev->beacon_registrations_lock);
8921 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8922 if (reg->nlportid == info->snd_portid) {
8923 rv = -EALREADY;
8924 goto out_err;
8925 }
8926 }
8927 /* Add it to the list */
8928 nreg->nlportid = info->snd_portid;
8929 list_add(&nreg->list, &rdev->beacon_registrations);
8930
8931 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008932
8933 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008934out_err:
8935 spin_unlock_bh(&rdev->beacon_registrations_lock);
8936 kfree(nreg);
8937 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008938}
8939
Johannes Berg98104fde2012-06-16 00:19:54 +02008940static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8941{
8942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8943 struct wireless_dev *wdev = info->user_ptr[1];
8944 int err;
8945
8946 if (!rdev->ops->start_p2p_device)
8947 return -EOPNOTSUPP;
8948
8949 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8950 return -EOPNOTSUPP;
8951
8952 if (wdev->p2p_started)
8953 return 0;
8954
Johannes Berg98104fde2012-06-16 00:19:54 +02008955 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008956 if (err)
8957 return err;
8958
Johannes Bergeeb126e2012-10-23 15:16:50 +02008959 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008960 if (err)
8961 return err;
8962
8963 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008964 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008965
8966 return 0;
8967}
8968
8969static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8970{
8971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8972 struct wireless_dev *wdev = info->user_ptr[1];
8973
8974 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8975 return -EOPNOTSUPP;
8976
8977 if (!rdev->ops->stop_p2p_device)
8978 return -EOPNOTSUPP;
8979
Johannes Bergf9f47522013-03-19 15:04:07 +01008980 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008981
8982 return 0;
8983}
8984
Johannes Berg3713b4e2013-02-14 16:19:38 +01008985static int nl80211_get_protocol_features(struct sk_buff *skb,
8986 struct genl_info *info)
8987{
8988 void *hdr;
8989 struct sk_buff *msg;
8990
8991 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8992 if (!msg)
8993 return -ENOMEM;
8994
8995 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8996 NL80211_CMD_GET_PROTOCOL_FEATURES);
8997 if (!hdr)
8998 goto nla_put_failure;
8999
9000 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9001 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9002 goto nla_put_failure;
9003
9004 genlmsg_end(msg, hdr);
9005 return genlmsg_reply(msg, info);
9006
9007 nla_put_failure:
9008 kfree_skb(msg);
9009 return -ENOBUFS;
9010}
9011
Jouni Malinen355199e2013-02-27 17:14:27 +02009012static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9013{
9014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9015 struct cfg80211_update_ft_ies_params ft_params;
9016 struct net_device *dev = info->user_ptr[1];
9017
9018 if (!rdev->ops->update_ft_ies)
9019 return -EOPNOTSUPP;
9020
9021 if (!info->attrs[NL80211_ATTR_MDID] ||
9022 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9023 return -EINVAL;
9024
9025 memset(&ft_params, 0, sizeof(ft_params));
9026 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9027 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9028 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9029
9030 return rdev_update_ft_ies(rdev, dev, &ft_params);
9031}
9032
Arend van Spriel5de17982013-04-18 15:49:00 +02009033static int nl80211_crit_protocol_start(struct sk_buff *skb,
9034 struct genl_info *info)
9035{
9036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9037 struct wireless_dev *wdev = info->user_ptr[1];
9038 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9039 u16 duration;
9040 int ret;
9041
9042 if (!rdev->ops->crit_proto_start)
9043 return -EOPNOTSUPP;
9044
9045 if (WARN_ON(!rdev->ops->crit_proto_stop))
9046 return -EINVAL;
9047
9048 if (rdev->crit_proto_nlportid)
9049 return -EBUSY;
9050
9051 /* determine protocol if provided */
9052 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9053 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9054
9055 if (proto >= NUM_NL80211_CRIT_PROTO)
9056 return -EINVAL;
9057
9058 /* timeout must be provided */
9059 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9060 return -EINVAL;
9061
9062 duration =
9063 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9064
9065 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9066 return -ERANGE;
9067
9068 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9069 if (!ret)
9070 rdev->crit_proto_nlportid = info->snd_portid;
9071
9072 return ret;
9073}
9074
9075static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9076 struct genl_info *info)
9077{
9078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9079 struct wireless_dev *wdev = info->user_ptr[1];
9080
9081 if (!rdev->ops->crit_proto_stop)
9082 return -EOPNOTSUPP;
9083
9084 if (rdev->crit_proto_nlportid) {
9085 rdev->crit_proto_nlportid = 0;
9086 rdev_crit_proto_stop(rdev, wdev);
9087 }
9088 return 0;
9089}
9090
Johannes Bergad7e7182013-11-13 13:37:47 +01009091static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9092{
9093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9094 struct wireless_dev *wdev =
9095 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9096 int i, err;
9097 u32 vid, subcmd;
9098
9099 if (!rdev->wiphy.vendor_commands)
9100 return -EOPNOTSUPP;
9101
9102 if (IS_ERR(wdev)) {
9103 err = PTR_ERR(wdev);
9104 if (err != -EINVAL)
9105 return err;
9106 wdev = NULL;
9107 } else if (wdev->wiphy != &rdev->wiphy) {
9108 return -EINVAL;
9109 }
9110
9111 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9112 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9113 return -EINVAL;
9114
9115 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9116 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9117 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9118 const struct wiphy_vendor_command *vcmd;
9119 void *data = NULL;
9120 int len = 0;
9121
9122 vcmd = &rdev->wiphy.vendor_commands[i];
9123
9124 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9125 continue;
9126
9127 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9128 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9129 if (!wdev)
9130 return -EINVAL;
9131 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9132 !wdev->netdev)
9133 return -EINVAL;
9134
9135 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9136 if (wdev->netdev &&
9137 !netif_running(wdev->netdev))
9138 return -ENETDOWN;
9139 if (!wdev->netdev && !wdev->p2p_started)
9140 return -ENETDOWN;
9141 }
9142 } else {
9143 wdev = NULL;
9144 }
9145
9146 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9147 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9148 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9149 }
9150
9151 rdev->cur_cmd_info = info;
9152 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9153 data, len);
9154 rdev->cur_cmd_info = NULL;
9155 return err;
9156 }
9157
9158 return -EOPNOTSUPP;
9159}
9160
9161struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9162 enum nl80211_commands cmd,
9163 enum nl80211_attrs attr,
9164 int approxlen)
9165{
9166 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9167
9168 if (WARN_ON(!rdev->cur_cmd_info))
9169 return NULL;
9170
9171 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9172 rdev->cur_cmd_info->snd_portid,
9173 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009174 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009175}
9176EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9177
9178int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9179{
9180 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9181 void *hdr = ((void **)skb->cb)[1];
9182 struct nlattr *data = ((void **)skb->cb)[2];
9183
9184 if (WARN_ON(!rdev->cur_cmd_info)) {
9185 kfree_skb(skb);
9186 return -EINVAL;
9187 }
9188
9189 nla_nest_end(skb, data);
9190 genlmsg_end(skb, hdr);
9191 return genlmsg_reply(skb, rdev->cur_cmd_info);
9192}
9193EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9194
9195
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009196static int nl80211_set_qos_map(struct sk_buff *skb,
9197 struct genl_info *info)
9198{
9199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9200 struct cfg80211_qos_map *qos_map = NULL;
9201 struct net_device *dev = info->user_ptr[1];
9202 u8 *pos, len, num_des, des_len, des;
9203 int ret;
9204
9205 if (!rdev->ops->set_qos_map)
9206 return -EOPNOTSUPP;
9207
9208 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9209 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9210 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9211
9212 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9213 len > IEEE80211_QOS_MAP_LEN_MAX)
9214 return -EINVAL;
9215
9216 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9217 if (!qos_map)
9218 return -ENOMEM;
9219
9220 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9221 if (num_des) {
9222 des_len = num_des *
9223 sizeof(struct cfg80211_dscp_exception);
9224 memcpy(qos_map->dscp_exception, pos, des_len);
9225 qos_map->num_des = num_des;
9226 for (des = 0; des < num_des; des++) {
9227 if (qos_map->dscp_exception[des].up > 7) {
9228 kfree(qos_map);
9229 return -EINVAL;
9230 }
9231 }
9232 pos += des_len;
9233 }
9234 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9235 }
9236
9237 wdev_lock(dev->ieee80211_ptr);
9238 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9239 if (!ret)
9240 ret = rdev_set_qos_map(rdev, dev, qos_map);
9241 wdev_unlock(dev->ieee80211_ptr);
9242
9243 kfree(qos_map);
9244 return ret;
9245}
9246
Johannes Berg4c476992010-10-04 21:36:35 +02009247#define NL80211_FLAG_NEED_WIPHY 0x01
9248#define NL80211_FLAG_NEED_NETDEV 0x02
9249#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009250#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9251#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9252 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009253#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009254/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009255#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9256 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009257
Johannes Bergf84f7712013-11-14 17:14:45 +01009258static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009259 struct genl_info *info)
9260{
9261 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009262 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009263 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009264 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9265
9266 if (rtnl)
9267 rtnl_lock();
9268
9269 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009270 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009271 if (IS_ERR(rdev)) {
9272 if (rtnl)
9273 rtnl_unlock();
9274 return PTR_ERR(rdev);
9275 }
9276 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009277 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9278 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009279 ASSERT_RTNL();
9280
Johannes Berg89a54e42012-06-15 14:33:17 +02009281 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9282 info->attrs);
9283 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009284 if (rtnl)
9285 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009286 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009287 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009288
Johannes Berg89a54e42012-06-15 14:33:17 +02009289 dev = wdev->netdev;
9290 rdev = wiphy_to_dev(wdev->wiphy);
9291
Johannes Berg1bf614e2012-06-15 15:23:36 +02009292 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9293 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009294 if (rtnl)
9295 rtnl_unlock();
9296 return -EINVAL;
9297 }
9298
9299 info->user_ptr[1] = dev;
9300 } else {
9301 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009302 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009303
Johannes Berg1bf614e2012-06-15 15:23:36 +02009304 if (dev) {
9305 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9306 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009307 if (rtnl)
9308 rtnl_unlock();
9309 return -ENETDOWN;
9310 }
9311
9312 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009313 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9314 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009315 if (rtnl)
9316 rtnl_unlock();
9317 return -ENETDOWN;
9318 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009319 }
9320
Johannes Berg4c476992010-10-04 21:36:35 +02009321 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009322 }
9323
9324 return 0;
9325}
9326
Johannes Bergf84f7712013-11-14 17:14:45 +01009327static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009328 struct genl_info *info)
9329{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009330 if (info->user_ptr[1]) {
9331 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9332 struct wireless_dev *wdev = info->user_ptr[1];
9333
9334 if (wdev->netdev)
9335 dev_put(wdev->netdev);
9336 } else {
9337 dev_put(info->user_ptr[1]);
9338 }
9339 }
Johannes Berg4c476992010-10-04 21:36:35 +02009340 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9341 rtnl_unlock();
9342}
9343
Johannes Berg4534de82013-11-14 17:14:46 +01009344static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009345 {
9346 .cmd = NL80211_CMD_GET_WIPHY,
9347 .doit = nl80211_get_wiphy,
9348 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009349 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009350 .policy = nl80211_policy,
9351 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009352 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9353 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009354 },
9355 {
9356 .cmd = NL80211_CMD_SET_WIPHY,
9357 .doit = nl80211_set_wiphy,
9358 .policy = nl80211_policy,
9359 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009360 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009361 },
9362 {
9363 .cmd = NL80211_CMD_GET_INTERFACE,
9364 .doit = nl80211_get_interface,
9365 .dumpit = nl80211_dump_interface,
9366 .policy = nl80211_policy,
9367 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009368 .internal_flags = NL80211_FLAG_NEED_WDEV |
9369 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009370 },
9371 {
9372 .cmd = NL80211_CMD_SET_INTERFACE,
9373 .doit = nl80211_set_interface,
9374 .policy = nl80211_policy,
9375 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009376 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9377 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009378 },
9379 {
9380 .cmd = NL80211_CMD_NEW_INTERFACE,
9381 .doit = nl80211_new_interface,
9382 .policy = nl80211_policy,
9383 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009384 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9385 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009386 },
9387 {
9388 .cmd = NL80211_CMD_DEL_INTERFACE,
9389 .doit = nl80211_del_interface,
9390 .policy = nl80211_policy,
9391 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009392 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009393 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009394 },
Johannes Berg41ade002007-12-19 02:03:29 +01009395 {
9396 .cmd = NL80211_CMD_GET_KEY,
9397 .doit = nl80211_get_key,
9398 .policy = nl80211_policy,
9399 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009401 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009402 },
9403 {
9404 .cmd = NL80211_CMD_SET_KEY,
9405 .doit = nl80211_set_key,
9406 .policy = nl80211_policy,
9407 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009409 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009410 },
9411 {
9412 .cmd = NL80211_CMD_NEW_KEY,
9413 .doit = nl80211_new_key,
9414 .policy = nl80211_policy,
9415 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009416 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009417 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009418 },
9419 {
9420 .cmd = NL80211_CMD_DEL_KEY,
9421 .doit = nl80211_del_key,
9422 .policy = nl80211_policy,
9423 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009424 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009425 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009426 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009427 {
9428 .cmd = NL80211_CMD_SET_BEACON,
9429 .policy = nl80211_policy,
9430 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009431 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009432 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009433 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009434 },
9435 {
Johannes Berg88600202012-02-13 15:17:18 +01009436 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009437 .policy = nl80211_policy,
9438 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009439 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009440 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009441 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009442 },
9443 {
Johannes Berg88600202012-02-13 15:17:18 +01009444 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009445 .policy = nl80211_policy,
9446 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009447 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009448 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009449 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009450 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009451 {
9452 .cmd = NL80211_CMD_GET_STATION,
9453 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009454 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009455 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009456 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9457 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009458 },
9459 {
9460 .cmd = NL80211_CMD_SET_STATION,
9461 .doit = nl80211_set_station,
9462 .policy = nl80211_policy,
9463 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009465 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009466 },
9467 {
9468 .cmd = NL80211_CMD_NEW_STATION,
9469 .doit = nl80211_new_station,
9470 .policy = nl80211_policy,
9471 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009473 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009474 },
9475 {
9476 .cmd = NL80211_CMD_DEL_STATION,
9477 .doit = nl80211_del_station,
9478 .policy = nl80211_policy,
9479 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009481 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009482 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009483 {
9484 .cmd = NL80211_CMD_GET_MPATH,
9485 .doit = nl80211_get_mpath,
9486 .dumpit = nl80211_dump_mpath,
9487 .policy = nl80211_policy,
9488 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009489 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009490 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009491 },
9492 {
9493 .cmd = NL80211_CMD_SET_MPATH,
9494 .doit = nl80211_set_mpath,
9495 .policy = nl80211_policy,
9496 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009498 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009499 },
9500 {
9501 .cmd = NL80211_CMD_NEW_MPATH,
9502 .doit = nl80211_new_mpath,
9503 .policy = nl80211_policy,
9504 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009505 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009506 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009507 },
9508 {
9509 .cmd = NL80211_CMD_DEL_MPATH,
9510 .doit = nl80211_del_mpath,
9511 .policy = nl80211_policy,
9512 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009513 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009514 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009515 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009516 {
9517 .cmd = NL80211_CMD_SET_BSS,
9518 .doit = nl80211_set_bss,
9519 .policy = nl80211_policy,
9520 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009522 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009523 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009524 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009525 .cmd = NL80211_CMD_GET_REG,
9526 .doit = nl80211_get_reg,
9527 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009528 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009529 /* can be retrieved by unprivileged users */
9530 },
9531 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009532 .cmd = NL80211_CMD_SET_REG,
9533 .doit = nl80211_set_reg,
9534 .policy = nl80211_policy,
9535 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009536 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009537 },
9538 {
9539 .cmd = NL80211_CMD_REQ_SET_REG,
9540 .doit = nl80211_req_set_reg,
9541 .policy = nl80211_policy,
9542 .flags = GENL_ADMIN_PERM,
9543 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009544 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009545 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9546 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009547 .policy = nl80211_policy,
9548 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009550 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009551 },
9552 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009553 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9554 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009555 .policy = nl80211_policy,
9556 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009557 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009558 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009559 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009560 {
Johannes Berg2a519312009-02-10 21:25:55 +01009561 .cmd = NL80211_CMD_TRIGGER_SCAN,
9562 .doit = nl80211_trigger_scan,
9563 .policy = nl80211_policy,
9564 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009565 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009566 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009567 },
9568 {
9569 .cmd = NL80211_CMD_GET_SCAN,
9570 .policy = nl80211_policy,
9571 .dumpit = nl80211_dump_scan,
9572 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009573 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009574 .cmd = NL80211_CMD_START_SCHED_SCAN,
9575 .doit = nl80211_start_sched_scan,
9576 .policy = nl80211_policy,
9577 .flags = GENL_ADMIN_PERM,
9578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9579 NL80211_FLAG_NEED_RTNL,
9580 },
9581 {
9582 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9583 .doit = nl80211_stop_sched_scan,
9584 .policy = nl80211_policy,
9585 .flags = GENL_ADMIN_PERM,
9586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9587 NL80211_FLAG_NEED_RTNL,
9588 },
9589 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009590 .cmd = NL80211_CMD_AUTHENTICATE,
9591 .doit = nl80211_authenticate,
9592 .policy = nl80211_policy,
9593 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009595 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009596 },
9597 {
9598 .cmd = NL80211_CMD_ASSOCIATE,
9599 .doit = nl80211_associate,
9600 .policy = nl80211_policy,
9601 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009603 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009604 },
9605 {
9606 .cmd = NL80211_CMD_DEAUTHENTICATE,
9607 .doit = nl80211_deauthenticate,
9608 .policy = nl80211_policy,
9609 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009611 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009612 },
9613 {
9614 .cmd = NL80211_CMD_DISASSOCIATE,
9615 .doit = nl80211_disassociate,
9616 .policy = nl80211_policy,
9617 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009619 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009620 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009621 {
9622 .cmd = NL80211_CMD_JOIN_IBSS,
9623 .doit = nl80211_join_ibss,
9624 .policy = nl80211_policy,
9625 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009627 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009628 },
9629 {
9630 .cmd = NL80211_CMD_LEAVE_IBSS,
9631 .doit = nl80211_leave_ibss,
9632 .policy = nl80211_policy,
9633 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009634 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009635 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009636 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009637#ifdef CONFIG_NL80211_TESTMODE
9638 {
9639 .cmd = NL80211_CMD_TESTMODE,
9640 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009641 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009642 .policy = nl80211_policy,
9643 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009644 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9645 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009646 },
9647#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009648 {
9649 .cmd = NL80211_CMD_CONNECT,
9650 .doit = nl80211_connect,
9651 .policy = nl80211_policy,
9652 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009653 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009654 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009655 },
9656 {
9657 .cmd = NL80211_CMD_DISCONNECT,
9658 .doit = nl80211_disconnect,
9659 .policy = nl80211_policy,
9660 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009662 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009663 },
Johannes Berg463d0182009-07-14 00:33:35 +02009664 {
9665 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9666 .doit = nl80211_wiphy_netns,
9667 .policy = nl80211_policy,
9668 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009669 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9670 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009671 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009672 {
9673 .cmd = NL80211_CMD_GET_SURVEY,
9674 .policy = nl80211_policy,
9675 .dumpit = nl80211_dump_survey,
9676 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009677 {
9678 .cmd = NL80211_CMD_SET_PMKSA,
9679 .doit = nl80211_setdel_pmksa,
9680 .policy = nl80211_policy,
9681 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009682 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009683 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009684 },
9685 {
9686 .cmd = NL80211_CMD_DEL_PMKSA,
9687 .doit = nl80211_setdel_pmksa,
9688 .policy = nl80211_policy,
9689 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009690 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009691 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009692 },
9693 {
9694 .cmd = NL80211_CMD_FLUSH_PMKSA,
9695 .doit = nl80211_flush_pmksa,
9696 .policy = nl80211_policy,
9697 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009699 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009700 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009701 {
9702 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9703 .doit = nl80211_remain_on_channel,
9704 .policy = nl80211_policy,
9705 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009706 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009707 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009708 },
9709 {
9710 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9711 .doit = nl80211_cancel_remain_on_channel,
9712 .policy = nl80211_policy,
9713 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009714 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009715 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009716 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009717 {
9718 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9719 .doit = nl80211_set_tx_bitrate_mask,
9720 .policy = nl80211_policy,
9721 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009722 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9723 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009724 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009725 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009726 .cmd = NL80211_CMD_REGISTER_FRAME,
9727 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009728 .policy = nl80211_policy,
9729 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009730 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009731 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009732 },
9733 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009734 .cmd = NL80211_CMD_FRAME,
9735 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009736 .policy = nl80211_policy,
9737 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009738 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009739 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009740 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009741 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009742 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9743 .doit = nl80211_tx_mgmt_cancel_wait,
9744 .policy = nl80211_policy,
9745 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009746 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009747 NL80211_FLAG_NEED_RTNL,
9748 },
9749 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009750 .cmd = NL80211_CMD_SET_POWER_SAVE,
9751 .doit = nl80211_set_power_save,
9752 .policy = nl80211_policy,
9753 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009754 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9755 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009756 },
9757 {
9758 .cmd = NL80211_CMD_GET_POWER_SAVE,
9759 .doit = nl80211_get_power_save,
9760 .policy = nl80211_policy,
9761 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009762 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9763 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009764 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009765 {
9766 .cmd = NL80211_CMD_SET_CQM,
9767 .doit = nl80211_set_cqm,
9768 .policy = nl80211_policy,
9769 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009770 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9771 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009772 },
Johannes Bergf444de02010-05-05 15:25:02 +02009773 {
9774 .cmd = NL80211_CMD_SET_CHANNEL,
9775 .doit = nl80211_set_channel,
9776 .policy = nl80211_policy,
9777 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009778 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9779 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009780 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009781 {
9782 .cmd = NL80211_CMD_SET_WDS_PEER,
9783 .doit = nl80211_set_wds_peer,
9784 .policy = nl80211_policy,
9785 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009786 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9787 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009788 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009789 {
9790 .cmd = NL80211_CMD_JOIN_MESH,
9791 .doit = nl80211_join_mesh,
9792 .policy = nl80211_policy,
9793 .flags = GENL_ADMIN_PERM,
9794 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9795 NL80211_FLAG_NEED_RTNL,
9796 },
9797 {
9798 .cmd = NL80211_CMD_LEAVE_MESH,
9799 .doit = nl80211_leave_mesh,
9800 .policy = nl80211_policy,
9801 .flags = GENL_ADMIN_PERM,
9802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9803 NL80211_FLAG_NEED_RTNL,
9804 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009805#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009806 {
9807 .cmd = NL80211_CMD_GET_WOWLAN,
9808 .doit = nl80211_get_wowlan,
9809 .policy = nl80211_policy,
9810 /* can be retrieved by unprivileged users */
9811 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9812 NL80211_FLAG_NEED_RTNL,
9813 },
9814 {
9815 .cmd = NL80211_CMD_SET_WOWLAN,
9816 .doit = nl80211_set_wowlan,
9817 .policy = nl80211_policy,
9818 .flags = GENL_ADMIN_PERM,
9819 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9820 NL80211_FLAG_NEED_RTNL,
9821 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009822#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009823 {
9824 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9825 .doit = nl80211_set_rekey_data,
9826 .policy = nl80211_policy,
9827 .flags = GENL_ADMIN_PERM,
9828 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9829 NL80211_FLAG_NEED_RTNL,
9830 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009831 {
9832 .cmd = NL80211_CMD_TDLS_MGMT,
9833 .doit = nl80211_tdls_mgmt,
9834 .policy = nl80211_policy,
9835 .flags = GENL_ADMIN_PERM,
9836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9837 NL80211_FLAG_NEED_RTNL,
9838 },
9839 {
9840 .cmd = NL80211_CMD_TDLS_OPER,
9841 .doit = nl80211_tdls_oper,
9842 .policy = nl80211_policy,
9843 .flags = GENL_ADMIN_PERM,
9844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9845 NL80211_FLAG_NEED_RTNL,
9846 },
Johannes Berg28946da2011-11-04 11:18:12 +01009847 {
9848 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9849 .doit = nl80211_register_unexpected_frame,
9850 .policy = nl80211_policy,
9851 .flags = GENL_ADMIN_PERM,
9852 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9853 NL80211_FLAG_NEED_RTNL,
9854 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009855 {
9856 .cmd = NL80211_CMD_PROBE_CLIENT,
9857 .doit = nl80211_probe_client,
9858 .policy = nl80211_policy,
9859 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009860 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009861 NL80211_FLAG_NEED_RTNL,
9862 },
Johannes Berg5e760232011-11-04 11:18:17 +01009863 {
9864 .cmd = NL80211_CMD_REGISTER_BEACONS,
9865 .doit = nl80211_register_beacons,
9866 .policy = nl80211_policy,
9867 .flags = GENL_ADMIN_PERM,
9868 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9869 NL80211_FLAG_NEED_RTNL,
9870 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009871 {
9872 .cmd = NL80211_CMD_SET_NOACK_MAP,
9873 .doit = nl80211_set_noack_map,
9874 .policy = nl80211_policy,
9875 .flags = GENL_ADMIN_PERM,
9876 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9877 NL80211_FLAG_NEED_RTNL,
9878 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009879 {
9880 .cmd = NL80211_CMD_START_P2P_DEVICE,
9881 .doit = nl80211_start_p2p_device,
9882 .policy = nl80211_policy,
9883 .flags = GENL_ADMIN_PERM,
9884 .internal_flags = NL80211_FLAG_NEED_WDEV |
9885 NL80211_FLAG_NEED_RTNL,
9886 },
9887 {
9888 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9889 .doit = nl80211_stop_p2p_device,
9890 .policy = nl80211_policy,
9891 .flags = GENL_ADMIN_PERM,
9892 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9893 NL80211_FLAG_NEED_RTNL,
9894 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009895 {
9896 .cmd = NL80211_CMD_SET_MCAST_RATE,
9897 .doit = nl80211_set_mcast_rate,
9898 .policy = nl80211_policy,
9899 .flags = GENL_ADMIN_PERM,
9900 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9901 NL80211_FLAG_NEED_RTNL,
9902 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309903 {
9904 .cmd = NL80211_CMD_SET_MAC_ACL,
9905 .doit = nl80211_set_mac_acl,
9906 .policy = nl80211_policy,
9907 .flags = GENL_ADMIN_PERM,
9908 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9909 NL80211_FLAG_NEED_RTNL,
9910 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009911 {
9912 .cmd = NL80211_CMD_RADAR_DETECT,
9913 .doit = nl80211_start_radar_detection,
9914 .policy = nl80211_policy,
9915 .flags = GENL_ADMIN_PERM,
9916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9917 NL80211_FLAG_NEED_RTNL,
9918 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009919 {
9920 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9921 .doit = nl80211_get_protocol_features,
9922 .policy = nl80211_policy,
9923 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009924 {
9925 .cmd = NL80211_CMD_UPDATE_FT_IES,
9926 .doit = nl80211_update_ft_ies,
9927 .policy = nl80211_policy,
9928 .flags = GENL_ADMIN_PERM,
9929 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9930 NL80211_FLAG_NEED_RTNL,
9931 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009932 {
9933 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9934 .doit = nl80211_crit_protocol_start,
9935 .policy = nl80211_policy,
9936 .flags = GENL_ADMIN_PERM,
9937 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9938 NL80211_FLAG_NEED_RTNL,
9939 },
9940 {
9941 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9942 .doit = nl80211_crit_protocol_stop,
9943 .policy = nl80211_policy,
9944 .flags = GENL_ADMIN_PERM,
9945 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9946 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009947 },
9948 {
9949 .cmd = NL80211_CMD_GET_COALESCE,
9950 .doit = nl80211_get_coalesce,
9951 .policy = nl80211_policy,
9952 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9953 NL80211_FLAG_NEED_RTNL,
9954 },
9955 {
9956 .cmd = NL80211_CMD_SET_COALESCE,
9957 .doit = nl80211_set_coalesce,
9958 .policy = nl80211_policy,
9959 .flags = GENL_ADMIN_PERM,
9960 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9961 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009962 },
9963 {
9964 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9965 .doit = nl80211_channel_switch,
9966 .policy = nl80211_policy,
9967 .flags = GENL_ADMIN_PERM,
9968 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9969 NL80211_FLAG_NEED_RTNL,
9970 },
Johannes Bergad7e7182013-11-13 13:37:47 +01009971 {
9972 .cmd = NL80211_CMD_VENDOR,
9973 .doit = nl80211_vendor_cmd,
9974 .policy = nl80211_policy,
9975 .flags = GENL_ADMIN_PERM,
9976 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9977 NL80211_FLAG_NEED_RTNL,
9978 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009979 {
9980 .cmd = NL80211_CMD_SET_QOS_MAP,
9981 .doit = nl80211_set_qos_map,
9982 .policy = nl80211_policy,
9983 .flags = GENL_ADMIN_PERM,
9984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9985 NL80211_FLAG_NEED_RTNL,
9986 },
Johannes Berg55682962007-09-20 13:09:35 -04009987};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009988
Johannes Berg55682962007-09-20 13:09:35 -04009989/* notification functions */
9990
9991void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9992{
9993 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009994 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009995
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009996 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009997 if (!msg)
9998 return;
9999
Johannes Berg86e8cf92013-06-19 10:57:22 +020010000 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010001 nlmsg_free(msg);
10002 return;
10003 }
10004
Johannes Berg68eb5502013-11-19 15:19:38 +010010005 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010006 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010007}
10008
Johannes Berg362a4152009-05-24 16:43:15 +020010009static int nl80211_add_scan_req(struct sk_buff *msg,
10010 struct cfg80211_registered_device *rdev)
10011{
10012 struct cfg80211_scan_request *req = rdev->scan_req;
10013 struct nlattr *nest;
10014 int i;
10015
10016 if (WARN_ON(!req))
10017 return 0;
10018
10019 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10020 if (!nest)
10021 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010022 for (i = 0; i < req->n_ssids; i++) {
10023 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10024 goto nla_put_failure;
10025 }
Johannes Berg362a4152009-05-24 16:43:15 +020010026 nla_nest_end(msg, nest);
10027
10028 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10029 if (!nest)
10030 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010031 for (i = 0; i < req->n_channels; i++) {
10032 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10033 goto nla_put_failure;
10034 }
Johannes Berg362a4152009-05-24 16:43:15 +020010035 nla_nest_end(msg, nest);
10036
David S. Miller9360ffd2012-03-29 04:41:26 -040010037 if (req->ie &&
10038 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10039 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010040
Johannes Bergae917c92013-10-25 11:05:22 +020010041 if (req->flags &&
10042 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10043 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010044
Johannes Berg362a4152009-05-24 16:43:15 +020010045 return 0;
10046 nla_put_failure:
10047 return -ENOBUFS;
10048}
10049
Johannes Berga538e2d2009-06-16 19:56:42 +020010050static int nl80211_send_scan_msg(struct sk_buff *msg,
10051 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010052 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010053 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010054 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010055{
10056 void *hdr;
10057
Eric W. Biederman15e47302012-09-07 20:12:54 +000010058 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010059 if (!hdr)
10060 return -1;
10061
David S. Miller9360ffd2012-03-29 04:41:26 -040010062 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010063 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10064 wdev->netdev->ifindex)) ||
10065 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010066 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010067
Johannes Berg362a4152009-05-24 16:43:15 +020010068 /* ignore errors and send incomplete event anyway */
10069 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010070
10071 return genlmsg_end(msg, hdr);
10072
10073 nla_put_failure:
10074 genlmsg_cancel(msg, hdr);
10075 return -EMSGSIZE;
10076}
10077
Luciano Coelho807f8a82011-05-11 17:09:35 +030010078static int
10079nl80211_send_sched_scan_msg(struct sk_buff *msg,
10080 struct cfg80211_registered_device *rdev,
10081 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010082 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010083{
10084 void *hdr;
10085
Eric W. Biederman15e47302012-09-07 20:12:54 +000010086 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010087 if (!hdr)
10088 return -1;
10089
David S. Miller9360ffd2012-03-29 04:41:26 -040010090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10091 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10092 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010093
10094 return genlmsg_end(msg, hdr);
10095
10096 nla_put_failure:
10097 genlmsg_cancel(msg, hdr);
10098 return -EMSGSIZE;
10099}
10100
Johannes Berga538e2d2009-06-16 19:56:42 +020010101void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010102 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010103{
10104 struct sk_buff *msg;
10105
Thomas Graf58050fc2012-06-28 03:57:45 +000010106 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010107 if (!msg)
10108 return;
10109
Johannes Bergfd014282012-06-18 19:17:03 +020010110 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010111 NL80211_CMD_TRIGGER_SCAN) < 0) {
10112 nlmsg_free(msg);
10113 return;
10114 }
10115
Johannes Berg68eb5502013-11-19 15:19:38 +010010116 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010117 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010118}
10119
Johannes Bergf9d15d12014-01-22 11:14:19 +020010120struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10121 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010122{
10123 struct sk_buff *msg;
10124
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010125 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010126 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010127 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010128
Johannes Bergfd014282012-06-18 19:17:03 +020010129 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010130 aborted ? NL80211_CMD_SCAN_ABORTED :
10131 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010132 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010133 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010134 }
10135
Johannes Bergf9d15d12014-01-22 11:14:19 +020010136 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010137}
10138
Johannes Bergf9d15d12014-01-22 11:14:19 +020010139void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10140 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010141{
Johannes Berg2a519312009-02-10 21:25:55 +010010142 if (!msg)
10143 return;
10144
Johannes Berg68eb5502013-11-19 15:19:38 +010010145 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010146 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010147}
10148
Luciano Coelho807f8a82011-05-11 17:09:35 +030010149void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10150 struct net_device *netdev)
10151{
10152 struct sk_buff *msg;
10153
10154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10155 if (!msg)
10156 return;
10157
10158 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10159 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10160 nlmsg_free(msg);
10161 return;
10162 }
10163
Johannes Berg68eb5502013-11-19 15:19:38 +010010164 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010165 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010166}
10167
10168void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10169 struct net_device *netdev, u32 cmd)
10170{
10171 struct sk_buff *msg;
10172
Thomas Graf58050fc2012-06-28 03:57:45 +000010173 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010174 if (!msg)
10175 return;
10176
10177 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10178 nlmsg_free(msg);
10179 return;
10180 }
10181
Johannes Berg68eb5502013-11-19 15:19:38 +010010182 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010183 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010184}
10185
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010186/*
10187 * This can happen on global regulatory changes or device specific settings
10188 * based on custom world regulatory domains.
10189 */
10190void nl80211_send_reg_change_event(struct regulatory_request *request)
10191{
10192 struct sk_buff *msg;
10193 void *hdr;
10194
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010195 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010196 if (!msg)
10197 return;
10198
10199 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10200 if (!hdr) {
10201 nlmsg_free(msg);
10202 return;
10203 }
10204
10205 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010206 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10207 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010208
David S. Miller9360ffd2012-03-29 04:41:26 -040010209 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10210 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10211 NL80211_REGDOM_TYPE_WORLD))
10212 goto nla_put_failure;
10213 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10214 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10215 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10216 goto nla_put_failure;
10217 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10218 request->intersect) {
10219 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10220 NL80211_REGDOM_TYPE_INTERSECTION))
10221 goto nla_put_failure;
10222 } else {
10223 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10224 NL80211_REGDOM_TYPE_COUNTRY) ||
10225 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10226 request->alpha2))
10227 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010228 }
10229
Johannes Bergf4173762012-12-03 18:23:37 +010010230 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010231 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10232 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010233
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010234 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010235
Johannes Bergbc43b282009-07-25 10:54:13 +020010236 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010237 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010238 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010239 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010240
10241 return;
10242
10243nla_put_failure:
10244 genlmsg_cancel(msg, hdr);
10245 nlmsg_free(msg);
10246}
10247
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010248static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10249 struct net_device *netdev,
10250 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010251 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010252{
10253 struct sk_buff *msg;
10254 void *hdr;
10255
Johannes Berge6d6e342009-07-01 21:26:47 +020010256 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010257 if (!msg)
10258 return;
10259
10260 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10261 if (!hdr) {
10262 nlmsg_free(msg);
10263 return;
10264 }
10265
David S. Miller9360ffd2012-03-29 04:41:26 -040010266 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10267 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10268 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10269 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010270
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010271 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010272
Johannes Berg68eb5502013-11-19 15:19:38 +010010273 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010274 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010275 return;
10276
10277 nla_put_failure:
10278 genlmsg_cancel(msg, hdr);
10279 nlmsg_free(msg);
10280}
10281
10282void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010283 struct net_device *netdev, const u8 *buf,
10284 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010285{
10286 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010287 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010288}
10289
10290void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10291 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010292 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010293{
Johannes Berge6d6e342009-07-01 21:26:47 +020010294 nl80211_send_mlme_event(rdev, netdev, buf, len,
10295 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010296}
10297
Jouni Malinen53b46b82009-03-27 20:53:56 +020010298void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010299 struct net_device *netdev, const u8 *buf,
10300 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010301{
10302 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010303 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010304}
10305
Jouni Malinen53b46b82009-03-27 20:53:56 +020010306void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10307 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010308 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010309{
10310 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010311 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010312}
10313
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010314void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10315 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010316{
Johannes Berg947add32013-02-22 22:05:20 +010010317 struct wireless_dev *wdev = dev->ieee80211_ptr;
10318 struct wiphy *wiphy = wdev->wiphy;
10319 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010320 const struct ieee80211_mgmt *mgmt = (void *)buf;
10321 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010322
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010323 if (WARN_ON(len < 2))
10324 return;
10325
10326 if (ieee80211_is_deauth(mgmt->frame_control))
10327 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10328 else
10329 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10330
10331 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10332 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010333}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010334EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010335
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010336static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10337 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010338 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010339{
10340 struct sk_buff *msg;
10341 void *hdr;
10342
Johannes Berge6d6e342009-07-01 21:26:47 +020010343 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010344 if (!msg)
10345 return;
10346
10347 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10348 if (!hdr) {
10349 nlmsg_free(msg);
10350 return;
10351 }
10352
David S. Miller9360ffd2012-03-29 04:41:26 -040010353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10354 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10355 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10356 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10357 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010358
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010359 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010360
Johannes Berg68eb5502013-11-19 15:19:38 +010010361 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010362 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010363 return;
10364
10365 nla_put_failure:
10366 genlmsg_cancel(msg, hdr);
10367 nlmsg_free(msg);
10368}
10369
10370void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010371 struct net_device *netdev, const u8 *addr,
10372 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010373{
10374 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010375 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010376}
10377
10378void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010379 struct net_device *netdev, const u8 *addr,
10380 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010381{
Johannes Berge6d6e342009-07-01 21:26:47 +020010382 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10383 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010384}
10385
Samuel Ortizb23aa672009-07-01 21:26:54 +020010386void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10387 struct net_device *netdev, const u8 *bssid,
10388 const u8 *req_ie, size_t req_ie_len,
10389 const u8 *resp_ie, size_t resp_ie_len,
10390 u16 status, gfp_t gfp)
10391{
10392 struct sk_buff *msg;
10393 void *hdr;
10394
Thomas Graf58050fc2012-06-28 03:57:45 +000010395 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010396 if (!msg)
10397 return;
10398
10399 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10400 if (!hdr) {
10401 nlmsg_free(msg);
10402 return;
10403 }
10404
David S. Miller9360ffd2012-03-29 04:41:26 -040010405 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10406 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10407 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10408 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10409 (req_ie &&
10410 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10411 (resp_ie &&
10412 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10413 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010414
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010415 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010416
Johannes Berg68eb5502013-11-19 15:19:38 +010010417 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010418 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010419 return;
10420
10421 nla_put_failure:
10422 genlmsg_cancel(msg, hdr);
10423 nlmsg_free(msg);
10424
10425}
10426
10427void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10428 struct net_device *netdev, const u8 *bssid,
10429 const u8 *req_ie, size_t req_ie_len,
10430 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10431{
10432 struct sk_buff *msg;
10433 void *hdr;
10434
Thomas Graf58050fc2012-06-28 03:57:45 +000010435 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010436 if (!msg)
10437 return;
10438
10439 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10440 if (!hdr) {
10441 nlmsg_free(msg);
10442 return;
10443 }
10444
David S. Miller9360ffd2012-03-29 04:41:26 -040010445 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10446 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10447 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10448 (req_ie &&
10449 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10450 (resp_ie &&
10451 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10452 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010453
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010454 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010455
Johannes Berg68eb5502013-11-19 15:19:38 +010010456 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010457 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010458 return;
10459
10460 nla_put_failure:
10461 genlmsg_cancel(msg, hdr);
10462 nlmsg_free(msg);
10463
10464}
10465
10466void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10467 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010468 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010469{
10470 struct sk_buff *msg;
10471 void *hdr;
10472
Thomas Graf58050fc2012-06-28 03:57:45 +000010473 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010474 if (!msg)
10475 return;
10476
10477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10478 if (!hdr) {
10479 nlmsg_free(msg);
10480 return;
10481 }
10482
David S. Miller9360ffd2012-03-29 04:41:26 -040010483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10485 (from_ap && reason &&
10486 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10487 (from_ap &&
10488 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10489 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10490 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010491
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010492 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010493
Johannes Berg68eb5502013-11-19 15:19:38 +010010494 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010495 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010496 return;
10497
10498 nla_put_failure:
10499 genlmsg_cancel(msg, hdr);
10500 nlmsg_free(msg);
10501
10502}
10503
Johannes Berg04a773a2009-04-19 21:24:32 +020010504void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10505 struct net_device *netdev, const u8 *bssid,
10506 gfp_t gfp)
10507{
10508 struct sk_buff *msg;
10509 void *hdr;
10510
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010511 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010512 if (!msg)
10513 return;
10514
10515 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10516 if (!hdr) {
10517 nlmsg_free(msg);
10518 return;
10519 }
10520
David S. Miller9360ffd2012-03-29 04:41:26 -040010521 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10522 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10523 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10524 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010525
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010526 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010527
Johannes Berg68eb5502013-11-19 15:19:38 +010010528 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010529 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010530 return;
10531
10532 nla_put_failure:
10533 genlmsg_cancel(msg, hdr);
10534 nlmsg_free(msg);
10535}
10536
Johannes Berg947add32013-02-22 22:05:20 +010010537void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10538 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010539{
Johannes Berg947add32013-02-22 22:05:20 +010010540 struct wireless_dev *wdev = dev->ieee80211_ptr;
10541 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010542 struct sk_buff *msg;
10543 void *hdr;
10544
Johannes Berg947add32013-02-22 22:05:20 +010010545 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10546 return;
10547
10548 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10549
Javier Cardonac93b5e72011-04-07 15:08:34 -070010550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10551 if (!msg)
10552 return;
10553
10554 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10555 if (!hdr) {
10556 nlmsg_free(msg);
10557 return;
10558 }
10559
David S. Miller9360ffd2012-03-29 04:41:26 -040010560 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010561 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10562 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010563 (ie_len && ie &&
10564 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10565 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010566
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010567 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010568
Johannes Berg68eb5502013-11-19 15:19:38 +010010569 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010570 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010571 return;
10572
10573 nla_put_failure:
10574 genlmsg_cancel(msg, hdr);
10575 nlmsg_free(msg);
10576}
Johannes Berg947add32013-02-22 22:05:20 +010010577EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010578
Jouni Malinena3b8b052009-03-27 21:59:49 +020010579void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10580 struct net_device *netdev, const u8 *addr,
10581 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010582 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010583{
10584 struct sk_buff *msg;
10585 void *hdr;
10586
Johannes Berge6d6e342009-07-01 21:26:47 +020010587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010588 if (!msg)
10589 return;
10590
10591 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10592 if (!hdr) {
10593 nlmsg_free(msg);
10594 return;
10595 }
10596
David S. Miller9360ffd2012-03-29 04:41:26 -040010597 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10598 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10599 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10600 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10601 (key_id != -1 &&
10602 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10603 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10604 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010605
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010606 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010607
Johannes Berg68eb5502013-11-19 15:19:38 +010010608 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010609 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010610 return;
10611
10612 nla_put_failure:
10613 genlmsg_cancel(msg, hdr);
10614 nlmsg_free(msg);
10615}
10616
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010617void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10618 struct ieee80211_channel *channel_before,
10619 struct ieee80211_channel *channel_after)
10620{
10621 struct sk_buff *msg;
10622 void *hdr;
10623 struct nlattr *nl_freq;
10624
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010625 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010626 if (!msg)
10627 return;
10628
10629 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10630 if (!hdr) {
10631 nlmsg_free(msg);
10632 return;
10633 }
10634
10635 /*
10636 * Since we are applying the beacon hint to a wiphy we know its
10637 * wiphy_idx is valid
10638 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010639 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10640 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010641
10642 /* Before */
10643 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10644 if (!nl_freq)
10645 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010646 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010647 goto nla_put_failure;
10648 nla_nest_end(msg, nl_freq);
10649
10650 /* After */
10651 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10652 if (!nl_freq)
10653 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010654 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010655 goto nla_put_failure;
10656 nla_nest_end(msg, nl_freq);
10657
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010658 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010659
Johannes Berg463d0182009-07-14 00:33:35 +020010660 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010661 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010662 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010663 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010664
10665 return;
10666
10667nla_put_failure:
10668 genlmsg_cancel(msg, hdr);
10669 nlmsg_free(msg);
10670}
10671
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010672static void nl80211_send_remain_on_chan_event(
10673 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010674 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010675 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010676 unsigned int duration, gfp_t gfp)
10677{
10678 struct sk_buff *msg;
10679 void *hdr;
10680
10681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10682 if (!msg)
10683 return;
10684
10685 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10686 if (!hdr) {
10687 nlmsg_free(msg);
10688 return;
10689 }
10690
David S. Miller9360ffd2012-03-29 04:41:26 -040010691 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010692 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10693 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010694 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010695 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010696 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10697 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010698 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10699 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010700
David S. Miller9360ffd2012-03-29 04:41:26 -040010701 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10702 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10703 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010704
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010705 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010706
Johannes Berg68eb5502013-11-19 15:19:38 +010010707 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010708 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010709 return;
10710
10711 nla_put_failure:
10712 genlmsg_cancel(msg, hdr);
10713 nlmsg_free(msg);
10714}
10715
Johannes Berg947add32013-02-22 22:05:20 +010010716void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10717 struct ieee80211_channel *chan,
10718 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010719{
Johannes Berg947add32013-02-22 22:05:20 +010010720 struct wiphy *wiphy = wdev->wiphy;
10721 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10722
10723 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010724 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010725 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010726 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010727}
Johannes Berg947add32013-02-22 22:05:20 +010010728EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010729
Johannes Berg947add32013-02-22 22:05:20 +010010730void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10731 struct ieee80211_channel *chan,
10732 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010733{
Johannes Berg947add32013-02-22 22:05:20 +010010734 struct wiphy *wiphy = wdev->wiphy;
10735 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10736
10737 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010738 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010739 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010740}
Johannes Berg947add32013-02-22 22:05:20 +010010741EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010742
Johannes Berg947add32013-02-22 22:05:20 +010010743void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10744 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010745{
Johannes Berg947add32013-02-22 22:05:20 +010010746 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10747 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010748 struct sk_buff *msg;
10749
Johannes Berg947add32013-02-22 22:05:20 +010010750 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10751
Thomas Graf58050fc2012-06-28 03:57:45 +000010752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010753 if (!msg)
10754 return;
10755
John W. Linville66266b32012-03-15 13:25:41 -040010756 if (nl80211_send_station(msg, 0, 0, 0,
10757 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010758 nlmsg_free(msg);
10759 return;
10760 }
10761
Johannes Berg68eb5502013-11-19 15:19:38 +010010762 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010763 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010764}
Johannes Berg947add32013-02-22 22:05:20 +010010765EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010766
Johannes Berg947add32013-02-22 22:05:20 +010010767void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010768{
Johannes Berg947add32013-02-22 22:05:20 +010010769 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10770 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010771 struct sk_buff *msg;
10772 void *hdr;
10773
Johannes Berg947add32013-02-22 22:05:20 +010010774 trace_cfg80211_del_sta(dev, mac_addr);
10775
Thomas Graf58050fc2012-06-28 03:57:45 +000010776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010777 if (!msg)
10778 return;
10779
10780 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10781 if (!hdr) {
10782 nlmsg_free(msg);
10783 return;
10784 }
10785
David S. Miller9360ffd2012-03-29 04:41:26 -040010786 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10787 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10788 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010789
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010790 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010791
Johannes Berg68eb5502013-11-19 15:19:38 +010010792 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010793 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010794 return;
10795
10796 nla_put_failure:
10797 genlmsg_cancel(msg, hdr);
10798 nlmsg_free(msg);
10799}
Johannes Berg947add32013-02-22 22:05:20 +010010800EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010801
Johannes Berg947add32013-02-22 22:05:20 +010010802void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10803 enum nl80211_connect_failed_reason reason,
10804 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010805{
Johannes Berg947add32013-02-22 22:05:20 +010010806 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10807 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010808 struct sk_buff *msg;
10809 void *hdr;
10810
10811 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10812 if (!msg)
10813 return;
10814
10815 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10816 if (!hdr) {
10817 nlmsg_free(msg);
10818 return;
10819 }
10820
10821 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10822 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10823 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10824 goto nla_put_failure;
10825
10826 genlmsg_end(msg, hdr);
10827
Johannes Berg68eb5502013-11-19 15:19:38 +010010828 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010829 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010830 return;
10831
10832 nla_put_failure:
10833 genlmsg_cancel(msg, hdr);
10834 nlmsg_free(msg);
10835}
Johannes Berg947add32013-02-22 22:05:20 +010010836EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010837
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010838static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10839 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010840{
10841 struct wireless_dev *wdev = dev->ieee80211_ptr;
10842 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10843 struct sk_buff *msg;
10844 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010845 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010846
Eric W. Biederman15e47302012-09-07 20:12:54 +000010847 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010848 return false;
10849
10850 msg = nlmsg_new(100, gfp);
10851 if (!msg)
10852 return true;
10853
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010854 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010855 if (!hdr) {
10856 nlmsg_free(msg);
10857 return true;
10858 }
10859
David S. Miller9360ffd2012-03-29 04:41:26 -040010860 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10861 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10862 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10863 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010864
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010865 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010866 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010867 return true;
10868
10869 nla_put_failure:
10870 genlmsg_cancel(msg, hdr);
10871 nlmsg_free(msg);
10872 return true;
10873}
10874
Johannes Berg947add32013-02-22 22:05:20 +010010875bool cfg80211_rx_spurious_frame(struct net_device *dev,
10876 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010877{
Johannes Berg947add32013-02-22 22:05:20 +010010878 struct wireless_dev *wdev = dev->ieee80211_ptr;
10879 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010880
Johannes Berg947add32013-02-22 22:05:20 +010010881 trace_cfg80211_rx_spurious_frame(dev, addr);
10882
10883 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10884 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10885 trace_cfg80211_return_bool(false);
10886 return false;
10887 }
10888 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10889 addr, gfp);
10890 trace_cfg80211_return_bool(ret);
10891 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010892}
Johannes Berg947add32013-02-22 22:05:20 +010010893EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10894
10895bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10896 const u8 *addr, gfp_t gfp)
10897{
10898 struct wireless_dev *wdev = dev->ieee80211_ptr;
10899 bool ret;
10900
10901 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10902
10903 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10904 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10905 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10906 trace_cfg80211_return_bool(false);
10907 return false;
10908 }
10909 ret = __nl80211_unexpected_frame(dev,
10910 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10911 addr, gfp);
10912 trace_cfg80211_return_bool(ret);
10913 return ret;
10914}
10915EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010916
Johannes Berg2e161f72010-08-12 15:38:38 +020010917int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010918 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010919 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010920 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010921{
Johannes Berg71bbc992012-06-15 15:30:18 +020010922 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010923 struct sk_buff *msg;
10924 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010925
10926 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10927 if (!msg)
10928 return -ENOMEM;
10929
Johannes Berg2e161f72010-08-12 15:38:38 +020010930 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010931 if (!hdr) {
10932 nlmsg_free(msg);
10933 return -ENOMEM;
10934 }
10935
David S. Miller9360ffd2012-03-29 04:41:26 -040010936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010937 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10938 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010939 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010940 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10941 (sig_dbm &&
10942 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010943 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10944 (flags &&
10945 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010946 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010947
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010948 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010949
Eric W. Biederman15e47302012-09-07 20:12:54 +000010950 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010951
10952 nla_put_failure:
10953 genlmsg_cancel(msg, hdr);
10954 nlmsg_free(msg);
10955 return -ENOBUFS;
10956}
10957
Johannes Berg947add32013-02-22 22:05:20 +010010958void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10959 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010960{
Johannes Berg947add32013-02-22 22:05:20 +010010961 struct wiphy *wiphy = wdev->wiphy;
10962 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010963 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010964 struct sk_buff *msg;
10965 void *hdr;
10966
Johannes Berg947add32013-02-22 22:05:20 +010010967 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10968
Jouni Malinen026331c2010-02-15 12:53:10 +020010969 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10970 if (!msg)
10971 return;
10972
Johannes Berg2e161f72010-08-12 15:38:38 +020010973 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010974 if (!hdr) {
10975 nlmsg_free(msg);
10976 return;
10977 }
10978
David S. Miller9360ffd2012-03-29 04:41:26 -040010979 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010980 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10981 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010982 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010983 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10984 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10985 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10986 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010987
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010988 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010989
Johannes Berg68eb5502013-11-19 15:19:38 +010010990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010991 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010992 return;
10993
10994 nla_put_failure:
10995 genlmsg_cancel(msg, hdr);
10996 nlmsg_free(msg);
10997}
Johannes Berg947add32013-02-22 22:05:20 +010010998EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010999
Johannes Berg947add32013-02-22 22:05:20 +010011000void cfg80211_cqm_rssi_notify(struct net_device *dev,
11001 enum nl80211_cqm_rssi_threshold_event rssi_event,
11002 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011003{
Johannes Berg947add32013-02-22 22:05:20 +010011004 struct wireless_dev *wdev = dev->ieee80211_ptr;
11005 struct wiphy *wiphy = wdev->wiphy;
11006 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011007 struct sk_buff *msg;
11008 struct nlattr *pinfoattr;
11009 void *hdr;
11010
Johannes Berg947add32013-02-22 22:05:20 +010011011 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11012
Thomas Graf58050fc2012-06-28 03:57:45 +000011013 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011014 if (!msg)
11015 return;
11016
11017 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11018 if (!hdr) {
11019 nlmsg_free(msg);
11020 return;
11021 }
11022
David S. Miller9360ffd2012-03-29 04:41:26 -040011023 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011024 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011025 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011026
11027 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11028 if (!pinfoattr)
11029 goto nla_put_failure;
11030
David S. Miller9360ffd2012-03-29 04:41:26 -040011031 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11032 rssi_event))
11033 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011034
11035 nla_nest_end(msg, pinfoattr);
11036
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011037 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011038
Johannes Berg68eb5502013-11-19 15:19:38 +010011039 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011040 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011041 return;
11042
11043 nla_put_failure:
11044 genlmsg_cancel(msg, hdr);
11045 nlmsg_free(msg);
11046}
Johannes Berg947add32013-02-22 22:05:20 +010011047EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011048
Johannes Berg947add32013-02-22 22:05:20 +010011049static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11050 struct net_device *netdev, const u8 *bssid,
11051 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011052{
11053 struct sk_buff *msg;
11054 struct nlattr *rekey_attr;
11055 void *hdr;
11056
Thomas Graf58050fc2012-06-28 03:57:45 +000011057 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011058 if (!msg)
11059 return;
11060
11061 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11062 if (!hdr) {
11063 nlmsg_free(msg);
11064 return;
11065 }
11066
David S. Miller9360ffd2012-03-29 04:41:26 -040011067 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11068 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11069 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11070 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011071
11072 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11073 if (!rekey_attr)
11074 goto nla_put_failure;
11075
David S. Miller9360ffd2012-03-29 04:41:26 -040011076 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11077 NL80211_REPLAY_CTR_LEN, replay_ctr))
11078 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011079
11080 nla_nest_end(msg, rekey_attr);
11081
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011082 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011083
Johannes Berg68eb5502013-11-19 15:19:38 +010011084 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011085 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011086 return;
11087
11088 nla_put_failure:
11089 genlmsg_cancel(msg, hdr);
11090 nlmsg_free(msg);
11091}
11092
Johannes Berg947add32013-02-22 22:05:20 +010011093void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11094 const u8 *replay_ctr, gfp_t gfp)
11095{
11096 struct wireless_dev *wdev = dev->ieee80211_ptr;
11097 struct wiphy *wiphy = wdev->wiphy;
11098 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11099
11100 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11101 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11102}
11103EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11104
11105static void
11106nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11107 struct net_device *netdev, int index,
11108 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011109{
11110 struct sk_buff *msg;
11111 struct nlattr *attr;
11112 void *hdr;
11113
Thomas Graf58050fc2012-06-28 03:57:45 +000011114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011115 if (!msg)
11116 return;
11117
11118 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11119 if (!hdr) {
11120 nlmsg_free(msg);
11121 return;
11122 }
11123
David S. Miller9360ffd2012-03-29 04:41:26 -040011124 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11125 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11126 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011127
11128 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11129 if (!attr)
11130 goto nla_put_failure;
11131
David S. Miller9360ffd2012-03-29 04:41:26 -040011132 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11133 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11134 (preauth &&
11135 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11136 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011137
11138 nla_nest_end(msg, attr);
11139
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011140 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011141
Johannes Berg68eb5502013-11-19 15:19:38 +010011142 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011143 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011144 return;
11145
11146 nla_put_failure:
11147 genlmsg_cancel(msg, hdr);
11148 nlmsg_free(msg);
11149}
11150
Johannes Berg947add32013-02-22 22:05:20 +010011151void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11152 const u8 *bssid, bool preauth, gfp_t gfp)
11153{
11154 struct wireless_dev *wdev = dev->ieee80211_ptr;
11155 struct wiphy *wiphy = wdev->wiphy;
11156 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11157
11158 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11159 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11160}
11161EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11162
11163static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11164 struct net_device *netdev,
11165 struct cfg80211_chan_def *chandef,
11166 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011167{
11168 struct sk_buff *msg;
11169 void *hdr;
11170
Thomas Graf58050fc2012-06-28 03:57:45 +000011171 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011172 if (!msg)
11173 return;
11174
11175 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11176 if (!hdr) {
11177 nlmsg_free(msg);
11178 return;
11179 }
11180
Johannes Berg683b6d32012-11-08 21:25:48 +010011181 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11182 goto nla_put_failure;
11183
11184 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011185 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011186
11187 genlmsg_end(msg, hdr);
11188
Johannes Berg68eb5502013-11-19 15:19:38 +010011189 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011190 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011191 return;
11192
11193 nla_put_failure:
11194 genlmsg_cancel(msg, hdr);
11195 nlmsg_free(msg);
11196}
11197
Johannes Berg947add32013-02-22 22:05:20 +010011198void cfg80211_ch_switch_notify(struct net_device *dev,
11199 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011200{
Johannes Berg947add32013-02-22 22:05:20 +010011201 struct wireless_dev *wdev = dev->ieee80211_ptr;
11202 struct wiphy *wiphy = wdev->wiphy;
11203 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11204
Simon Wunderliche487eae2013-11-21 18:19:51 +010011205 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011206
Simon Wunderliche487eae2013-11-21 18:19:51 +010011207 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011208
11209 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011210 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011211 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11212 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011213 return;
Johannes Berg947add32013-02-22 22:05:20 +010011214
Michal Kazior9e0e2962014-01-29 14:22:27 +010011215 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011216 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011217 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011218}
11219EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11220
11221void cfg80211_cqm_txe_notify(struct net_device *dev,
11222 const u8 *peer, u32 num_packets,
11223 u32 rate, u32 intvl, gfp_t gfp)
11224{
11225 struct wireless_dev *wdev = dev->ieee80211_ptr;
11226 struct wiphy *wiphy = wdev->wiphy;
11227 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011228 struct sk_buff *msg;
11229 struct nlattr *pinfoattr;
11230 void *hdr;
11231
11232 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11233 if (!msg)
11234 return;
11235
11236 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11237 if (!hdr) {
11238 nlmsg_free(msg);
11239 return;
11240 }
11241
11242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011243 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011244 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11245 goto nla_put_failure;
11246
11247 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11248 if (!pinfoattr)
11249 goto nla_put_failure;
11250
11251 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11252 goto nla_put_failure;
11253
11254 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11255 goto nla_put_failure;
11256
11257 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11258 goto nla_put_failure;
11259
11260 nla_nest_end(msg, pinfoattr);
11261
11262 genlmsg_end(msg, hdr);
11263
Johannes Berg68eb5502013-11-19 15:19:38 +010011264 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011265 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011266 return;
11267
11268 nla_put_failure:
11269 genlmsg_cancel(msg, hdr);
11270 nlmsg_free(msg);
11271}
Johannes Berg947add32013-02-22 22:05:20 +010011272EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011273
11274void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011275nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011276 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011277 enum nl80211_radar_event event,
11278 struct net_device *netdev, gfp_t gfp)
11279{
11280 struct sk_buff *msg;
11281 void *hdr;
11282
11283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11284 if (!msg)
11285 return;
11286
11287 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11288 if (!hdr) {
11289 nlmsg_free(msg);
11290 return;
11291 }
11292
11293 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11294 goto nla_put_failure;
11295
11296 /* NOP and radar events don't need a netdev parameter */
11297 if (netdev) {
11298 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11299
11300 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11301 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11302 goto nla_put_failure;
11303 }
11304
11305 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11306 goto nla_put_failure;
11307
11308 if (nl80211_send_chandef(msg, chandef))
11309 goto nla_put_failure;
11310
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011311 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011312
Johannes Berg68eb5502013-11-19 15:19:38 +010011313 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011314 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011315 return;
11316
11317 nla_put_failure:
11318 genlmsg_cancel(msg, hdr);
11319 nlmsg_free(msg);
11320}
11321
Johannes Berg947add32013-02-22 22:05:20 +010011322void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11323 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011324{
Johannes Berg947add32013-02-22 22:05:20 +010011325 struct wireless_dev *wdev = dev->ieee80211_ptr;
11326 struct wiphy *wiphy = wdev->wiphy;
11327 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011328 struct sk_buff *msg;
11329 struct nlattr *pinfoattr;
11330 void *hdr;
11331
Johannes Berg947add32013-02-22 22:05:20 +010011332 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11333
Thomas Graf58050fc2012-06-28 03:57:45 +000011334 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011335 if (!msg)
11336 return;
11337
11338 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11339 if (!hdr) {
11340 nlmsg_free(msg);
11341 return;
11342 }
11343
David S. Miller9360ffd2012-03-29 04:41:26 -040011344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011345 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011346 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11347 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011348
11349 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11350 if (!pinfoattr)
11351 goto nla_put_failure;
11352
David S. Miller9360ffd2012-03-29 04:41:26 -040011353 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11354 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011355
11356 nla_nest_end(msg, pinfoattr);
11357
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011358 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011359
Johannes Berg68eb5502013-11-19 15:19:38 +010011360 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011361 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011362 return;
11363
11364 nla_put_failure:
11365 genlmsg_cancel(msg, hdr);
11366 nlmsg_free(msg);
11367}
Johannes Berg947add32013-02-22 22:05:20 +010011368EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011369
Johannes Berg7f6cf312011-11-04 11:18:15 +010011370void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11371 u64 cookie, bool acked, gfp_t gfp)
11372{
11373 struct wireless_dev *wdev = dev->ieee80211_ptr;
11374 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11375 struct sk_buff *msg;
11376 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011377
Beni Lev4ee3e062012-08-27 12:49:39 +030011378 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11379
Thomas Graf58050fc2012-06-28 03:57:45 +000011380 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011381
Johannes Berg7f6cf312011-11-04 11:18:15 +010011382 if (!msg)
11383 return;
11384
11385 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11386 if (!hdr) {
11387 nlmsg_free(msg);
11388 return;
11389 }
11390
David S. Miller9360ffd2012-03-29 04:41:26 -040011391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11392 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11393 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11394 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11395 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11396 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011397
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011398 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011399
Johannes Berg68eb5502013-11-19 15:19:38 +010011400 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011401 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011402 return;
11403
11404 nla_put_failure:
11405 genlmsg_cancel(msg, hdr);
11406 nlmsg_free(msg);
11407}
11408EXPORT_SYMBOL(cfg80211_probe_status);
11409
Johannes Berg5e760232011-11-04 11:18:17 +010011410void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11411 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011412 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011413{
11414 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11415 struct sk_buff *msg;
11416 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011417 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011418
Beni Lev4ee3e062012-08-27 12:49:39 +030011419 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11420
Ben Greear37c73b52012-10-26 14:49:25 -070011421 spin_lock_bh(&rdev->beacon_registrations_lock);
11422 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11423 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11424 if (!msg) {
11425 spin_unlock_bh(&rdev->beacon_registrations_lock);
11426 return;
11427 }
Johannes Berg5e760232011-11-04 11:18:17 +010011428
Ben Greear37c73b52012-10-26 14:49:25 -070011429 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11430 if (!hdr)
11431 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011432
Ben Greear37c73b52012-10-26 14:49:25 -070011433 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11434 (freq &&
11435 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11436 (sig_dbm &&
11437 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11438 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11439 goto nla_put_failure;
11440
11441 genlmsg_end(msg, hdr);
11442
11443 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011444 }
Ben Greear37c73b52012-10-26 14:49:25 -070011445 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011446 return;
11447
11448 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011449 spin_unlock_bh(&rdev->beacon_registrations_lock);
11450 if (hdr)
11451 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011452 nlmsg_free(msg);
11453}
11454EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11455
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011456#ifdef CONFIG_PM
11457void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11458 struct cfg80211_wowlan_wakeup *wakeup,
11459 gfp_t gfp)
11460{
11461 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11462 struct sk_buff *msg;
11463 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011464 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011465
11466 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11467
11468 if (wakeup)
11469 size += wakeup->packet_present_len;
11470
11471 msg = nlmsg_new(size, gfp);
11472 if (!msg)
11473 return;
11474
11475 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11476 if (!hdr)
11477 goto free_msg;
11478
11479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11480 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11481 goto free_msg;
11482
11483 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11484 wdev->netdev->ifindex))
11485 goto free_msg;
11486
11487 if (wakeup) {
11488 struct nlattr *reasons;
11489
11490 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011491 if (!reasons)
11492 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011493
11494 if (wakeup->disconnect &&
11495 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11496 goto free_msg;
11497 if (wakeup->magic_pkt &&
11498 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11499 goto free_msg;
11500 if (wakeup->gtk_rekey_failure &&
11501 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11502 goto free_msg;
11503 if (wakeup->eap_identity_req &&
11504 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11505 goto free_msg;
11506 if (wakeup->four_way_handshake &&
11507 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11508 goto free_msg;
11509 if (wakeup->rfkill_release &&
11510 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11511 goto free_msg;
11512
11513 if (wakeup->pattern_idx >= 0 &&
11514 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11515 wakeup->pattern_idx))
11516 goto free_msg;
11517
Johannes Bergae917c92013-10-25 11:05:22 +020011518 if (wakeup->tcp_match &&
11519 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11520 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011521
Johannes Bergae917c92013-10-25 11:05:22 +020011522 if (wakeup->tcp_connlost &&
11523 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11524 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011525
Johannes Bergae917c92013-10-25 11:05:22 +020011526 if (wakeup->tcp_nomoretokens &&
11527 nla_put_flag(msg,
11528 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11529 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011530
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011531 if (wakeup->packet) {
11532 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11533 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11534
11535 if (!wakeup->packet_80211) {
11536 pkt_attr =
11537 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11538 len_attr =
11539 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11540 }
11541
11542 if (wakeup->packet_len &&
11543 nla_put_u32(msg, len_attr, wakeup->packet_len))
11544 goto free_msg;
11545
11546 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11547 wakeup->packet))
11548 goto free_msg;
11549 }
11550
11551 nla_nest_end(msg, reasons);
11552 }
11553
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011554 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011555
Johannes Berg68eb5502013-11-19 15:19:38 +010011556 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011557 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011558 return;
11559
11560 free_msg:
11561 nlmsg_free(msg);
11562}
11563EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11564#endif
11565
Jouni Malinen3475b092012-11-16 22:49:57 +020011566void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11567 enum nl80211_tdls_operation oper,
11568 u16 reason_code, gfp_t gfp)
11569{
11570 struct wireless_dev *wdev = dev->ieee80211_ptr;
11571 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11572 struct sk_buff *msg;
11573 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011574
11575 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11576 reason_code);
11577
11578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11579 if (!msg)
11580 return;
11581
11582 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11583 if (!hdr) {
11584 nlmsg_free(msg);
11585 return;
11586 }
11587
11588 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11589 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11590 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11591 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11592 (reason_code > 0 &&
11593 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11594 goto nla_put_failure;
11595
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011596 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011597
Johannes Berg68eb5502013-11-19 15:19:38 +010011598 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011599 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011600 return;
11601
11602 nla_put_failure:
11603 genlmsg_cancel(msg, hdr);
11604 nlmsg_free(msg);
11605}
11606EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11607
Jouni Malinen026331c2010-02-15 12:53:10 +020011608static int nl80211_netlink_notify(struct notifier_block * nb,
11609 unsigned long state,
11610 void *_notify)
11611{
11612 struct netlink_notify *notify = _notify;
11613 struct cfg80211_registered_device *rdev;
11614 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011615 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011616
11617 if (state != NETLINK_URELEASE)
11618 return NOTIFY_DONE;
11619
11620 rcu_read_lock();
11621
Johannes Berg5e760232011-11-04 11:18:17 +010011622 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011623 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011624 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011625
11626 spin_lock_bh(&rdev->beacon_registrations_lock);
11627 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11628 list) {
11629 if (reg->nlportid == notify->portid) {
11630 list_del(&reg->list);
11631 kfree(reg);
11632 break;
11633 }
11634 }
11635 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011636 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011637
11638 rcu_read_unlock();
11639
11640 return NOTIFY_DONE;
11641}
11642
11643static struct notifier_block nl80211_netlink_notifier = {
11644 .notifier_call = nl80211_netlink_notify,
11645};
11646
Jouni Malinen355199e2013-02-27 17:14:27 +020011647void cfg80211_ft_event(struct net_device *netdev,
11648 struct cfg80211_ft_event_params *ft_event)
11649{
11650 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11651 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11652 struct sk_buff *msg;
11653 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011654
11655 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11656
11657 if (!ft_event->target_ap)
11658 return;
11659
11660 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11661 if (!msg)
11662 return;
11663
11664 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011665 if (!hdr)
11666 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011667
Johannes Bergae917c92013-10-25 11:05:22 +020011668 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11669 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11670 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11671 goto out;
11672
11673 if (ft_event->ies &&
11674 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11675 goto out;
11676 if (ft_event->ric_ies &&
11677 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11678 ft_event->ric_ies))
11679 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011680
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011681 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011682
Johannes Berg68eb5502013-11-19 15:19:38 +010011683 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011684 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011685 return;
11686 out:
11687 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011688}
11689EXPORT_SYMBOL(cfg80211_ft_event);
11690
Arend van Spriel5de17982013-04-18 15:49:00 +020011691void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11692{
11693 struct cfg80211_registered_device *rdev;
11694 struct sk_buff *msg;
11695 void *hdr;
11696 u32 nlportid;
11697
11698 rdev = wiphy_to_dev(wdev->wiphy);
11699 if (!rdev->crit_proto_nlportid)
11700 return;
11701
11702 nlportid = rdev->crit_proto_nlportid;
11703 rdev->crit_proto_nlportid = 0;
11704
11705 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11706 if (!msg)
11707 return;
11708
11709 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11710 if (!hdr)
11711 goto nla_put_failure;
11712
11713 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11714 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11715 goto nla_put_failure;
11716
11717 genlmsg_end(msg, hdr);
11718
11719 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11720 return;
11721
11722 nla_put_failure:
11723 if (hdr)
11724 genlmsg_cancel(msg, hdr);
11725 nlmsg_free(msg);
11726
11727}
11728EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11729
Johannes Berg348baf02014-01-24 14:06:29 +010011730void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11731{
11732 struct wiphy *wiphy = wdev->wiphy;
11733 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11734 struct sk_buff *msg;
11735 void *hdr;
11736
11737 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11738 if (!msg)
11739 return;
11740
11741 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11742 if (!hdr)
11743 goto out;
11744
11745 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11746 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11747 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11748 goto out;
11749
11750 genlmsg_end(msg, hdr);
11751
11752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11753 NL80211_MCGRP_MLME, GFP_KERNEL);
11754 return;
11755 out:
11756 nlmsg_free(msg);
11757}
11758
Johannes Berg55682962007-09-20 13:09:35 -040011759/* initialisation/exit functions */
11760
11761int nl80211_init(void)
11762{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011763 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011764
Johannes Berg2a94fe42013-11-19 15:19:39 +010011765 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11766 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011767 if (err)
11768 return err;
11769
Jouni Malinen026331c2010-02-15 12:53:10 +020011770 err = netlink_register_notifier(&nl80211_netlink_notifier);
11771 if (err)
11772 goto err_out;
11773
Johannes Berg55682962007-09-20 13:09:35 -040011774 return 0;
11775 err_out:
11776 genl_unregister_family(&nl80211_fam);
11777 return err;
11778}
11779
11780void nl80211_exit(void)
11781{
Jouni Malinen026331c2010-02-15 12:53:10 +020011782 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011783 genl_unregister_family(&nl80211_fam);
11784}