blob: 138dc3bb8b67d8c345531a95ce0c8342271ce79e [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Bergf84f7712013-11-14 17:14:45 +010033static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020034 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010035static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg2a94fe42013-11-19 15:19:39 +010050/* multicast groups */
51enum nl80211_multicast_groups {
52 NL80211_MCGRP_CONFIG,
53 NL80211_MCGRP_SCAN,
54 NL80211_MCGRP_REGULATORY,
55 NL80211_MCGRP_MLME,
56 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
57};
58
59static const struct genl_multicast_group nl80211_mcgrps[] = {
60 [NL80211_MCGRP_CONFIG] = { .name = "config", },
61 [NL80211_MCGRP_SCAN] = { .name = "scan", },
62 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
63 [NL80211_MCGRP_MLME] = { .name = "mlme", },
64#ifdef CONFIG_NL80211_TESTMODE
65 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
66#endif
67};
68
Johannes Berg89a54e42012-06-15 14:33:17 +020069/* returns ERR_PTR values */
70static struct wireless_dev *
71__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040072{
Johannes Berg89a54e42012-06-15 14:33:17 +020073 struct cfg80211_registered_device *rdev;
74 struct wireless_dev *result = NULL;
75 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
76 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
77 u64 wdev_id;
78 int wiphy_idx = -1;
79 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040080
Johannes Berg5fe231e2013-05-08 21:45:15 +020081 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg89a54e42012-06-15 14:33:17 +020083 if (!have_ifidx && !have_wdev_id)
84 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (have_ifidx)
87 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
88 if (have_wdev_id) {
89 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
90 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040091 }
92
Johannes Berg89a54e42012-06-15 14:33:17 +020093 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
94 struct wireless_dev *wdev;
95
96 if (wiphy_net(&rdev->wiphy) != netns)
97 continue;
98
99 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
100 continue;
101
Johannes Berg89a54e42012-06-15 14:33:17 +0200102 list_for_each_entry(wdev, &rdev->wdev_list, list) {
103 if (have_ifidx && wdev->netdev &&
104 wdev->netdev->ifindex == ifidx) {
105 result = wdev;
106 break;
107 }
108 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
109 result = wdev;
110 break;
111 }
112 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200113
114 if (result)
115 break;
116 }
117
118 if (result)
119 return result;
120 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400121}
122
Johannes Berga9455402012-06-15 13:32:49 +0200123static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200124__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200125{
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 struct cfg80211_registered_device *rdev = NULL, *tmp;
127 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200128
Johannes Berg5fe231e2013-05-08 21:45:15 +0200129 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg878d9ec2012-06-15 14:18:32 +0200131 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 !attrs[NL80211_ATTR_IFINDEX] &&
133 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200134 return ERR_PTR(-EINVAL);
135
Johannes Berg878d9ec2012-06-15 14:18:32 +0200136 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200139
Johannes Berg89a54e42012-06-15 14:33:17 +0200140 if (attrs[NL80211_ATTR_WDEV]) {
141 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
142 struct wireless_dev *wdev;
143 bool found = false;
144
145 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
146 if (tmp) {
147 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200148 list_for_each_entry(wdev, &tmp->wdev_list, list) {
149 if (wdev->identifier != (u32)wdev_id)
150 continue;
151 found = true;
152 break;
153 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200154
155 if (!found)
156 tmp = NULL;
157
158 if (rdev && tmp != rdev)
159 return ERR_PTR(-EINVAL);
160 rdev = tmp;
161 }
162 }
163
Johannes Berg878d9ec2012-06-15 14:18:32 +0200164 if (attrs[NL80211_ATTR_IFINDEX]) {
165 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200166 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 if (netdev) {
168 if (netdev->ieee80211_ptr)
169 tmp = wiphy_to_dev(
170 netdev->ieee80211_ptr->wiphy);
171 else
172 tmp = NULL;
173
174 dev_put(netdev);
175
176 /* not wireless device -- return error */
177 if (!tmp)
178 return ERR_PTR(-EINVAL);
179
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
183
184 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200185 }
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
187
Johannes Berg4f7eff12012-06-15 14:14:22 +0200188 if (!rdev)
189 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
193
194 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200195}
196
197/*
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200200 *
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
203 */
204static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200205cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200206{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208}
209
Johannes Berg55682962007-09-20 13:09:35 -0400210/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700214 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100216
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400228
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100232
Eliad Pellere007b852011-11-24 18:13:56 +0200233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Johannes Bergb9454e82009-07-08 13:29:08 +0200236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100244
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800260 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
265
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-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 },
Johannes Berg55682962007-09-20 13:09:35 -0400379};
380
Johannes Berge31b8212010-10-05 19:39:30 +0200381/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000382static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200383 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200384 [NL80211_KEY_IDX] = { .type = NLA_U8 },
385 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200386 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200387 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
388 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200389 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100390 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
391};
392
393/* policy for the key default flags */
394static const struct nla_policy
395nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
396 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
397 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200398};
399
Johannes Bergff1b6e62011-05-04 15:37:28 +0200400/* policy for WoWLAN attributes */
401static const struct nla_policy
402nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
403 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
404 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
405 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
406 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200407 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
409 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100411 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
412};
413
414static const struct nla_policy
415nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
416 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
417 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
418 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
419 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
420 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
421 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
422 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
423 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
424 },
425 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
426 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
427 },
428 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
429 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
430 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200431};
432
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700433/* policy for coalesce rule attributes */
434static const struct nla_policy
435nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
436 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
437 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
438 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
439};
440
Johannes Berge5497d72011-07-05 16:35:40 +0200441/* policy for GTK rekey offload attributes */
442static const struct nla_policy
443nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
444 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
445 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
446 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
447};
448
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300449static const struct nla_policy
450nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200451 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300452 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700453 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300454};
455
Johannes Berg97990a02013-04-19 01:02:55 +0200456static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
457 struct netlink_callback *cb,
458 struct cfg80211_registered_device **rdev,
459 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100460{
Johannes Berg67748892010-10-04 21:14:06 +0200461 int err;
462
Johannes Berg67748892010-10-04 21:14:06 +0200463 rtnl_lock();
464
Johannes Berg97990a02013-04-19 01:02:55 +0200465 if (!cb->args[0]) {
466 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
467 nl80211_fam.attrbuf, nl80211_fam.maxattr,
468 nl80211_policy);
469 if (err)
470 goto out_unlock;
471
472 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
473 nl80211_fam.attrbuf);
474 if (IS_ERR(*wdev)) {
475 err = PTR_ERR(*wdev);
476 goto out_unlock;
477 }
478 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200479 /* 0 is the first index - add 1 to parse only once */
480 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200481 cb->args[1] = (*wdev)->identifier;
482 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200483 /* subtract the 1 again here */
484 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200485 struct wireless_dev *tmp;
486
487 if (!wiphy) {
488 err = -ENODEV;
489 goto out_unlock;
490 }
491 *rdev = wiphy_to_dev(wiphy);
492 *wdev = NULL;
493
Johannes Berg97990a02013-04-19 01:02:55 +0200494 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
495 if (tmp->identifier == cb->args[1]) {
496 *wdev = tmp;
497 break;
498 }
499 }
Johannes Berg97990a02013-04-19 01:02:55 +0200500
501 if (!*wdev) {
502 err = -ENODEV;
503 goto out_unlock;
504 }
Johannes Berg67748892010-10-04 21:14:06 +0200505 }
506
Johannes Berg67748892010-10-04 21:14:06 +0200507 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200508 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200509 rtnl_unlock();
510 return err;
511}
512
Johannes Berg97990a02013-04-19 01:02:55 +0200513static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200514{
Johannes Berg67748892010-10-04 21:14:06 +0200515 rtnl_unlock();
516}
517
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100518/* IE validation */
519static bool is_valid_ie_attr(const struct nlattr *attr)
520{
521 const u8 *pos;
522 int len;
523
524 if (!attr)
525 return true;
526
527 pos = nla_data(attr);
528 len = nla_len(attr);
529
530 while (len) {
531 u8 elemlen;
532
533 if (len < 2)
534 return false;
535 len -= 2;
536
537 elemlen = pos[1];
538 if (elemlen > len)
539 return false;
540
541 len -= elemlen;
542 pos += 2 + elemlen;
543 }
544
545 return true;
546}
547
Johannes Berg55682962007-09-20 13:09:35 -0400548/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000549static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400550 int flags, u8 cmd)
551{
552 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000553 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400554}
555
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400556static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100557 struct ieee80211_channel *chan,
558 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400559{
David S. Miller9360ffd2012-03-29 04:41:26 -0400560 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
561 chan->center_freq))
562 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400563
David S. Miller9360ffd2012-03-29 04:41:26 -0400564 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
565 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
566 goto nla_put_failure;
567 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
568 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
569 goto nla_put_failure;
570 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
571 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
572 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100573 if (chan->flags & IEEE80211_CHAN_RADAR) {
574 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
575 goto nla_put_failure;
576 if (large) {
577 u32 time;
578
579 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
580
581 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
582 chan->dfs_state))
583 goto nla_put_failure;
584 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
585 time))
586 goto nla_put_failure;
587 }
588 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400589
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100590 if (large) {
591 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
592 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
593 goto nla_put_failure;
594 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
595 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
596 goto nla_put_failure;
597 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
598 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
599 goto nla_put_failure;
600 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
601 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
602 goto nla_put_failure;
603 }
604
David S. Miller9360ffd2012-03-29 04:41:26 -0400605 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
606 DBM_TO_MBM(chan->max_power)))
607 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400608
609 return 0;
610
611 nla_put_failure:
612 return -ENOBUFS;
613}
614
Johannes Berg55682962007-09-20 13:09:35 -0400615/* netlink command implementations */
616
Johannes Bergb9454e82009-07-08 13:29:08 +0200617struct key_parse {
618 struct key_params p;
619 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200620 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200621 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100622 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200623};
624
625static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
626{
627 struct nlattr *tb[NL80211_KEY_MAX + 1];
628 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
629 nl80211_key_policy);
630 if (err)
631 return err;
632
633 k->def = !!tb[NL80211_KEY_DEFAULT];
634 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
635
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100636 if (k->def) {
637 k->def_uni = true;
638 k->def_multi = true;
639 }
640 if (k->defmgmt)
641 k->def_multi = true;
642
Johannes Bergb9454e82009-07-08 13:29:08 +0200643 if (tb[NL80211_KEY_IDX])
644 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
645
646 if (tb[NL80211_KEY_DATA]) {
647 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
648 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
649 }
650
651 if (tb[NL80211_KEY_SEQ]) {
652 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
653 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
654 }
655
656 if (tb[NL80211_KEY_CIPHER])
657 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
658
Johannes Berge31b8212010-10-05 19:39:30 +0200659 if (tb[NL80211_KEY_TYPE]) {
660 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
661 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
662 return -EINVAL;
663 }
664
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100665 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
666 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100667 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
668 tb[NL80211_KEY_DEFAULT_TYPES],
669 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 if (err)
671 return err;
672
673 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
674 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
675 }
676
Johannes Bergb9454e82009-07-08 13:29:08 +0200677 return 0;
678}
679
680static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
681{
682 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
683 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
684 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
685 }
686
687 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
688 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
689 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
690 }
691
692 if (info->attrs[NL80211_ATTR_KEY_IDX])
693 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
694
695 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
696 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
697
698 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
699 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
700
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100701 if (k->def) {
702 k->def_uni = true;
703 k->def_multi = true;
704 }
705 if (k->defmgmt)
706 k->def_multi = true;
707
Johannes Berge31b8212010-10-05 19:39:30 +0200708 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
709 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
710 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
711 return -EINVAL;
712 }
713
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100714 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
715 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
716 int err = nla_parse_nested(
717 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
718 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
719 nl80211_key_default_policy);
720 if (err)
721 return err;
722
723 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
724 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
725 }
726
Johannes Bergb9454e82009-07-08 13:29:08 +0200727 return 0;
728}
729
730static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
731{
732 int err;
733
734 memset(k, 0, sizeof(*k));
735 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200736 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200737
738 if (info->attrs[NL80211_ATTR_KEY])
739 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
740 else
741 err = nl80211_parse_key_old(info, k);
742
743 if (err)
744 return err;
745
746 if (k->def && k->defmgmt)
747 return -EINVAL;
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (k->defmgmt) {
750 if (k->def_uni || !k->def_multi)
751 return -EINVAL;
752 }
753
Johannes Bergb9454e82009-07-08 13:29:08 +0200754 if (k->idx != -1) {
755 if (k->defmgmt) {
756 if (k->idx < 4 || k->idx > 5)
757 return -EINVAL;
758 } else if (k->def) {
759 if (k->idx < 0 || k->idx > 3)
760 return -EINVAL;
761 } else {
762 if (k->idx < 0 || k->idx > 5)
763 return -EINVAL;
764 }
765 }
766
767 return 0;
768}
769
Johannes Bergfffd0932009-07-08 14:22:54 +0200770static struct cfg80211_cached_keys *
771nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530772 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200773{
774 struct key_parse parse;
775 struct nlattr *key;
776 struct cfg80211_cached_keys *result;
777 int rem, err, def = 0;
778
779 result = kzalloc(sizeof(*result), GFP_KERNEL);
780 if (!result)
781 return ERR_PTR(-ENOMEM);
782
783 result->def = -1;
784 result->defmgmt = -1;
785
786 nla_for_each_nested(key, keys, rem) {
787 memset(&parse, 0, sizeof(parse));
788 parse.idx = -1;
789
790 err = nl80211_parse_key_new(key, &parse);
791 if (err)
792 goto error;
793 err = -EINVAL;
794 if (!parse.p.key)
795 goto error;
796 if (parse.idx < 0 || parse.idx > 4)
797 goto error;
798 if (parse.def) {
799 if (def)
800 goto error;
801 def = 1;
802 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100803 if (!parse.def_uni || !parse.def_multi)
804 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200805 } else if (parse.defmgmt)
806 goto error;
807 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200808 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 if (err)
810 goto error;
811 result->params[parse.idx].cipher = parse.p.cipher;
812 result->params[parse.idx].key_len = parse.p.key_len;
813 result->params[parse.idx].key = result->data[parse.idx];
814 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530815
816 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
817 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
818 if (no_ht)
819 *no_ht = true;
820 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200821 }
822
823 return result;
824 error:
825 kfree(result);
826 return ERR_PTR(err);
827}
828
829static int nl80211_key_allowed(struct wireless_dev *wdev)
830{
831 ASSERT_WDEV_LOCK(wdev);
832
Johannes Bergfffd0932009-07-08 14:22:54 +0200833 switch (wdev->iftype) {
834 case NL80211_IFTYPE_AP:
835 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200836 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700837 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200838 break;
839 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200840 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200841 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200842 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200843 return -ENOLINK;
844 break;
845 default:
846 return -EINVAL;
847 }
848
849 return 0;
850}
851
Johannes Berg7527a782011-05-13 10:58:57 +0200852static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
853{
854 struct nlattr *nl_modes = nla_nest_start(msg, attr);
855 int i;
856
857 if (!nl_modes)
858 goto nla_put_failure;
859
860 i = 0;
861 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400862 if ((ifmodes & 1) && nla_put_flag(msg, i))
863 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200864 ifmodes >>= 1;
865 i++;
866 }
867
868 nla_nest_end(msg, nl_modes);
869 return 0;
870
871nla_put_failure:
872 return -ENOBUFS;
873}
874
875static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100876 struct sk_buff *msg,
877 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200878{
879 struct nlattr *nl_combis;
880 int i, j;
881
882 nl_combis = nla_nest_start(msg,
883 NL80211_ATTR_INTERFACE_COMBINATIONS);
884 if (!nl_combis)
885 goto nla_put_failure;
886
887 for (i = 0; i < wiphy->n_iface_combinations; i++) {
888 const struct ieee80211_iface_combination *c;
889 struct nlattr *nl_combi, *nl_limits;
890
891 c = &wiphy->iface_combinations[i];
892
893 nl_combi = nla_nest_start(msg, i + 1);
894 if (!nl_combi)
895 goto nla_put_failure;
896
897 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
898 if (!nl_limits)
899 goto nla_put_failure;
900
901 for (j = 0; j < c->n_limits; j++) {
902 struct nlattr *nl_limit;
903
904 nl_limit = nla_nest_start(msg, j + 1);
905 if (!nl_limit)
906 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400907 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
908 c->limits[j].max))
909 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200910 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
911 c->limits[j].types))
912 goto nla_put_failure;
913 nla_nest_end(msg, nl_limit);
914 }
915
916 nla_nest_end(msg, nl_limits);
917
David S. Miller9360ffd2012-03-29 04:41:26 -0400918 if (c->beacon_int_infra_match &&
919 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
920 goto nla_put_failure;
921 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
922 c->num_different_channels) ||
923 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
924 c->max_interfaces))
925 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100926 if (large &&
927 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
928 c->radar_detect_widths))
929 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200930
931 nla_nest_end(msg, nl_combi);
932 }
933
934 nla_nest_end(msg, nl_combis);
935
936 return 0;
937nla_put_failure:
938 return -ENOBUFS;
939}
940
Johannes Berg3713b4e2013-02-14 16:19:38 +0100941#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100942static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
943 struct sk_buff *msg)
944{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200945 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100946 struct nlattr *nl_tcp;
947
948 if (!tcp)
949 return 0;
950
951 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
952 if (!nl_tcp)
953 return -ENOBUFS;
954
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
956 tcp->data_payload_max))
957 return -ENOBUFS;
958
959 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
960 tcp->data_payload_max))
961 return -ENOBUFS;
962
963 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
964 return -ENOBUFS;
965
966 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
967 sizeof(*tcp->tok), tcp->tok))
968 return -ENOBUFS;
969
970 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
971 tcp->data_interval_max))
972 return -ENOBUFS;
973
974 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
975 tcp->wake_payload_max))
976 return -ENOBUFS;
977
978 nla_nest_end(msg, nl_tcp);
979 return 0;
980}
981
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100983 struct cfg80211_registered_device *dev,
984 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100985{
986 struct nlattr *nl_wowlan;
987
Johannes Berg964dc9e2013-06-03 17:25:34 +0200988 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100989 return 0;
990
991 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
992 if (!nl_wowlan)
993 return -ENOBUFS;
994
Johannes Berg964dc9e2013-06-03 17:25:34 +0200995 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100996 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200997 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100998 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200999 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001001 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001003 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001005 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001007 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001008 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1011 return -ENOBUFS;
1012
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001014 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +02001015 .max_patterns = dev->wiphy.wowlan->n_patterns,
1016 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1017 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1018 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001019 };
1020
1021 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1022 sizeof(pat), &pat))
1023 return -ENOBUFS;
1024 }
1025
Johannes Bergb56cf722013-02-20 01:02:38 +01001026 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1027 return -ENOBUFS;
1028
Johannes Berg3713b4e2013-02-14 16:19:38 +01001029 nla_nest_end(msg, nl_wowlan);
1030
1031 return 0;
1032}
1033#endif
1034
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001035static int nl80211_send_coalesce(struct sk_buff *msg,
1036 struct cfg80211_registered_device *dev)
1037{
1038 struct nl80211_coalesce_rule_support rule;
1039
1040 if (!dev->wiphy.coalesce)
1041 return 0;
1042
1043 rule.max_rules = dev->wiphy.coalesce->n_rules;
1044 rule.max_delay = dev->wiphy.coalesce->max_delay;
1045 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1046 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1047 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1048 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1049
1050 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1051 return -ENOBUFS;
1052
1053 return 0;
1054}
1055
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1057 struct ieee80211_supported_band *sband)
1058{
1059 struct nlattr *nl_rates, *nl_rate;
1060 struct ieee80211_rate *rate;
1061 int i;
1062
1063 /* add HT info */
1064 if (sband->ht_cap.ht_supported &&
1065 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1066 sizeof(sband->ht_cap.mcs),
1067 &sband->ht_cap.mcs) ||
1068 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1069 sband->ht_cap.cap) ||
1070 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1071 sband->ht_cap.ampdu_factor) ||
1072 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1073 sband->ht_cap.ampdu_density)))
1074 return -ENOBUFS;
1075
1076 /* add VHT info */
1077 if (sband->vht_cap.vht_supported &&
1078 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1079 sizeof(sband->vht_cap.vht_mcs),
1080 &sband->vht_cap.vht_mcs) ||
1081 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1082 sband->vht_cap.cap)))
1083 return -ENOBUFS;
1084
1085 /* add bitrates */
1086 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1087 if (!nl_rates)
1088 return -ENOBUFS;
1089
1090 for (i = 0; i < sband->n_bitrates; i++) {
1091 nl_rate = nla_nest_start(msg, i);
1092 if (!nl_rate)
1093 return -ENOBUFS;
1094
1095 rate = &sband->bitrates[i];
1096 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1097 rate->bitrate))
1098 return -ENOBUFS;
1099 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1100 nla_put_flag(msg,
1101 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1102 return -ENOBUFS;
1103
1104 nla_nest_end(msg, nl_rate);
1105 }
1106
1107 nla_nest_end(msg, nl_rates);
1108
1109 return 0;
1110}
1111
1112static int
1113nl80211_send_mgmt_stypes(struct sk_buff *msg,
1114 const struct ieee80211_txrx_stypes *mgmt_stypes)
1115{
1116 u16 stypes;
1117 struct nlattr *nl_ftypes, *nl_ifs;
1118 enum nl80211_iftype ift;
1119 int i;
1120
1121 if (!mgmt_stypes)
1122 return 0;
1123
1124 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1125 if (!nl_ifs)
1126 return -ENOBUFS;
1127
1128 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1129 nl_ftypes = nla_nest_start(msg, ift);
1130 if (!nl_ftypes)
1131 return -ENOBUFS;
1132 i = 0;
1133 stypes = mgmt_stypes[ift].tx;
1134 while (stypes) {
1135 if ((stypes & 1) &&
1136 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1137 (i << 4) | IEEE80211_FTYPE_MGMT))
1138 return -ENOBUFS;
1139 stypes >>= 1;
1140 i++;
1141 }
1142 nla_nest_end(msg, nl_ftypes);
1143 }
1144
1145 nla_nest_end(msg, nl_ifs);
1146
1147 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1148 if (!nl_ifs)
1149 return -ENOBUFS;
1150
1151 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1152 nl_ftypes = nla_nest_start(msg, ift);
1153 if (!nl_ftypes)
1154 return -ENOBUFS;
1155 i = 0;
1156 stypes = mgmt_stypes[ift].rx;
1157 while (stypes) {
1158 if ((stypes & 1) &&
1159 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1160 (i << 4) | IEEE80211_FTYPE_MGMT))
1161 return -ENOBUFS;
1162 stypes >>= 1;
1163 i++;
1164 }
1165 nla_nest_end(msg, nl_ftypes);
1166 }
1167 nla_nest_end(msg, nl_ifs);
1168
1169 return 0;
1170}
1171
Johannes Berg86e8cf92013-06-19 10:57:22 +02001172struct nl80211_dump_wiphy_state {
1173 s64 filter_wiphy;
1174 long start;
1175 long split_start, band_start, chan_start;
1176 bool split;
1177};
1178
Johannes Berg3713b4e2013-02-14 16:19:38 +01001179static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1180 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001181 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001182{
1183 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001184 struct nlattr *nl_bands, *nl_band;
1185 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001186 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001187 enum ieee80211_band band;
1188 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001189 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001190 const struct ieee80211_txrx_stypes *mgmt_stypes =
1191 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001192 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001193
Eric W. Biederman15e47302012-09-07 20:12:54 +00001194 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001195 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001196 return -ENOBUFS;
1197
Johannes Berg86e8cf92013-06-19 10:57:22 +02001198 if (WARN_ON(!state))
1199 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001200
David S. Miller9360ffd2012-03-29 04:41:26 -04001201 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001202 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1203 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001204 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001205 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001206 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001207
Johannes Berg86e8cf92013-06-19 10:57:22 +02001208 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001209 case 0:
1210 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1211 dev->wiphy.retry_short) ||
1212 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1213 dev->wiphy.retry_long) ||
1214 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1215 dev->wiphy.frag_threshold) ||
1216 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1217 dev->wiphy.rts_threshold) ||
1218 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1219 dev->wiphy.coverage_class) ||
1220 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1221 dev->wiphy.max_scan_ssids) ||
1222 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1223 dev->wiphy.max_sched_scan_ssids) ||
1224 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1225 dev->wiphy.max_scan_ie_len) ||
1226 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1227 dev->wiphy.max_sched_scan_ie_len) ||
1228 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1229 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001230 goto nla_put_failure;
1231
Johannes Berg3713b4e2013-02-14 16:19:38 +01001232 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1233 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1234 goto nla_put_failure;
1235 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1236 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1237 goto nla_put_failure;
1238 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1239 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1240 goto nla_put_failure;
1241 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1242 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1243 goto nla_put_failure;
1244 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1245 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1246 goto nla_put_failure;
1247 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1248 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001249 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001250 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1251 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1252 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001253
Johannes Berg86e8cf92013-06-19 10:57:22 +02001254 state->split_start++;
1255 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001256 break;
1257 case 1:
1258 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1259 sizeof(u32) * dev->wiphy.n_cipher_suites,
1260 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001261 goto nla_put_failure;
1262
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1264 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001265 goto nla_put_failure;
1266
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1268 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1269 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001270
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1272 dev->wiphy.available_antennas_tx) ||
1273 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1274 dev->wiphy.available_antennas_rx))
1275 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001276
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1278 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1279 dev->wiphy.probe_resp_offload))
1280 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001281
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 if ((dev->wiphy.available_antennas_tx ||
1283 dev->wiphy.available_antennas_rx) &&
1284 dev->ops->get_antenna) {
1285 u32 tx_ant = 0, rx_ant = 0;
1286 int res;
1287 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1288 if (!res) {
1289 if (nla_put_u32(msg,
1290 NL80211_ATTR_WIPHY_ANTENNA_TX,
1291 tx_ant) ||
1292 nla_put_u32(msg,
1293 NL80211_ATTR_WIPHY_ANTENNA_RX,
1294 rx_ant))
1295 goto nla_put_failure;
1296 }
Johannes Bergee688b002008-01-24 19:38:39 +01001297 }
1298
Johannes Berg86e8cf92013-06-19 10:57:22 +02001299 state->split_start++;
1300 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 break;
1302 case 2:
1303 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1304 dev->wiphy.interface_modes))
1305 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001306 state->split_start++;
1307 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 break;
1309 case 3:
1310 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1311 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001312 goto nla_put_failure;
1313
Johannes Berg86e8cf92013-06-19 10:57:22 +02001314 for (band = state->band_start;
1315 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 struct ieee80211_supported_band *sband;
1317
1318 sband = dev->wiphy.bands[band];
1319
1320 if (!sband)
1321 continue;
1322
1323 nl_band = nla_nest_start(msg, band);
1324 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001325 goto nla_put_failure;
1326
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 case 0:
1329 if (nl80211_send_band_rateinfo(msg, sband))
1330 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 state->chan_start++;
1332 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 break;
1334 default:
1335 /* add frequencies */
1336 nl_freqs = nla_nest_start(
1337 msg, NL80211_BAND_ATTR_FREQS);
1338 if (!nl_freqs)
1339 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001340
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 i < sband->n_channels;
1343 i++) {
1344 nl_freq = nla_nest_start(msg, i);
1345 if (!nl_freq)
1346 goto nla_put_failure;
1347
1348 chan = &sband->channels[i];
1349
Johannes Berg86e8cf92013-06-19 10:57:22 +02001350 if (nl80211_msg_put_channel(
1351 msg, chan,
1352 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 goto nla_put_failure;
1354
1355 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 break;
1358 }
1359 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001360 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001362 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 nla_nest_end(msg, nl_freqs);
1364 }
1365
1366 nla_nest_end(msg, nl_band);
1367
Johannes Berg86e8cf92013-06-19 10:57:22 +02001368 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001370 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 band--;
1372 break;
1373 }
Johannes Bergee688b002008-01-24 19:38:39 +01001374 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001376
Johannes Berg3713b4e2013-02-14 16:19:38 +01001377 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001378 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001380 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001381
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001383 if (state->band_start == 0 && state->chan_start == 0)
1384 state->split_start++;
1385 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 break;
1387 case 4:
1388 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1389 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001390 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391
1392 i = 0;
1393#define CMD(op, n) \
1394 do { \
1395 if (dev->ops->op) { \
1396 i++; \
1397 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1398 goto nla_put_failure; \
1399 } \
1400 } while (0)
1401
1402 CMD(add_virtual_intf, NEW_INTERFACE);
1403 CMD(change_virtual_intf, SET_INTERFACE);
1404 CMD(add_key, NEW_KEY);
1405 CMD(start_ap, START_AP);
1406 CMD(add_station, NEW_STATION);
1407 CMD(add_mpath, NEW_MPATH);
1408 CMD(update_mesh_config, SET_MESH_CONFIG);
1409 CMD(change_bss, SET_BSS);
1410 CMD(auth, AUTHENTICATE);
1411 CMD(assoc, ASSOCIATE);
1412 CMD(deauth, DEAUTHENTICATE);
1413 CMD(disassoc, DISASSOCIATE);
1414 CMD(join_ibss, JOIN_IBSS);
1415 CMD(join_mesh, JOIN_MESH);
1416 CMD(set_pmksa, SET_PMKSA);
1417 CMD(del_pmksa, DEL_PMKSA);
1418 CMD(flush_pmksa, FLUSH_PMKSA);
1419 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1420 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1421 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1422 CMD(mgmt_tx, FRAME);
1423 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1424 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1425 i++;
1426 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1427 goto nla_put_failure;
1428 }
1429 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1430 dev->ops->join_mesh) {
1431 i++;
1432 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1433 goto nla_put_failure;
1434 }
1435 CMD(set_wds_peer, SET_WDS_PEER);
1436 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1437 CMD(tdls_mgmt, TDLS_MGMT);
1438 CMD(tdls_oper, TDLS_OPER);
1439 }
1440 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1441 CMD(sched_scan_start, START_SCHED_SCAN);
1442 CMD(probe_client, PROBE_CLIENT);
1443 CMD(set_noack_map, SET_NOACK_MAP);
1444 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1445 i++;
1446 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1447 goto nla_put_failure;
1448 }
1449 CMD(start_p2p_device, START_P2P_DEVICE);
1450 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001451 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001452 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1453 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001454 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1455 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001456 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001457
Kalle Valo4745fc02011-11-17 19:06:10 +02001458#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001460#endif
1461
Johannes Berg8fdc6212009-03-14 09:34:01 +01001462#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001463
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 if (dev->ops->connect || dev->ops->auth) {
1465 i++;
1466 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001467 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001468 }
1469
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 if (dev->ops->disconnect || dev->ops->deauth) {
1471 i++;
1472 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1473 goto nla_put_failure;
1474 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001475
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001477 state->split_start++;
1478 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001479 break;
1480 case 5:
1481 if (dev->ops->remain_on_channel &&
1482 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1483 nla_put_u32(msg,
1484 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1485 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001486 goto nla_put_failure;
1487
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1489 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1490 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001491
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1493 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001494 state->split_start++;
1495 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 break;
1497 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001498#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001499 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001500 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001501 state->split_start++;
1502 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 break;
1504#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001505 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506#endif
1507 case 7:
1508 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1509 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001510 goto nla_put_failure;
1511
Johannes Berg86e8cf92013-06-19 10:57:22 +02001512 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1513 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001515
Johannes Berg86e8cf92013-06-19 10:57:22 +02001516 state->split_start++;
1517 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 break;
1519 case 8:
1520 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1521 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1522 dev->wiphy.ap_sme_capa))
1523 goto nla_put_failure;
1524
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001525 features = dev->wiphy.features;
1526 /*
1527 * We can only add the per-channel limit information if the
1528 * dump is split, otherwise it makes it too big. Therefore
1529 * only advertise it in that case.
1530 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001531 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001532 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1533 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 goto nla_put_failure;
1535
1536 if (dev->wiphy.ht_capa_mod_mask &&
1537 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1538 sizeof(*dev->wiphy.ht_capa_mod_mask),
1539 dev->wiphy.ht_capa_mod_mask))
1540 goto nla_put_failure;
1541
1542 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1543 dev->wiphy.max_acl_mac_addrs &&
1544 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1545 dev->wiphy.max_acl_mac_addrs))
1546 goto nla_put_failure;
1547
1548 /*
1549 * Any information below this point is only available to
1550 * applications that can deal with it being split. This
1551 * helps ensure that newly added capabilities don't break
1552 * older tools by overrunning their buffers.
1553 *
1554 * We still increment split_start so that in the split
1555 * case we'll continue with more data in the next round,
1556 * but break unconditionally so unsplit data stops here.
1557 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001558 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 break;
1560 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001561 if (dev->wiphy.extended_capabilities &&
1562 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1563 dev->wiphy.extended_capabilities_len,
1564 dev->wiphy.extended_capabilities) ||
1565 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1566 dev->wiphy.extended_capabilities_len,
1567 dev->wiphy.extended_capabilities_mask)))
1568 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569
Johannes Bergee2aca32013-02-21 17:36:01 +01001570 if (dev->wiphy.vht_capa_mod_mask &&
1571 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1572 sizeof(*dev->wiphy.vht_capa_mod_mask),
1573 dev->wiphy.vht_capa_mod_mask))
1574 goto nla_put_failure;
1575
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001576 state->split_start++;
1577 break;
1578 case 10:
1579 if (nl80211_send_coalesce(msg, dev))
1580 goto nla_put_failure;
1581
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001585 }
Johannes Berg55682962007-09-20 13:09:35 -04001586 return genlmsg_end(msg, hdr);
1587
1588 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001589 genlmsg_cancel(msg, hdr);
1590 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001591}
1592
Johannes Berg86e8cf92013-06-19 10:57:22 +02001593static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1594 struct netlink_callback *cb,
1595 struct nl80211_dump_wiphy_state *state)
1596{
1597 struct nlattr **tb = nl80211_fam.attrbuf;
1598 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1599 tb, nl80211_fam.maxattr, nl80211_policy);
1600 /* ignore parse errors for backward compatibility */
1601 if (ret)
1602 return 0;
1603
1604 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1605 if (tb[NL80211_ATTR_WIPHY])
1606 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1607 if (tb[NL80211_ATTR_WDEV])
1608 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1609 if (tb[NL80211_ATTR_IFINDEX]) {
1610 struct net_device *netdev;
1611 struct cfg80211_registered_device *rdev;
1612 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1613
1614 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1615 if (!netdev)
1616 return -ENODEV;
1617 if (netdev->ieee80211_ptr) {
1618 rdev = wiphy_to_dev(
1619 netdev->ieee80211_ptr->wiphy);
1620 state->filter_wiphy = rdev->wiphy_idx;
1621 }
1622 dev_put(netdev);
1623 }
1624
1625 return 0;
1626}
1627
Johannes Berg55682962007-09-20 13:09:35 -04001628static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1629{
Johannes Berg645e77d2013-03-01 14:03:49 +01001630 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001631 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001632 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001633
Johannes Berg5fe231e2013-05-08 21:45:15 +02001634 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001635 if (!state) {
1636 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001637 if (!state) {
1638 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001639 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001640 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001641 state->filter_wiphy = -1;
1642 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1643 if (ret) {
1644 kfree(state);
1645 rtnl_unlock();
1646 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001648 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001649 }
1650
Johannes Berg79c97e92009-07-07 03:56:12 +02001651 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001652 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1653 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001654 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001655 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001656 if (state->filter_wiphy != -1 &&
1657 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001658 continue;
1659 /* attempt to fit multiple wiphy data chunks into the skb */
1660 do {
1661 ret = nl80211_send_wiphy(dev, skb,
1662 NETLINK_CB(cb->skb).portid,
1663 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001664 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 if (ret < 0) {
1666 /*
1667 * If sending the wiphy data didn't fit (ENOBUFS
1668 * or EMSGSIZE returned), this SKB is still
1669 * empty (so it's not too big because another
1670 * wiphy dataset is already in the skb) and
1671 * we've not tried to adjust the dump allocation
1672 * yet ... then adjust the alloc size to be
1673 * bigger, and return 1 but with the empty skb.
1674 * This results in an empty message being RX'ed
1675 * in userspace, but that is ignored.
1676 *
1677 * We can then retry with the larger buffer.
1678 */
1679 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1680 !skb->len &&
1681 cb->min_dump_alloc < 4096) {
1682 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001683 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 return 1;
1685 }
1686 idx--;
1687 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001688 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001689 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001690 break;
Johannes Berg55682962007-09-20 13:09:35 -04001691 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001692 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001693
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001695
1696 return skb->len;
1697}
1698
Johannes Berg86e8cf92013-06-19 10:57:22 +02001699static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1700{
1701 kfree((void *)cb->args[0]);
1702 return 0;
1703}
1704
Johannes Berg55682962007-09-20 13:09:35 -04001705static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1706{
1707 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001708 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001709 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001710
Johannes Berg645e77d2013-03-01 14:03:49 +01001711 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001712 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001713 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001714
Johannes Berg3713b4e2013-02-14 16:19:38 +01001715 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001716 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001717 nlmsg_free(msg);
1718 return -ENOBUFS;
1719 }
Johannes Berg55682962007-09-20 13:09:35 -04001720
Johannes Berg134e6372009-07-10 09:51:34 +00001721 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001722}
1723
Jouni Malinen31888482008-10-30 16:59:24 +02001724static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1725 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1726 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1727 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1728 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1729 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1730};
1731
1732static int parse_txq_params(struct nlattr *tb[],
1733 struct ieee80211_txq_params *txq_params)
1734{
Johannes Berga3304b02012-03-28 11:04:24 +02001735 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001736 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1737 !tb[NL80211_TXQ_ATTR_AIFS])
1738 return -EINVAL;
1739
Johannes Berga3304b02012-03-28 11:04:24 +02001740 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001741 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1742 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1743 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1744 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1745
Johannes Berga3304b02012-03-28 11:04:24 +02001746 if (txq_params->ac >= NL80211_NUM_ACS)
1747 return -EINVAL;
1748
Jouni Malinen31888482008-10-30 16:59:24 +02001749 return 0;
1750}
1751
Johannes Bergf444de02010-05-05 15:25:02 +02001752static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1753{
1754 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001755 * You can only set the channel explicitly for WDS interfaces,
1756 * all others have their channel managed via their respective
1757 * "establish a connection" command (connect, join, ...)
1758 *
1759 * For AP/GO and mesh mode, the channel can be set with the
1760 * channel userspace API, but is only stored and passed to the
1761 * low-level driver when the AP starts or the mesh is joined.
1762 * This is for backward compatibility, userspace can also give
1763 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001764 *
1765 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001766 * whatever else is going on, so they have their own special
1767 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001768 */
1769 return !wdev ||
1770 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001771 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001772 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1773 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001774}
1775
Johannes Berg683b6d32012-11-08 21:25:48 +01001776static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1777 struct genl_info *info,
1778 struct cfg80211_chan_def *chandef)
1779{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301780 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001781
1782 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1783 return -EINVAL;
1784
1785 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1786
1787 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001788 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1789 chandef->center_freq1 = control_freq;
1790 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001791
1792 /* Primary channel not allowed */
1793 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1794 return -EINVAL;
1795
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001796 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1797 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001798
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001799 chantype = nla_get_u32(
1800 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1801
1802 switch (chantype) {
1803 case NL80211_CHAN_NO_HT:
1804 case NL80211_CHAN_HT20:
1805 case NL80211_CHAN_HT40PLUS:
1806 case NL80211_CHAN_HT40MINUS:
1807 cfg80211_chandef_create(chandef, chandef->chan,
1808 chantype);
1809 break;
1810 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001811 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001812 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001813 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1814 chandef->width =
1815 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1816 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1817 chandef->center_freq1 =
1818 nla_get_u32(
1819 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1820 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1821 chandef->center_freq2 =
1822 nla_get_u32(
1823 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1824 }
1825
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001826 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001827 return -EINVAL;
1828
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001829 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1830 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001831 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001832
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001833 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1834 chandef->width == NL80211_CHAN_WIDTH_10) &&
1835 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1836 return -EINVAL;
1837
Johannes Berg683b6d32012-11-08 21:25:48 +01001838 return 0;
1839}
1840
Johannes Bergf444de02010-05-05 15:25:02 +02001841static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1842 struct wireless_dev *wdev,
1843 struct genl_info *info)
1844{
Johannes Berg683b6d32012-11-08 21:25:48 +01001845 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001846 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001847 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1848
1849 if (wdev)
1850 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001851
Johannes Bergf444de02010-05-05 15:25:02 +02001852 if (!nl80211_can_set_dev_channel(wdev))
1853 return -EOPNOTSUPP;
1854
Johannes Berg683b6d32012-11-08 21:25:48 +01001855 result = nl80211_parse_chandef(rdev, info, &chandef);
1856 if (result)
1857 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001858
Johannes Berge8c9bd52012-06-06 08:18:22 +02001859 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001860 case NL80211_IFTYPE_AP:
1861 case NL80211_IFTYPE_P2P_GO:
1862 if (wdev->beacon_interval) {
1863 result = -EBUSY;
1864 break;
1865 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001866 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001867 result = -EINVAL;
1868 break;
1869 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001870 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001871 result = 0;
1872 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001873 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001874 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001875 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001876 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001877 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001878 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001879 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001880 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001881 }
Johannes Bergf444de02010-05-05 15:25:02 +02001882
1883 return result;
1884}
1885
1886static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1887{
Johannes Berg4c476992010-10-04 21:36:35 +02001888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1889 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001890
Johannes Berg4c476992010-10-04 21:36:35 +02001891 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001892}
1893
Bill Jordane8347eb2010-10-01 13:54:28 -04001894static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1895{
Johannes Berg43b19952010-10-07 13:10:30 +02001896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1897 struct net_device *dev = info->user_ptr[1];
1898 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001899 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001900
1901 if (!info->attrs[NL80211_ATTR_MAC])
1902 return -EINVAL;
1903
Johannes Berg43b19952010-10-07 13:10:30 +02001904 if (netif_running(dev))
1905 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001906
Johannes Berg43b19952010-10-07 13:10:30 +02001907 if (!rdev->ops->set_wds_peer)
1908 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001909
Johannes Berg43b19952010-10-07 13:10:30 +02001910 if (wdev->iftype != NL80211_IFTYPE_WDS)
1911 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001912
1913 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001914 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001915}
1916
1917
Johannes Berg55682962007-09-20 13:09:35 -04001918static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1919{
1920 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001921 struct net_device *netdev = NULL;
1922 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001923 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001924 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001925 u32 changed;
1926 u8 retry_short = 0, retry_long = 0;
1927 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001928 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001929
Johannes Berg5fe231e2013-05-08 21:45:15 +02001930 ASSERT_RTNL();
1931
Johannes Bergf444de02010-05-05 15:25:02 +02001932 /*
1933 * Try to find the wiphy and netdev. Normally this
1934 * function shouldn't need the netdev, but this is
1935 * done for backward compatibility -- previously
1936 * setting the channel was done per wiphy, but now
1937 * it is per netdev. Previous userland like hostapd
1938 * also passed a netdev to set_wiphy, so that it is
1939 * possible to let that go to the right netdev!
1940 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001941
Johannes Bergf444de02010-05-05 15:25:02 +02001942 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1943 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1944
1945 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001946 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001947 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001948 else
Johannes Bergf444de02010-05-05 15:25:02 +02001949 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001950 }
1951
Johannes Bergf444de02010-05-05 15:25:02 +02001952 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001953 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1954 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001955 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001956 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001957 wdev = NULL;
1958 netdev = NULL;
1959 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001960 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001961 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001962
1963 /*
1964 * end workaround code, by now the rdev is available
1965 * and locked, and wdev may or may not be NULL.
1966 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001967
1968 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001969 result = cfg80211_dev_rename(
1970 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001971
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001972 if (result)
1973 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001974
Jouni Malinen31888482008-10-30 16:59:24 +02001975 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1976 struct ieee80211_txq_params txq_params;
1977 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1978
1979 if (!rdev->ops->set_txq_params) {
1980 result = -EOPNOTSUPP;
1981 goto bad_res;
1982 }
1983
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001984 if (!netdev) {
1985 result = -EINVAL;
1986 goto bad_res;
1987 }
1988
Johannes Berg133a3ff2011-11-03 14:50:13 +01001989 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1990 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1991 result = -EINVAL;
1992 goto bad_res;
1993 }
1994
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001995 if (!netif_running(netdev)) {
1996 result = -ENETDOWN;
1997 goto bad_res;
1998 }
1999
Jouni Malinen31888482008-10-30 16:59:24 +02002000 nla_for_each_nested(nl_txq_params,
2001 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2002 rem_txq_params) {
2003 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2004 nla_data(nl_txq_params),
2005 nla_len(nl_txq_params),
2006 txq_params_policy);
2007 result = parse_txq_params(tb, &txq_params);
2008 if (result)
2009 goto bad_res;
2010
Hila Gonene35e4d22012-06-27 17:19:42 +03002011 result = rdev_set_txq_params(rdev, netdev,
2012 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002013 if (result)
2014 goto bad_res;
2015 }
2016 }
2017
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002018 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002019 result = __nl80211_set_channel(rdev,
2020 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2021 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002022 if (result)
2023 goto bad_res;
2024 }
2025
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002026 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002027 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002028 enum nl80211_tx_power_setting type;
2029 int idx, mbm = 0;
2030
Johannes Bergc8442112012-10-24 10:17:18 +02002031 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2032 txp_wdev = NULL;
2033
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002034 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002035 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002036 goto bad_res;
2037 }
2038
2039 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2040 type = nla_get_u32(info->attrs[idx]);
2041
2042 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2043 (type != NL80211_TX_POWER_AUTOMATIC)) {
2044 result = -EINVAL;
2045 goto bad_res;
2046 }
2047
2048 if (type != NL80211_TX_POWER_AUTOMATIC) {
2049 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2050 mbm = nla_get_u32(info->attrs[idx]);
2051 }
2052
Johannes Bergc8442112012-10-24 10:17:18 +02002053 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002054 if (result)
2055 goto bad_res;
2056 }
2057
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002058 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2059 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2060 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002061 if ((!rdev->wiphy.available_antennas_tx &&
2062 !rdev->wiphy.available_antennas_rx) ||
2063 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002064 result = -EOPNOTSUPP;
2065 goto bad_res;
2066 }
2067
2068 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2069 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2070
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002071 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002072 * available antenna masks, except for the "all" mask */
2073 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2074 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002075 result = -EINVAL;
2076 goto bad_res;
2077 }
2078
Bruno Randolf7f531e02010-12-16 11:30:22 +09002079 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2080 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002081
Hila Gonene35e4d22012-06-27 17:19:42 +03002082 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002083 if (result)
2084 goto bad_res;
2085 }
2086
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002087 changed = 0;
2088
2089 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2090 retry_short = nla_get_u8(
2091 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2092 if (retry_short == 0) {
2093 result = -EINVAL;
2094 goto bad_res;
2095 }
2096 changed |= WIPHY_PARAM_RETRY_SHORT;
2097 }
2098
2099 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2100 retry_long = nla_get_u8(
2101 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2102 if (retry_long == 0) {
2103 result = -EINVAL;
2104 goto bad_res;
2105 }
2106 changed |= WIPHY_PARAM_RETRY_LONG;
2107 }
2108
2109 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2110 frag_threshold = nla_get_u32(
2111 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2112 if (frag_threshold < 256) {
2113 result = -EINVAL;
2114 goto bad_res;
2115 }
2116 if (frag_threshold != (u32) -1) {
2117 /*
2118 * Fragments (apart from the last one) are required to
2119 * have even length. Make the fragmentation code
2120 * simpler by stripping LSB should someone try to use
2121 * odd threshold value.
2122 */
2123 frag_threshold &= ~0x1;
2124 }
2125 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2126 }
2127
2128 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2129 rts_threshold = nla_get_u32(
2130 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2131 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2132 }
2133
Lukáš Turek81077e82009-12-21 22:50:47 +01002134 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2135 coverage_class = nla_get_u8(
2136 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2137 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2138 }
2139
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002140 if (changed) {
2141 u8 old_retry_short, old_retry_long;
2142 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002143 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002144
2145 if (!rdev->ops->set_wiphy_params) {
2146 result = -EOPNOTSUPP;
2147 goto bad_res;
2148 }
2149
2150 old_retry_short = rdev->wiphy.retry_short;
2151 old_retry_long = rdev->wiphy.retry_long;
2152 old_frag_threshold = rdev->wiphy.frag_threshold;
2153 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002154 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002155
2156 if (changed & WIPHY_PARAM_RETRY_SHORT)
2157 rdev->wiphy.retry_short = retry_short;
2158 if (changed & WIPHY_PARAM_RETRY_LONG)
2159 rdev->wiphy.retry_long = retry_long;
2160 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2161 rdev->wiphy.frag_threshold = frag_threshold;
2162 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2163 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002164 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2165 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002166
Hila Gonene35e4d22012-06-27 17:19:42 +03002167 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002168 if (result) {
2169 rdev->wiphy.retry_short = old_retry_short;
2170 rdev->wiphy.retry_long = old_retry_long;
2171 rdev->wiphy.frag_threshold = old_frag_threshold;
2172 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002173 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002174 }
2175 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002176
Johannes Berg306d6112008-12-08 12:39:04 +01002177 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002178 if (netdev)
2179 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002180 return result;
2181}
2182
Johannes Berg71bbc992012-06-15 15:30:18 +02002183static inline u64 wdev_id(struct wireless_dev *wdev)
2184{
2185 return (u64)wdev->identifier |
2186 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2187}
Johannes Berg55682962007-09-20 13:09:35 -04002188
Johannes Berg683b6d32012-11-08 21:25:48 +01002189static int nl80211_send_chandef(struct sk_buff *msg,
2190 struct cfg80211_chan_def *chandef)
2191{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002192 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002193
Johannes Berg683b6d32012-11-08 21:25:48 +01002194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2195 chandef->chan->center_freq))
2196 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002197 switch (chandef->width) {
2198 case NL80211_CHAN_WIDTH_20_NOHT:
2199 case NL80211_CHAN_WIDTH_20:
2200 case NL80211_CHAN_WIDTH_40:
2201 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2202 cfg80211_get_chandef_type(chandef)))
2203 return -ENOBUFS;
2204 break;
2205 default:
2206 break;
2207 }
2208 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2209 return -ENOBUFS;
2210 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2211 return -ENOBUFS;
2212 if (chandef->center_freq2 &&
2213 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002214 return -ENOBUFS;
2215 return 0;
2216}
2217
Eric W. Biederman15e47302012-09-07 20:12:54 +00002218static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002219 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002220 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002221{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002222 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002223 void *hdr;
2224
Eric W. Biederman15e47302012-09-07 20:12:54 +00002225 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002226 if (!hdr)
2227 return -1;
2228
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002229 if (dev &&
2230 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002231 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002232 goto nla_put_failure;
2233
2234 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2235 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002236 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002237 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002238 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2239 rdev->devlist_generation ^
2240 (cfg80211_rdev_list_generation << 2)))
2241 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002242
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002243 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002244 int ret;
2245 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002246
Johannes Berg683b6d32012-11-08 21:25:48 +01002247 ret = rdev_get_channel(rdev, wdev, &chandef);
2248 if (ret == 0) {
2249 if (nl80211_send_chandef(msg, &chandef))
2250 goto nla_put_failure;
2251 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002252 }
2253
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002254 if (wdev->ssid_len) {
2255 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2256 goto nla_put_failure;
2257 }
2258
Johannes Berg55682962007-09-20 13:09:35 -04002259 return genlmsg_end(msg, hdr);
2260
2261 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002262 genlmsg_cancel(msg, hdr);
2263 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002264}
2265
2266static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2267{
2268 int wp_idx = 0;
2269 int if_idx = 0;
2270 int wp_start = cb->args[0];
2271 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002272 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002273 struct wireless_dev *wdev;
2274
Johannes Berg5fe231e2013-05-08 21:45:15 +02002275 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002276 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2277 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002278 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002279 if (wp_idx < wp_start) {
2280 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002281 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002282 }
Johannes Berg55682962007-09-20 13:09:35 -04002283 if_idx = 0;
2284
Johannes Berg89a54e42012-06-15 14:33:17 +02002285 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002286 if (if_idx < if_start) {
2287 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002288 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002289 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002290 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002291 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002292 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002293 goto out;
2294 }
2295 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002296 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002297
2298 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002299 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002300 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002301 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002302
2303 cb->args[0] = wp_idx;
2304 cb->args[1] = if_idx;
2305
2306 return skb->len;
2307}
2308
2309static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2310{
2311 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002312 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002313 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002314
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002316 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002317 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002318
Eric W. Biederman15e47302012-09-07 20:12:54 +00002319 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002320 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002321 nlmsg_free(msg);
2322 return -ENOBUFS;
2323 }
Johannes Berg55682962007-09-20 13:09:35 -04002324
Johannes Berg134e6372009-07-10 09:51:34 +00002325 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002326}
2327
Michael Wu66f7ac52008-01-31 19:48:22 +01002328static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2329 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2330 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2331 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2332 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2333 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002334 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002335};
2336
2337static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2338{
2339 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2340 int flag;
2341
2342 *mntrflags = 0;
2343
2344 if (!nla)
2345 return -EINVAL;
2346
2347 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2348 nla, mntr_flags_policy))
2349 return -EINVAL;
2350
2351 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2352 if (flags[flag])
2353 *mntrflags |= (1<<flag);
2354
2355 return 0;
2356}
2357
Johannes Berg9bc383d2009-11-19 11:55:19 +01002358static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002359 struct net_device *netdev, u8 use_4addr,
2360 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002361{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002362 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002363 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002364 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002365 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002366 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002367
2368 switch (iftype) {
2369 case NL80211_IFTYPE_AP_VLAN:
2370 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2371 return 0;
2372 break;
2373 case NL80211_IFTYPE_STATION:
2374 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2375 return 0;
2376 break;
2377 default:
2378 break;
2379 }
2380
2381 return -EOPNOTSUPP;
2382}
2383
Johannes Berg55682962007-09-20 13:09:35 -04002384static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2385{
Johannes Berg4c476992010-10-04 21:36:35 +02002386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002387 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002388 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002389 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002390 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002391 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002392 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002393
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002394 memset(&params, 0, sizeof(params));
2395
Johannes Berg04a773a2009-04-19 21:24:32 +02002396 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002397
Johannes Berg723b0382008-09-16 20:22:09 +02002398 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002399 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002400 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002401 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002402 if (ntype > NL80211_IFTYPE_MAX)
2403 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002404 }
2405
Johannes Berg92ffe052008-09-16 20:39:36 +02002406 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002407 struct wireless_dev *wdev = dev->ieee80211_ptr;
2408
Johannes Berg4c476992010-10-04 21:36:35 +02002409 if (ntype != NL80211_IFTYPE_MESH_POINT)
2410 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002411 if (netif_running(dev))
2412 return -EBUSY;
2413
2414 wdev_lock(wdev);
2415 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2416 IEEE80211_MAX_MESH_ID_LEN);
2417 wdev->mesh_id_up_len =
2418 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2419 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2420 wdev->mesh_id_up_len);
2421 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002422 }
2423
Felix Fietkau8b787642009-11-10 18:53:10 +01002424 if (info->attrs[NL80211_ATTR_4ADDR]) {
2425 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2426 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002427 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002428 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002429 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002430 } else {
2431 params.use_4addr = -1;
2432 }
2433
Johannes Berg92ffe052008-09-16 20:39:36 +02002434 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002435 if (ntype != NL80211_IFTYPE_MONITOR)
2436 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002437 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2438 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002439 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002440 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002441
2442 flags = &_flags;
2443 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002444 }
Johannes Berg3b858752009-03-12 09:55:09 +01002445
Luciano Coelho18003292013-08-29 13:26:57 +03002446 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002447 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2448 return -EOPNOTSUPP;
2449
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002450 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002451 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002452 else
2453 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002454
Johannes Berg9bc383d2009-11-19 11:55:19 +01002455 if (!err && params.use_4addr != -1)
2456 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2457
Johannes Berg55682962007-09-20 13:09:35 -04002458 return err;
2459}
2460
2461static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2462{
Johannes Berg4c476992010-10-04 21:36:35 +02002463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002464 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002465 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002466 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002467 int err;
2468 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002469 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002470
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002471 memset(&params, 0, sizeof(params));
2472
Johannes Berg55682962007-09-20 13:09:35 -04002473 if (!info->attrs[NL80211_ATTR_IFNAME])
2474 return -EINVAL;
2475
2476 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2477 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2478 if (type > NL80211_IFTYPE_MAX)
2479 return -EINVAL;
2480 }
2481
Johannes Berg79c97e92009-07-07 03:56:12 +02002482 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002483 !(rdev->wiphy.interface_modes & (1 << type)))
2484 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002485
Arend van Spriel1c18f142013-01-08 10:17:27 +01002486 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2487 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2488 ETH_ALEN);
2489 if (!is_valid_ether_addr(params.macaddr))
2490 return -EADDRNOTAVAIL;
2491 }
2492
Johannes Berg9bc383d2009-11-19 11:55:19 +01002493 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002494 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002495 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002496 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002497 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002498 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002499
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002500 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2501 if (!msg)
2502 return -ENOMEM;
2503
Michael Wu66f7ac52008-01-31 19:48:22 +01002504 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2505 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2506 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002507
Luciano Coelho18003292013-08-29 13:26:57 +03002508 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002509 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2510 return -EOPNOTSUPP;
2511
Hila Gonene35e4d22012-06-27 17:19:42 +03002512 wdev = rdev_add_virtual_intf(rdev,
2513 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2514 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002515 if (IS_ERR(wdev)) {
2516 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002517 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002518 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002519
Johannes Berg98104fde2012-06-16 00:19:54 +02002520 switch (type) {
2521 case NL80211_IFTYPE_MESH_POINT:
2522 if (!info->attrs[NL80211_ATTR_MESH_ID])
2523 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002524 wdev_lock(wdev);
2525 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2526 IEEE80211_MAX_MESH_ID_LEN);
2527 wdev->mesh_id_up_len =
2528 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2529 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2530 wdev->mesh_id_up_len);
2531 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002532 break;
2533 case NL80211_IFTYPE_P2P_DEVICE:
2534 /*
2535 * P2P Device doesn't have a netdev, so doesn't go
2536 * through the netdev notifier and must be added here
2537 */
2538 mutex_init(&wdev->mtx);
2539 INIT_LIST_HEAD(&wdev->event_list);
2540 spin_lock_init(&wdev->event_lock);
2541 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2542 spin_lock_init(&wdev->mgmt_registrations_lock);
2543
Johannes Berg98104fde2012-06-16 00:19:54 +02002544 wdev->identifier = ++rdev->wdev_id;
2545 list_add_rcu(&wdev->list, &rdev->wdev_list);
2546 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002547 break;
2548 default:
2549 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002550 }
2551
Eric W. Biederman15e47302012-09-07 20:12:54 +00002552 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002553 rdev, wdev) < 0) {
2554 nlmsg_free(msg);
2555 return -ENOBUFS;
2556 }
2557
2558 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002559}
2560
2561static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2562{
Johannes Berg4c476992010-10-04 21:36:35 +02002563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002564 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002565
Johannes Berg4c476992010-10-04 21:36:35 +02002566 if (!rdev->ops->del_virtual_intf)
2567 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002568
Johannes Berg84efbb82012-06-16 00:00:26 +02002569 /*
2570 * If we remove a wireless device without a netdev then clear
2571 * user_ptr[1] so that nl80211_post_doit won't dereference it
2572 * to check if it needs to do dev_put(). Otherwise it crashes
2573 * since the wdev has been freed, unlike with a netdev where
2574 * we need the dev_put() for the netdev to really be freed.
2575 */
2576 if (!wdev->netdev)
2577 info->user_ptr[1] = NULL;
2578
Hila Gonene35e4d22012-06-27 17:19:42 +03002579 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002580}
2581
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002582static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2583{
2584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2585 struct net_device *dev = info->user_ptr[1];
2586 u16 noack_map;
2587
2588 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2589 return -EINVAL;
2590
2591 if (!rdev->ops->set_noack_map)
2592 return -EOPNOTSUPP;
2593
2594 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2595
Hila Gonene35e4d22012-06-27 17:19:42 +03002596 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002597}
2598
Johannes Berg41ade002007-12-19 02:03:29 +01002599struct get_key_cookie {
2600 struct sk_buff *msg;
2601 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002602 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002603};
2604
2605static void get_key_callback(void *c, struct key_params *params)
2606{
Johannes Bergb9454e82009-07-08 13:29:08 +02002607 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002608 struct get_key_cookie *cookie = c;
2609
David S. Miller9360ffd2012-03-29 04:41:26 -04002610 if ((params->key &&
2611 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2612 params->key_len, params->key)) ||
2613 (params->seq &&
2614 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2615 params->seq_len, params->seq)) ||
2616 (params->cipher &&
2617 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2618 params->cipher)))
2619 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002620
Johannes Bergb9454e82009-07-08 13:29:08 +02002621 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2622 if (!key)
2623 goto nla_put_failure;
2624
David S. Miller9360ffd2012-03-29 04:41:26 -04002625 if ((params->key &&
2626 nla_put(cookie->msg, NL80211_KEY_DATA,
2627 params->key_len, params->key)) ||
2628 (params->seq &&
2629 nla_put(cookie->msg, NL80211_KEY_SEQ,
2630 params->seq_len, params->seq)) ||
2631 (params->cipher &&
2632 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2633 params->cipher)))
2634 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002635
David S. Miller9360ffd2012-03-29 04:41:26 -04002636 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2637 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002638
2639 nla_nest_end(cookie->msg, key);
2640
Johannes Berg41ade002007-12-19 02:03:29 +01002641 return;
2642 nla_put_failure:
2643 cookie->error = 1;
2644}
2645
2646static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2647{
Johannes Berg4c476992010-10-04 21:36:35 +02002648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002649 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002650 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002651 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002652 const u8 *mac_addr = NULL;
2653 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002654 struct get_key_cookie cookie = {
2655 .error = 0,
2656 };
2657 void *hdr;
2658 struct sk_buff *msg;
2659
2660 if (info->attrs[NL80211_ATTR_KEY_IDX])
2661 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2662
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002663 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002664 return -EINVAL;
2665
2666 if (info->attrs[NL80211_ATTR_MAC])
2667 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2668
Johannes Berge31b8212010-10-05 19:39:30 +02002669 pairwise = !!mac_addr;
2670 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2671 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2672 if (kt >= NUM_NL80211_KEYTYPES)
2673 return -EINVAL;
2674 if (kt != NL80211_KEYTYPE_GROUP &&
2675 kt != NL80211_KEYTYPE_PAIRWISE)
2676 return -EINVAL;
2677 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2678 }
2679
Johannes Berg4c476992010-10-04 21:36:35 +02002680 if (!rdev->ops->get_key)
2681 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002682
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002683 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002684 if (!msg)
2685 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002686
Eric W. Biederman15e47302012-09-07 20:12:54 +00002687 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002688 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002689 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002690 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002691
2692 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002693 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002694
David S. Miller9360ffd2012-03-29 04:41:26 -04002695 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2696 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2697 goto nla_put_failure;
2698 if (mac_addr &&
2699 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2700 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002701
Johannes Berge31b8212010-10-05 19:39:30 +02002702 if (pairwise && mac_addr &&
2703 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2704 return -ENOENT;
2705
Hila Gonene35e4d22012-06-27 17:19:42 +03002706 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2707 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002708
2709 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002710 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002711
2712 if (cookie.error)
2713 goto nla_put_failure;
2714
2715 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002716 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002717
2718 nla_put_failure:
2719 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002720 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002721 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002722 return err;
2723}
2724
2725static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2726{
Johannes Berg4c476992010-10-04 21:36:35 +02002727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002728 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002729 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002730 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002731
Johannes Bergb9454e82009-07-08 13:29:08 +02002732 err = nl80211_parse_key(info, &key);
2733 if (err)
2734 return err;
2735
2736 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002737 return -EINVAL;
2738
Johannes Bergb9454e82009-07-08 13:29:08 +02002739 /* only support setting default key */
2740 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002741 return -EINVAL;
2742
Johannes Bergfffd0932009-07-08 14:22:54 +02002743 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002744
2745 if (key.def) {
2746 if (!rdev->ops->set_default_key) {
2747 err = -EOPNOTSUPP;
2748 goto out;
2749 }
2750
2751 err = nl80211_key_allowed(dev->ieee80211_ptr);
2752 if (err)
2753 goto out;
2754
Hila Gonene35e4d22012-06-27 17:19:42 +03002755 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002756 key.def_uni, key.def_multi);
2757
2758 if (err)
2759 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002760
Johannes Berg3d23e342009-09-29 23:27:28 +02002761#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002762 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002763#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002764 } else {
2765 if (key.def_uni || !key.def_multi) {
2766 err = -EINVAL;
2767 goto out;
2768 }
2769
2770 if (!rdev->ops->set_default_mgmt_key) {
2771 err = -EOPNOTSUPP;
2772 goto out;
2773 }
2774
2775 err = nl80211_key_allowed(dev->ieee80211_ptr);
2776 if (err)
2777 goto out;
2778
Hila Gonene35e4d22012-06-27 17:19:42 +03002779 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002780 if (err)
2781 goto out;
2782
2783#ifdef CONFIG_CFG80211_WEXT
2784 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2785#endif
2786 }
2787
2788 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002789 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002790
Johannes Berg41ade002007-12-19 02:03:29 +01002791 return err;
2792}
2793
2794static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2795{
Johannes Berg4c476992010-10-04 21:36:35 +02002796 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002797 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002798 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002799 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002800 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002801
Johannes Bergb9454e82009-07-08 13:29:08 +02002802 err = nl80211_parse_key(info, &key);
2803 if (err)
2804 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002805
Johannes Bergb9454e82009-07-08 13:29:08 +02002806 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002807 return -EINVAL;
2808
Johannes Berg41ade002007-12-19 02:03:29 +01002809 if (info->attrs[NL80211_ATTR_MAC])
2810 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2811
Johannes Berge31b8212010-10-05 19:39:30 +02002812 if (key.type == -1) {
2813 if (mac_addr)
2814 key.type = NL80211_KEYTYPE_PAIRWISE;
2815 else
2816 key.type = NL80211_KEYTYPE_GROUP;
2817 }
2818
2819 /* for now */
2820 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2821 key.type != NL80211_KEYTYPE_GROUP)
2822 return -EINVAL;
2823
Johannes Berg4c476992010-10-04 21:36:35 +02002824 if (!rdev->ops->add_key)
2825 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002826
Johannes Berge31b8212010-10-05 19:39:30 +02002827 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2828 key.type == NL80211_KEYTYPE_PAIRWISE,
2829 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002830 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002831
2832 wdev_lock(dev->ieee80211_ptr);
2833 err = nl80211_key_allowed(dev->ieee80211_ptr);
2834 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002835 err = rdev_add_key(rdev, dev, key.idx,
2836 key.type == NL80211_KEYTYPE_PAIRWISE,
2837 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002838 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002839
Johannes Berg41ade002007-12-19 02:03:29 +01002840 return err;
2841}
2842
2843static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2844{
Johannes Berg4c476992010-10-04 21:36:35 +02002845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002846 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002847 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002848 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002849 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002850
Johannes Bergb9454e82009-07-08 13:29:08 +02002851 err = nl80211_parse_key(info, &key);
2852 if (err)
2853 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002854
2855 if (info->attrs[NL80211_ATTR_MAC])
2856 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2857
Johannes Berge31b8212010-10-05 19:39:30 +02002858 if (key.type == -1) {
2859 if (mac_addr)
2860 key.type = NL80211_KEYTYPE_PAIRWISE;
2861 else
2862 key.type = NL80211_KEYTYPE_GROUP;
2863 }
2864
2865 /* for now */
2866 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2867 key.type != NL80211_KEYTYPE_GROUP)
2868 return -EINVAL;
2869
Johannes Berg4c476992010-10-04 21:36:35 +02002870 if (!rdev->ops->del_key)
2871 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002872
Johannes Bergfffd0932009-07-08 14:22:54 +02002873 wdev_lock(dev->ieee80211_ptr);
2874 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002875
2876 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2877 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2878 err = -ENOENT;
2879
Johannes Bergfffd0932009-07-08 14:22:54 +02002880 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002881 err = rdev_del_key(rdev, dev, key.idx,
2882 key.type == NL80211_KEYTYPE_PAIRWISE,
2883 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002884
Johannes Berg3d23e342009-09-29 23:27:28 +02002885#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002886 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002887 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002888 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002889 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002890 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2891 }
2892#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002893 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002894
Johannes Berg41ade002007-12-19 02:03:29 +01002895 return err;
2896}
2897
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302898/* This function returns an error or the number of nested attributes */
2899static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2900{
2901 struct nlattr *attr;
2902 int n_entries = 0, tmp;
2903
2904 nla_for_each_nested(attr, nl_attr, tmp) {
2905 if (nla_len(attr) != ETH_ALEN)
2906 return -EINVAL;
2907
2908 n_entries++;
2909 }
2910
2911 return n_entries;
2912}
2913
2914/*
2915 * This function parses ACL information and allocates memory for ACL data.
2916 * On successful return, the calling function is responsible to free the
2917 * ACL buffer returned by this function.
2918 */
2919static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2920 struct genl_info *info)
2921{
2922 enum nl80211_acl_policy acl_policy;
2923 struct nlattr *attr;
2924 struct cfg80211_acl_data *acl;
2925 int i = 0, n_entries, tmp;
2926
2927 if (!wiphy->max_acl_mac_addrs)
2928 return ERR_PTR(-EOPNOTSUPP);
2929
2930 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2931 return ERR_PTR(-EINVAL);
2932
2933 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2934 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2935 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2936 return ERR_PTR(-EINVAL);
2937
2938 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2939 return ERR_PTR(-EINVAL);
2940
2941 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2942 if (n_entries < 0)
2943 return ERR_PTR(n_entries);
2944
2945 if (n_entries > wiphy->max_acl_mac_addrs)
2946 return ERR_PTR(-ENOTSUPP);
2947
2948 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2949 GFP_KERNEL);
2950 if (!acl)
2951 return ERR_PTR(-ENOMEM);
2952
2953 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2954 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2955 i++;
2956 }
2957
2958 acl->n_acl_entries = n_entries;
2959 acl->acl_policy = acl_policy;
2960
2961 return acl;
2962}
2963
2964static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2965{
2966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2967 struct net_device *dev = info->user_ptr[1];
2968 struct cfg80211_acl_data *acl;
2969 int err;
2970
2971 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2972 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2973 return -EOPNOTSUPP;
2974
2975 if (!dev->ieee80211_ptr->beacon_interval)
2976 return -EINVAL;
2977
2978 acl = parse_acl_data(&rdev->wiphy, info);
2979 if (IS_ERR(acl))
2980 return PTR_ERR(acl);
2981
2982 err = rdev_set_mac_acl(rdev, dev, acl);
2983
2984 kfree(acl);
2985
2986 return err;
2987}
2988
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002989static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002990 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002991{
Johannes Berg88600202012-02-13 15:17:18 +01002992 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002993
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002994 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2995 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2996 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2997 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002998 return -EINVAL;
2999
Johannes Berg88600202012-02-13 15:17:18 +01003000 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003001
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3003 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3004 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003005 if (!bcn->head_len)
3006 return -EINVAL;
3007 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003008 }
3009
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003010 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3011 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3012 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003013 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003014 }
3015
Johannes Berg4c476992010-10-04 21:36:35 +02003016 if (!haveinfo)
3017 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003018
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003019 if (attrs[NL80211_ATTR_IE]) {
3020 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3021 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003022 }
3023
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003024 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003025 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003026 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003027 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003028 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003029 }
3030
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003031 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003032 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003033 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003034 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003035 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003036 }
3037
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003038 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3039 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3040 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003041 }
3042
Johannes Berg88600202012-02-13 15:17:18 +01003043 return 0;
3044}
3045
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003046static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3047 struct cfg80211_ap_settings *params)
3048{
3049 struct wireless_dev *wdev;
3050 bool ret = false;
3051
Johannes Berg89a54e42012-06-15 14:33:17 +02003052 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003053 if (wdev->iftype != NL80211_IFTYPE_AP &&
3054 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3055 continue;
3056
Johannes Berg683b6d32012-11-08 21:25:48 +01003057 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003058 continue;
3059
Johannes Berg683b6d32012-11-08 21:25:48 +01003060 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003061 ret = true;
3062 break;
3063 }
3064
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003065 return ret;
3066}
3067
Jouni Malinene39e5b52012-09-30 19:29:39 +03003068static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3069 enum nl80211_auth_type auth_type,
3070 enum nl80211_commands cmd)
3071{
3072 if (auth_type > NL80211_AUTHTYPE_MAX)
3073 return false;
3074
3075 switch (cmd) {
3076 case NL80211_CMD_AUTHENTICATE:
3077 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3078 auth_type == NL80211_AUTHTYPE_SAE)
3079 return false;
3080 return true;
3081 case NL80211_CMD_CONNECT:
3082 case NL80211_CMD_START_AP:
3083 /* SAE not supported yet */
3084 if (auth_type == NL80211_AUTHTYPE_SAE)
3085 return false;
3086 return true;
3087 default:
3088 return false;
3089 }
3090}
3091
Johannes Berg88600202012-02-13 15:17:18 +01003092static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3093{
3094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3095 struct net_device *dev = info->user_ptr[1];
3096 struct wireless_dev *wdev = dev->ieee80211_ptr;
3097 struct cfg80211_ap_settings params;
3098 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003099 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003100
3101 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3102 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3103 return -EOPNOTSUPP;
3104
3105 if (!rdev->ops->start_ap)
3106 return -EOPNOTSUPP;
3107
3108 if (wdev->beacon_interval)
3109 return -EALREADY;
3110
3111 memset(&params, 0, sizeof(params));
3112
3113 /* these are required for START_AP */
3114 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3115 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3116 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3117 return -EINVAL;
3118
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003119 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003120 if (err)
3121 return err;
3122
3123 params.beacon_interval =
3124 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3125 params.dtim_period =
3126 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3127
3128 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3129 if (err)
3130 return err;
3131
3132 /*
3133 * In theory, some of these attributes should be required here
3134 * but since they were not used when the command was originally
3135 * added, keep them optional for old user space programs to let
3136 * them continue to work with drivers that do not need the
3137 * additional information -- drivers must check!
3138 */
3139 if (info->attrs[NL80211_ATTR_SSID]) {
3140 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3141 params.ssid_len =
3142 nla_len(info->attrs[NL80211_ATTR_SSID]);
3143 if (params.ssid_len == 0 ||
3144 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3145 return -EINVAL;
3146 }
3147
3148 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3149 params.hidden_ssid = nla_get_u32(
3150 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3151 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3152 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3153 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3154 return -EINVAL;
3155 }
3156
3157 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3158
3159 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3160 params.auth_type = nla_get_u32(
3161 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003162 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3163 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003164 return -EINVAL;
3165 } else
3166 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3167
3168 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3169 NL80211_MAX_NR_CIPHER_SUITES);
3170 if (err)
3171 return err;
3172
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303173 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3174 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3175 return -EOPNOTSUPP;
3176 params.inactivity_timeout = nla_get_u16(
3177 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3178 }
3179
Johannes Berg53cabad2012-11-14 15:17:28 +01003180 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3182 return -EINVAL;
3183 params.p2p_ctwindow =
3184 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3185 if (params.p2p_ctwindow > 127)
3186 return -EINVAL;
3187 if (params.p2p_ctwindow != 0 &&
3188 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3189 return -EINVAL;
3190 }
3191
3192 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3193 u8 tmp;
3194
3195 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3196 return -EINVAL;
3197 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3198 if (tmp > 1)
3199 return -EINVAL;
3200 params.p2p_opp_ps = tmp;
3201 if (params.p2p_opp_ps != 0 &&
3202 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3203 return -EINVAL;
3204 }
3205
Johannes Bergaa430da2012-05-16 23:50:18 +02003206 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003207 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3208 if (err)
3209 return err;
3210 } else if (wdev->preset_chandef.chan) {
3211 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003212 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003213 return -EINVAL;
3214
Johannes Berg683b6d32012-11-08 21:25:48 +01003215 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003216 return -EINVAL;
3217
Simon Wunderlich04f39042013-02-08 18:16:19 +01003218 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3219 if (err < 0)
3220 return err;
3221 if (err) {
3222 radar_detect_width = BIT(params.chandef.width);
3223 params.radar_required = true;
3224 }
3225
Simon Wunderlich04f39042013-02-08 18:16:19 +01003226 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3227 params.chandef.chan,
3228 CHAN_MODE_SHARED,
3229 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003230 if (err)
3231 return err;
3232
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303233 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3234 params.acl = parse_acl_data(&rdev->wiphy, info);
3235 if (IS_ERR(params.acl))
3236 return PTR_ERR(params.acl);
3237 }
3238
Hila Gonene35e4d22012-06-27 17:19:42 +03003239 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003240 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003241 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003242 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003243 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003244 wdev->ssid_len = params.ssid_len;
3245 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003246 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303247
3248 kfree(params.acl);
3249
Johannes Berg56d18932011-05-09 18:41:15 +02003250 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003251}
3252
Johannes Berg88600202012-02-13 15:17:18 +01003253static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3254{
3255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3256 struct net_device *dev = info->user_ptr[1];
3257 struct wireless_dev *wdev = dev->ieee80211_ptr;
3258 struct cfg80211_beacon_data params;
3259 int err;
3260
3261 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3262 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3263 return -EOPNOTSUPP;
3264
3265 if (!rdev->ops->change_beacon)
3266 return -EOPNOTSUPP;
3267
3268 if (!wdev->beacon_interval)
3269 return -EINVAL;
3270
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003271 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003272 if (err)
3273 return err;
3274
Hila Gonene35e4d22012-06-27 17:19:42 +03003275 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003276}
3277
3278static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003279{
Johannes Berg4c476992010-10-04 21:36:35 +02003280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3281 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003282
Michal Kazior60771782012-06-29 12:46:56 +02003283 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003284}
3285
Johannes Berg5727ef12007-12-19 02:03:34 +01003286static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3287 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3288 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3289 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003290 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003291 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003292 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003293};
3294
Johannes Bergeccb8e82009-05-11 21:57:56 +03003295static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003296 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003297 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003298{
3299 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003300 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003301 int flag;
3302
Johannes Bergeccb8e82009-05-11 21:57:56 +03003303 /*
3304 * Try parsing the new attribute first so userspace
3305 * can specify both for older kernels.
3306 */
3307 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3308 if (nla) {
3309 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003310
Johannes Bergeccb8e82009-05-11 21:57:56 +03003311 sta_flags = nla_data(nla);
3312 params->sta_flags_mask = sta_flags->mask;
3313 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003314 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003315 if ((params->sta_flags_mask |
3316 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3317 return -EINVAL;
3318 return 0;
3319 }
3320
3321 /* if present, parse the old attribute */
3322
3323 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003324 if (!nla)
3325 return 0;
3326
3327 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3328 nla, sta_flags_policy))
3329 return -EINVAL;
3330
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003331 /*
3332 * Only allow certain flags for interface types so that
3333 * other attributes are silently ignored. Remember that
3334 * this is backward compatibility code with old userspace
3335 * and shouldn't be hit in other cases anyway.
3336 */
3337 switch (iftype) {
3338 case NL80211_IFTYPE_AP:
3339 case NL80211_IFTYPE_AP_VLAN:
3340 case NL80211_IFTYPE_P2P_GO:
3341 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3342 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3343 BIT(NL80211_STA_FLAG_WME) |
3344 BIT(NL80211_STA_FLAG_MFP);
3345 break;
3346 case NL80211_IFTYPE_P2P_CLIENT:
3347 case NL80211_IFTYPE_STATION:
3348 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3349 BIT(NL80211_STA_FLAG_TDLS_PEER);
3350 break;
3351 case NL80211_IFTYPE_MESH_POINT:
3352 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3353 BIT(NL80211_STA_FLAG_MFP) |
3354 BIT(NL80211_STA_FLAG_AUTHORIZED);
3355 default:
3356 return -EINVAL;
3357 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003358
Johannes Berg3383b5a2012-05-10 20:14:43 +02003359 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3360 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003361 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003362
Johannes Berg3383b5a2012-05-10 20:14:43 +02003363 /* no longer support new API additions in old API */
3364 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3365 return -EINVAL;
3366 }
3367 }
3368
Johannes Berg5727ef12007-12-19 02:03:34 +01003369 return 0;
3370}
3371
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003372static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3373 int attr)
3374{
3375 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003376 u32 bitrate;
3377 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003378
3379 rate = nla_nest_start(msg, attr);
3380 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003381 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003382
3383 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3384 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003385 /* report 16-bit bitrate only if we can */
3386 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003387 if (bitrate > 0 &&
3388 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3389 return false;
3390 if (bitrate_compat > 0 &&
3391 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3392 return false;
3393
3394 if (info->flags & RATE_INFO_FLAGS_MCS) {
3395 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3396 return false;
3397 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3398 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3399 return false;
3400 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3401 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3402 return false;
3403 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3404 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3405 return false;
3406 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3407 return false;
3408 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3409 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3410 return false;
3411 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3412 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3413 return false;
3414 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3415 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3416 return false;
3417 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3418 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3419 return false;
3420 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3421 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3422 return false;
3423 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003424
3425 nla_nest_end(msg, rate);
3426 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003427}
3428
Felix Fietkau119363c2013-04-22 16:29:30 +02003429static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3430 int id)
3431{
3432 void *attr;
3433 int i = 0;
3434
3435 if (!mask)
3436 return true;
3437
3438 attr = nla_nest_start(msg, id);
3439 if (!attr)
3440 return false;
3441
3442 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3443 if (!(mask & BIT(i)))
3444 continue;
3445
3446 if (nla_put_u8(msg, i, signal[i]))
3447 return false;
3448 }
3449
3450 nla_nest_end(msg, attr);
3451
3452 return true;
3453}
3454
Eric W. Biederman15e47302012-09-07 20:12:54 +00003455static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003456 int flags,
3457 struct cfg80211_registered_device *rdev,
3458 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003459 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003460{
3461 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003462 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003463
Eric W. Biederman15e47302012-09-07 20:12:54 +00003464 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003465 if (!hdr)
3466 return -1;
3467
David S. Miller9360ffd2012-03-29 04:41:26 -04003468 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3469 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3470 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3471 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003472
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003473 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3474 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003475 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003476 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3477 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3478 sinfo->connected_time))
3479 goto nla_put_failure;
3480 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3481 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3482 sinfo->inactive_time))
3483 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003484 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3485 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003486 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003487 (u32)sinfo->rx_bytes))
3488 goto nla_put_failure;
3489 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003490 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003491 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3492 (u32)sinfo->tx_bytes))
3493 goto nla_put_failure;
3494 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3495 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003496 sinfo->rx_bytes))
3497 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003498 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3499 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003500 sinfo->tx_bytes))
3501 goto nla_put_failure;
3502 if ((sinfo->filled & STATION_INFO_LLID) &&
3503 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3504 goto nla_put_failure;
3505 if ((sinfo->filled & STATION_INFO_PLID) &&
3506 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3507 goto nla_put_failure;
3508 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3509 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3510 sinfo->plink_state))
3511 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003512 switch (rdev->wiphy.signal_type) {
3513 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003514 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3515 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3516 sinfo->signal))
3517 goto nla_put_failure;
3518 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3519 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3520 sinfo->signal_avg))
3521 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003522 break;
3523 default:
3524 break;
3525 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003526 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3527 if (!nl80211_put_signal(msg, sinfo->chains,
3528 sinfo->chain_signal,
3529 NL80211_STA_INFO_CHAIN_SIGNAL))
3530 goto nla_put_failure;
3531 }
3532 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3533 if (!nl80211_put_signal(msg, sinfo->chains,
3534 sinfo->chain_signal_avg,
3535 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3536 goto nla_put_failure;
3537 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003538 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003539 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3540 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003541 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003542 }
3543 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3544 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3545 NL80211_STA_INFO_RX_BITRATE))
3546 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003547 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003548 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3549 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3550 sinfo->rx_packets))
3551 goto nla_put_failure;
3552 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3553 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3554 sinfo->tx_packets))
3555 goto nla_put_failure;
3556 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3557 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3558 sinfo->tx_retries))
3559 goto nla_put_failure;
3560 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3561 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3562 sinfo->tx_failed))
3563 goto nla_put_failure;
3564 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3565 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3566 sinfo->beacon_loss_count))
3567 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003568 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3569 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3570 sinfo->local_pm))
3571 goto nla_put_failure;
3572 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3573 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3574 sinfo->peer_pm))
3575 goto nla_put_failure;
3576 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3577 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3578 sinfo->nonpeer_pm))
3579 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003580 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3581 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3582 if (!bss_param)
3583 goto nla_put_failure;
3584
David S. Miller9360ffd2012-03-29 04:41:26 -04003585 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3586 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3587 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3588 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3589 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3590 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3591 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3592 sinfo->bss_param.dtim_period) ||
3593 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3594 sinfo->bss_param.beacon_interval))
3595 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003596
3597 nla_nest_end(msg, bss_param);
3598 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003599 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3600 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3601 sizeof(struct nl80211_sta_flag_update),
3602 &sinfo->sta_flags))
3603 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003604 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3605 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3606 sinfo->t_offset))
3607 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003608 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003609
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3611 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3612 sinfo->assoc_req_ies))
3613 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003614
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003615 return genlmsg_end(msg, hdr);
3616
3617 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003618 genlmsg_cancel(msg, hdr);
3619 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003620}
3621
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003622static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003623 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003624{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003625 struct station_info sinfo;
3626 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003627 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003628 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003629 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003630 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003631
Johannes Berg97990a02013-04-19 01:02:55 +02003632 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003633 if (err)
3634 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003635
Johannes Berg97990a02013-04-19 01:02:55 +02003636 if (!wdev->netdev) {
3637 err = -EINVAL;
3638 goto out_err;
3639 }
3640
Johannes Bergbba95fe2008-07-29 13:22:51 +02003641 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003642 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003643 goto out_err;
3644 }
3645
Johannes Bergbba95fe2008-07-29 13:22:51 +02003646 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003647 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003648 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003649 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003650 if (err == -ENOENT)
3651 break;
3652 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003653 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003654
3655 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003656 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003657 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003658 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003659 &sinfo) < 0)
3660 goto out;
3661
3662 sta_idx++;
3663 }
3664
3665
3666 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003667 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003668 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003669 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003670 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003671
3672 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003673}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003674
Johannes Berg5727ef12007-12-19 02:03:34 +01003675static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3676{
Johannes Berg4c476992010-10-04 21:36:35 +02003677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3678 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003679 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003680 struct sk_buff *msg;
3681 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003682 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003683
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003684 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003685
3686 if (!info->attrs[NL80211_ATTR_MAC])
3687 return -EINVAL;
3688
3689 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3690
Johannes Berg4c476992010-10-04 21:36:35 +02003691 if (!rdev->ops->get_station)
3692 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003693
Hila Gonene35e4d22012-06-27 17:19:42 +03003694 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003695 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003696 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003697
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003698 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003699 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003700 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003701
Eric W. Biederman15e47302012-09-07 20:12:54 +00003702 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003703 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003704 nlmsg_free(msg);
3705 return -ENOBUFS;
3706 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003707
Johannes Berg4c476992010-10-04 21:36:35 +02003708 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003709}
3710
Johannes Berg77ee7c82013-02-15 00:48:33 +01003711int cfg80211_check_station_change(struct wiphy *wiphy,
3712 struct station_parameters *params,
3713 enum cfg80211_station_type statype)
3714{
3715 if (params->listen_interval != -1)
3716 return -EINVAL;
3717 if (params->aid)
3718 return -EINVAL;
3719
3720 /* When you run into this, adjust the code below for the new flag */
3721 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3722
3723 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003724 case CFG80211_STA_MESH_PEER_KERNEL:
3725 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003726 /*
3727 * No ignoring the TDLS flag here -- the userspace mesh
3728 * code doesn't have the bug of including TDLS in the
3729 * mask everywhere.
3730 */
3731 if (params->sta_flags_mask &
3732 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3733 BIT(NL80211_STA_FLAG_MFP) |
3734 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3735 return -EINVAL;
3736 break;
3737 case CFG80211_STA_TDLS_PEER_SETUP:
3738 case CFG80211_STA_TDLS_PEER_ACTIVE:
3739 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3740 return -EINVAL;
3741 /* ignore since it can't change */
3742 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3743 break;
3744 default:
3745 /* disallow mesh-specific things */
3746 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3747 return -EINVAL;
3748 if (params->local_pm)
3749 return -EINVAL;
3750 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3751 return -EINVAL;
3752 }
3753
3754 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3755 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3756 /* TDLS can't be set, ... */
3757 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3758 return -EINVAL;
3759 /*
3760 * ... but don't bother the driver with it. This works around
3761 * a hostapd/wpa_supplicant issue -- it always includes the
3762 * TLDS_PEER flag in the mask even for AP mode.
3763 */
3764 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3765 }
3766
3767 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3768 /* reject other things that can't change */
3769 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3770 return -EINVAL;
3771 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3772 return -EINVAL;
3773 if (params->supported_rates)
3774 return -EINVAL;
3775 if (params->ext_capab || params->ht_capa || params->vht_capa)
3776 return -EINVAL;
3777 }
3778
3779 if (statype != CFG80211_STA_AP_CLIENT) {
3780 if (params->vlan)
3781 return -EINVAL;
3782 }
3783
3784 switch (statype) {
3785 case CFG80211_STA_AP_MLME_CLIENT:
3786 /* Use this only for authorizing/unauthorizing a station */
3787 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3788 return -EOPNOTSUPP;
3789 break;
3790 case CFG80211_STA_AP_CLIENT:
3791 /* accept only the listed bits */
3792 if (params->sta_flags_mask &
3793 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3794 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3795 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3796 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3797 BIT(NL80211_STA_FLAG_WME) |
3798 BIT(NL80211_STA_FLAG_MFP)))
3799 return -EINVAL;
3800
3801 /* but authenticated/associated only if driver handles it */
3802 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3803 params->sta_flags_mask &
3804 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3805 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3806 return -EINVAL;
3807 break;
3808 case CFG80211_STA_IBSS:
3809 case CFG80211_STA_AP_STA:
3810 /* reject any changes other than AUTHORIZED */
3811 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3812 return -EINVAL;
3813 break;
3814 case CFG80211_STA_TDLS_PEER_SETUP:
3815 /* reject any changes other than AUTHORIZED or WME */
3816 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3817 BIT(NL80211_STA_FLAG_WME)))
3818 return -EINVAL;
3819 /* force (at least) rates when authorizing */
3820 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3821 !params->supported_rates)
3822 return -EINVAL;
3823 break;
3824 case CFG80211_STA_TDLS_PEER_ACTIVE:
3825 /* reject any changes */
3826 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003827 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003828 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3829 return -EINVAL;
3830 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003831 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003832 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3833 return -EINVAL;
3834 break;
3835 }
3836
3837 return 0;
3838}
3839EXPORT_SYMBOL(cfg80211_check_station_change);
3840
Johannes Berg5727ef12007-12-19 02:03:34 +01003841/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003842 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003843 */
Johannes Berg80b99892011-11-18 16:23:01 +01003844static struct net_device *get_vlan(struct genl_info *info,
3845 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003846{
Johannes Berg463d0182009-07-14 00:33:35 +02003847 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003848 struct net_device *v;
3849 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003850
Johannes Berg80b99892011-11-18 16:23:01 +01003851 if (!vlanattr)
3852 return NULL;
3853
3854 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3855 if (!v)
3856 return ERR_PTR(-ENODEV);
3857
3858 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3859 ret = -EINVAL;
3860 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003861 }
Johannes Berg80b99892011-11-18 16:23:01 +01003862
Johannes Berg77ee7c82013-02-15 00:48:33 +01003863 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3864 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3865 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3866 ret = -EINVAL;
3867 goto error;
3868 }
3869
Johannes Berg80b99892011-11-18 16:23:01 +01003870 if (!netif_running(v)) {
3871 ret = -ENETDOWN;
3872 goto error;
3873 }
3874
3875 return v;
3876 error:
3877 dev_put(v);
3878 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003879}
3880
Jouni Malinendf881292013-02-14 21:10:54 +02003881static struct nla_policy
3882nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3883 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3884 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3885};
3886
Johannes Bergff276692013-02-15 00:09:01 +01003887static int nl80211_parse_sta_wme(struct genl_info *info,
3888 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003889{
Jouni Malinendf881292013-02-14 21:10:54 +02003890 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3891 struct nlattr *nla;
3892 int err;
3893
Jouni Malinendf881292013-02-14 21:10:54 +02003894 /* parse WME attributes if present */
3895 if (!info->attrs[NL80211_ATTR_STA_WME])
3896 return 0;
3897
3898 nla = info->attrs[NL80211_ATTR_STA_WME];
3899 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3900 nl80211_sta_wme_policy);
3901 if (err)
3902 return err;
3903
3904 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3905 params->uapsd_queues = nla_get_u8(
3906 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3907 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3908 return -EINVAL;
3909
3910 if (tb[NL80211_STA_WME_MAX_SP])
3911 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3912
3913 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3914 return -EINVAL;
3915
3916 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3917
3918 return 0;
3919}
3920
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303921static int nl80211_parse_sta_channel_info(struct genl_info *info,
3922 struct station_parameters *params)
3923{
3924 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3925 params->supported_channels =
3926 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3927 params->supported_channels_len =
3928 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3929 /*
3930 * Need to include at least one (first channel, number of
3931 * channels) tuple for each subband, and must have proper
3932 * tuples for the rest of the data as well.
3933 */
3934 if (params->supported_channels_len < 2)
3935 return -EINVAL;
3936 if (params->supported_channels_len % 2)
3937 return -EINVAL;
3938 }
3939
3940 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3941 params->supported_oper_classes =
3942 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3943 params->supported_oper_classes_len =
3944 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3945 /*
3946 * The value of the Length field of the Supported Operating
3947 * Classes element is between 2 and 253.
3948 */
3949 if (params->supported_oper_classes_len < 2 ||
3950 params->supported_oper_classes_len > 253)
3951 return -EINVAL;
3952 }
3953 return 0;
3954}
3955
Johannes Bergff276692013-02-15 00:09:01 +01003956static int nl80211_set_station_tdls(struct genl_info *info,
3957 struct station_parameters *params)
3958{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303959 int err;
Johannes Bergff276692013-02-15 00:09:01 +01003960 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003961 if (info->attrs[NL80211_ATTR_PEER_AID])
3962 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003963 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3964 params->ht_capa =
3965 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3966 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3967 params->vht_capa =
3968 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3969
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303970 err = nl80211_parse_sta_channel_info(info, params);
3971 if (err)
3972 return err;
3973
Johannes Bergff276692013-02-15 00:09:01 +01003974 return nl80211_parse_sta_wme(info, params);
3975}
3976
Johannes Berg5727ef12007-12-19 02:03:34 +01003977static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3978{
Johannes Berg4c476992010-10-04 21:36:35 +02003979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003980 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003981 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003982 u8 *mac_addr;
3983 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003984
3985 memset(&params, 0, sizeof(params));
3986
3987 params.listen_interval = -1;
3988
Johannes Berg77ee7c82013-02-15 00:48:33 +01003989 if (!rdev->ops->change_station)
3990 return -EOPNOTSUPP;
3991
Johannes Berg5727ef12007-12-19 02:03:34 +01003992 if (info->attrs[NL80211_ATTR_STA_AID])
3993 return -EINVAL;
3994
3995 if (!info->attrs[NL80211_ATTR_MAC])
3996 return -EINVAL;
3997
3998 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3999
4000 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4001 params.supported_rates =
4002 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4003 params.supported_rates_len =
4004 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4005 }
4006
Jouni Malinen9d62a982013-02-14 21:10:13 +02004007 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4008 params.capability =
4009 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4010 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4011 }
4012
4013 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4014 params.ext_capab =
4015 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4016 params.ext_capab_len =
4017 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4018 }
4019
Jouni Malinendf881292013-02-14 21:10:54 +02004020 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004021 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004022
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004023 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004024 return -EINVAL;
4025
Johannes Bergf8bacc22013-02-14 23:27:01 +01004026 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004027 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004028 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4029 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4030 return -EINVAL;
4031 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004032
Johannes Bergf8bacc22013-02-14 23:27:01 +01004033 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004034 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004035 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4036 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4037 return -EINVAL;
4038 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4039 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004040
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004041 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4042 enum nl80211_mesh_power_mode pm = nla_get_u32(
4043 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4044
4045 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4046 pm > NL80211_MESH_POWER_MAX)
4047 return -EINVAL;
4048
4049 params.local_pm = pm;
4050 }
4051
Johannes Berg77ee7c82013-02-15 00:48:33 +01004052 /* Include parameters for TDLS peer (will check later) */
4053 err = nl80211_set_station_tdls(info, &params);
4054 if (err)
4055 return err;
4056
4057 params.vlan = get_vlan(info, rdev);
4058 if (IS_ERR(params.vlan))
4059 return PTR_ERR(params.vlan);
4060
Johannes Berga97f4422009-06-18 17:23:43 +02004061 switch (dev->ieee80211_ptr->iftype) {
4062 case NL80211_IFTYPE_AP:
4063 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004064 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004065 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004066 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004067 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004068 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004069 break;
4070 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004071 err = -EOPNOTSUPP;
4072 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004073 }
4074
Johannes Berg77ee7c82013-02-15 00:48:33 +01004075 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004076 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004077
Johannes Berg77ee7c82013-02-15 00:48:33 +01004078 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004079 if (params.vlan)
4080 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004081
Johannes Berg5727ef12007-12-19 02:03:34 +01004082 return err;
4083}
4084
4085static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4086{
Johannes Berg4c476992010-10-04 21:36:35 +02004087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004088 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004089 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004090 struct station_parameters params;
4091 u8 *mac_addr = NULL;
4092
4093 memset(&params, 0, sizeof(params));
4094
Johannes Berg984c3112013-02-14 23:43:25 +01004095 if (!rdev->ops->add_station)
4096 return -EOPNOTSUPP;
4097
Johannes Berg5727ef12007-12-19 02:03:34 +01004098 if (!info->attrs[NL80211_ATTR_MAC])
4099 return -EINVAL;
4100
Johannes Berg5727ef12007-12-19 02:03:34 +01004101 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4102 return -EINVAL;
4103
4104 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4105 return -EINVAL;
4106
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004107 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4108 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004109 return -EINVAL;
4110
Johannes Berg5727ef12007-12-19 02:03:34 +01004111 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4112 params.supported_rates =
4113 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4114 params.supported_rates_len =
4115 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4116 params.listen_interval =
4117 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004118
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004119 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004120 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004121 else
4122 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004123 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4124 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004125
Jouni Malinen9d62a982013-02-14 21:10:13 +02004126 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4127 params.capability =
4128 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4129 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4130 }
4131
4132 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4133 params.ext_capab =
4134 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4135 params.ext_capab_len =
4136 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4137 }
4138
Jouni Malinen36aedc902008-08-25 11:58:58 +03004139 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4140 params.ht_capa =
4141 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004142
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004143 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4144 params.vht_capa =
4145 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4146
Johannes Bergf8bacc22013-02-14 23:27:01 +01004147 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004148 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004149 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4150 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4151 return -EINVAL;
4152 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004153
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304154 err = nl80211_parse_sta_channel_info(info, &params);
4155 if (err)
4156 return err;
4157
Johannes Bergff276692013-02-15 00:09:01 +01004158 err = nl80211_parse_sta_wme(info, &params);
4159 if (err)
4160 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004161
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004162 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004163 return -EINVAL;
4164
Johannes Berg77ee7c82013-02-15 00:48:33 +01004165 /* When you run into this, adjust the code below for the new flag */
4166 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4167
Johannes Bergbdd90d52011-12-14 12:20:27 +01004168 switch (dev->ieee80211_ptr->iftype) {
4169 case NL80211_IFTYPE_AP:
4170 case NL80211_IFTYPE_AP_VLAN:
4171 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004172 /* ignore WME attributes if iface/sta is not capable */
4173 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4174 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4175 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004176
Johannes Bergbdd90d52011-12-14 12:20:27 +01004177 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004178 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4179 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004180 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004181 /* but don't bother the driver with it */
4182 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004183
Johannes Bergd582cff2012-10-26 17:53:44 +02004184 /* allow authenticated/associated only if driver handles it */
4185 if (!(rdev->wiphy.features &
4186 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4187 params.sta_flags_mask &
4188 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4189 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4190 return -EINVAL;
4191
Johannes Bergbdd90d52011-12-14 12:20:27 +01004192 /* must be last in here for error handling */
4193 params.vlan = get_vlan(info, rdev);
4194 if (IS_ERR(params.vlan))
4195 return PTR_ERR(params.vlan);
4196 break;
4197 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004198 /* ignore uAPSD data */
4199 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4200
Johannes Bergd582cff2012-10-26 17:53:44 +02004201 /* associated is disallowed */
4202 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4203 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004204 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004205 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4206 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004207 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004208 break;
4209 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004210 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004211 /* ignore uAPSD data */
4212 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4213
Johannes Berg77ee7c82013-02-15 00:48:33 +01004214 /* these are disallowed */
4215 if (params.sta_flags_mask &
4216 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4217 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004218 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004219 /* Only TDLS peers can be added */
4220 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4221 return -EINVAL;
4222 /* Can only add if TDLS ... */
4223 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4224 return -EOPNOTSUPP;
4225 /* ... with external setup is supported */
4226 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4227 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004228 /*
4229 * Older wpa_supplicant versions always mark the TDLS peer
4230 * as authorized, but it shouldn't yet be.
4231 */
4232 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004233 break;
4234 default:
4235 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004236 }
4237
Johannes Bergbdd90d52011-12-14 12:20:27 +01004238 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004239
Hila Gonene35e4d22012-06-27 17:19:42 +03004240 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004241
Johannes Berg5727ef12007-12-19 02:03:34 +01004242 if (params.vlan)
4243 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004244 return err;
4245}
4246
4247static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4248{
Johannes Berg4c476992010-10-04 21:36:35 +02004249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4250 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004251 u8 *mac_addr = NULL;
4252
4253 if (info->attrs[NL80211_ATTR_MAC])
4254 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4255
Johannes Berge80cf852009-05-11 14:43:13 +02004256 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004257 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004258 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004259 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4260 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004261
Johannes Berg4c476992010-10-04 21:36:35 +02004262 if (!rdev->ops->del_station)
4263 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004264
Hila Gonene35e4d22012-06-27 17:19:42 +03004265 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004266}
4267
Eric W. Biederman15e47302012-09-07 20:12:54 +00004268static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004269 int flags, struct net_device *dev,
4270 u8 *dst, u8 *next_hop,
4271 struct mpath_info *pinfo)
4272{
4273 void *hdr;
4274 struct nlattr *pinfoattr;
4275
Eric W. Biederman15e47302012-09-07 20:12:54 +00004276 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004277 if (!hdr)
4278 return -1;
4279
David S. Miller9360ffd2012-03-29 04:41:26 -04004280 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4281 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4282 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4283 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4284 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004285
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004286 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4287 if (!pinfoattr)
4288 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004289 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4290 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4291 pinfo->frame_qlen))
4292 goto nla_put_failure;
4293 if (((pinfo->filled & MPATH_INFO_SN) &&
4294 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4295 ((pinfo->filled & MPATH_INFO_METRIC) &&
4296 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4297 pinfo->metric)) ||
4298 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4299 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4300 pinfo->exptime)) ||
4301 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4302 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4303 pinfo->flags)) ||
4304 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4305 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4306 pinfo->discovery_timeout)) ||
4307 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4308 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4309 pinfo->discovery_retries)))
4310 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004311
4312 nla_nest_end(msg, pinfoattr);
4313
4314 return genlmsg_end(msg, hdr);
4315
4316 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004317 genlmsg_cancel(msg, hdr);
4318 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004319}
4320
4321static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004322 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004323{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004324 struct mpath_info pinfo;
4325 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004326 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004327 u8 dst[ETH_ALEN];
4328 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004329 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004330 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004331
Johannes Berg97990a02013-04-19 01:02:55 +02004332 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004333 if (err)
4334 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004335
4336 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004337 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004338 goto out_err;
4339 }
4340
Johannes Berg97990a02013-04-19 01:02:55 +02004341 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004342 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004343 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004344 }
4345
Johannes Bergbba95fe2008-07-29 13:22:51 +02004346 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004347 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4348 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004349 if (err == -ENOENT)
4350 break;
4351 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004352 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004353
Eric W. Biederman15e47302012-09-07 20:12:54 +00004354 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004355 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004356 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004357 &pinfo) < 0)
4358 goto out;
4359
4360 path_idx++;
4361 }
4362
4363
4364 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004365 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004366 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004367 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004368 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004369 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004370}
4371
4372static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4373{
Johannes Berg4c476992010-10-04 21:36:35 +02004374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004375 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004376 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004377 struct mpath_info pinfo;
4378 struct sk_buff *msg;
4379 u8 *dst = NULL;
4380 u8 next_hop[ETH_ALEN];
4381
4382 memset(&pinfo, 0, sizeof(pinfo));
4383
4384 if (!info->attrs[NL80211_ATTR_MAC])
4385 return -EINVAL;
4386
4387 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4388
Johannes Berg4c476992010-10-04 21:36:35 +02004389 if (!rdev->ops->get_mpath)
4390 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004391
Johannes Berg4c476992010-10-04 21:36:35 +02004392 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4393 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004394
Hila Gonene35e4d22012-06-27 17:19:42 +03004395 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004396 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004397 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004398
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004399 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004401 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004402
Eric W. Biederman15e47302012-09-07 20:12:54 +00004403 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004404 dev, dst, next_hop, &pinfo) < 0) {
4405 nlmsg_free(msg);
4406 return -ENOBUFS;
4407 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004408
Johannes Berg4c476992010-10-04 21:36:35 +02004409 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004410}
4411
4412static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4413{
Johannes Berg4c476992010-10-04 21:36:35 +02004414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4415 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004416 u8 *dst = NULL;
4417 u8 *next_hop = NULL;
4418
4419 if (!info->attrs[NL80211_ATTR_MAC])
4420 return -EINVAL;
4421
4422 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4423 return -EINVAL;
4424
4425 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4426 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4427
Johannes Berg4c476992010-10-04 21:36:35 +02004428 if (!rdev->ops->change_mpath)
4429 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004430
Johannes Berg4c476992010-10-04 21:36:35 +02004431 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4432 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433
Hila Gonene35e4d22012-06-27 17:19:42 +03004434 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004435}
Johannes Berg4c476992010-10-04 21:36:35 +02004436
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004437static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4438{
Johannes Berg4c476992010-10-04 21:36:35 +02004439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4440 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004441 u8 *dst = NULL;
4442 u8 *next_hop = NULL;
4443
4444 if (!info->attrs[NL80211_ATTR_MAC])
4445 return -EINVAL;
4446
4447 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4448 return -EINVAL;
4449
4450 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4451 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4452
Johannes Berg4c476992010-10-04 21:36:35 +02004453 if (!rdev->ops->add_mpath)
4454 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004455
Johannes Berg4c476992010-10-04 21:36:35 +02004456 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4457 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004458
Hila Gonene35e4d22012-06-27 17:19:42 +03004459 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004460}
4461
4462static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4463{
Johannes Berg4c476992010-10-04 21:36:35 +02004464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4465 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004466 u8 *dst = NULL;
4467
4468 if (info->attrs[NL80211_ATTR_MAC])
4469 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4470
Johannes Berg4c476992010-10-04 21:36:35 +02004471 if (!rdev->ops->del_mpath)
4472 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004473
Hila Gonene35e4d22012-06-27 17:19:42 +03004474 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004475}
4476
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004477static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4478{
Johannes Berg4c476992010-10-04 21:36:35 +02004479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4480 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004481 struct bss_parameters params;
4482
4483 memset(&params, 0, sizeof(params));
4484 /* default to not changing parameters */
4485 params.use_cts_prot = -1;
4486 params.use_short_preamble = -1;
4487 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004488 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004489 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004490 params.p2p_ctwindow = -1;
4491 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004492
4493 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4494 params.use_cts_prot =
4495 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4496 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4497 params.use_short_preamble =
4498 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4499 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4500 params.use_short_slot_time =
4501 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004502 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4503 params.basic_rates =
4504 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4505 params.basic_rates_len =
4506 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4507 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004508 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4509 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004510 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4511 params.ht_opmode =
4512 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004513
Johannes Berg53cabad2012-11-14 15:17:28 +01004514 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4515 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4516 return -EINVAL;
4517 params.p2p_ctwindow =
4518 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4519 if (params.p2p_ctwindow < 0)
4520 return -EINVAL;
4521 if (params.p2p_ctwindow != 0 &&
4522 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4523 return -EINVAL;
4524 }
4525
4526 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4527 u8 tmp;
4528
4529 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4530 return -EINVAL;
4531 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4532 if (tmp > 1)
4533 return -EINVAL;
4534 params.p2p_opp_ps = tmp;
4535 if (params.p2p_opp_ps &&
4536 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4537 return -EINVAL;
4538 }
4539
Johannes Berg4c476992010-10-04 21:36:35 +02004540 if (!rdev->ops->change_bss)
4541 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004542
Johannes Berg074ac8d2010-09-16 14:58:22 +02004543 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004544 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4545 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004546
Hila Gonene35e4d22012-06-27 17:19:42 +03004547 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004548}
4549
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004550static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004551 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4552 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4553 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4554 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4555 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4556 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4557};
4558
4559static int parse_reg_rule(struct nlattr *tb[],
4560 struct ieee80211_reg_rule *reg_rule)
4561{
4562 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4563 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4564
4565 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4566 return -EINVAL;
4567 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4568 return -EINVAL;
4569 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4570 return -EINVAL;
4571 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4572 return -EINVAL;
4573 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4574 return -EINVAL;
4575
4576 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4577
4578 freq_range->start_freq_khz =
4579 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4580 freq_range->end_freq_khz =
4581 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4582 freq_range->max_bandwidth_khz =
4583 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4584
4585 power_rule->max_eirp =
4586 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4587
4588 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4589 power_rule->max_antenna_gain =
4590 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4591
4592 return 0;
4593}
4594
4595static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4596{
4597 int r;
4598 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004599 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004600
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004601 /*
4602 * You should only get this when cfg80211 hasn't yet initialized
4603 * completely when built-in to the kernel right between the time
4604 * window between nl80211_init() and regulatory_init(), if that is
4605 * even possible.
4606 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004607 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004608 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004609
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004610 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4611 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004612
4613 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4614
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004615 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4616 user_reg_hint_type =
4617 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4618 else
4619 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4620
4621 switch (user_reg_hint_type) {
4622 case NL80211_USER_REG_HINT_USER:
4623 case NL80211_USER_REG_HINT_CELL_BASE:
4624 break;
4625 default:
4626 return -EINVAL;
4627 }
4628
4629 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004630
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004631 return r;
4632}
4633
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004634static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004635 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004636{
Johannes Berg4c476992010-10-04 21:36:35 +02004637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004638 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004639 struct wireless_dev *wdev = dev->ieee80211_ptr;
4640 struct mesh_config cur_params;
4641 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004642 void *hdr;
4643 struct nlattr *pinfoattr;
4644 struct sk_buff *msg;
4645
Johannes Berg29cbe682010-12-03 09:20:44 +01004646 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4647 return -EOPNOTSUPP;
4648
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004649 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004650 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004651
Johannes Berg29cbe682010-12-03 09:20:44 +01004652 wdev_lock(wdev);
4653 /* If not connected, get default parameters */
4654 if (!wdev->mesh_id_len)
4655 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4656 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004657 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004658 wdev_unlock(wdev);
4659
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004660 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004661 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662
4663 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004665 if (!msg)
4666 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004667 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004668 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004669 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004670 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004671 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004672 if (!pinfoattr)
4673 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004674 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4675 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4676 cur_params.dot11MeshRetryTimeout) ||
4677 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4678 cur_params.dot11MeshConfirmTimeout) ||
4679 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4680 cur_params.dot11MeshHoldingTimeout) ||
4681 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4682 cur_params.dot11MeshMaxPeerLinks) ||
4683 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4684 cur_params.dot11MeshMaxRetries) ||
4685 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4686 cur_params.dot11MeshTTL) ||
4687 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4688 cur_params.element_ttl) ||
4689 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4690 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004691 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4692 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004693 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4694 cur_params.dot11MeshHWMPmaxPREQretries) ||
4695 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4696 cur_params.path_refresh_time) ||
4697 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4698 cur_params.min_discovery_timeout) ||
4699 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4700 cur_params.dot11MeshHWMPactivePathTimeout) ||
4701 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4702 cur_params.dot11MeshHWMPpreqMinInterval) ||
4703 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4704 cur_params.dot11MeshHWMPperrMinInterval) ||
4705 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4706 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4707 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4708 cur_params.dot11MeshHWMPRootMode) ||
4709 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4710 cur_params.dot11MeshHWMPRannInterval) ||
4711 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4712 cur_params.dot11MeshGateAnnouncementProtocol) ||
4713 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4714 cur_params.dot11MeshForwarding) ||
4715 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004716 cur_params.rssi_threshold) ||
4717 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004718 cur_params.ht_opmode) ||
4719 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4720 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4721 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004722 cur_params.dot11MeshHWMProotInterval) ||
4723 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004724 cur_params.dot11MeshHWMPconfirmationInterval) ||
4725 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4726 cur_params.power_mode) ||
4727 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004728 cur_params.dot11MeshAwakeWindowDuration) ||
4729 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4730 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004731 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004732 nla_nest_end(msg, pinfoattr);
4733 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004734 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004735
Johannes Berg3b858752009-03-12 09:55:09 +01004736 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004737 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004738 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004739 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004740 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004741}
4742
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004743static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004744 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4745 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4746 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4747 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4748 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4749 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004750 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004751 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004752 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004753 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4754 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4755 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4756 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4757 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004758 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004759 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004760 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004761 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004762 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004763 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004764 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4765 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004766 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4767 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004768 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004769 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4770 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004771 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004772};
4773
Javier Cardonac80d5452010-12-16 17:37:49 -08004774static const struct nla_policy
4775 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004776 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004777 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4778 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004779 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004780 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004781 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004782 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004783 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004784 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004785};
4786
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004787static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004788 struct mesh_config *cfg,
4789 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004791 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004792 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004793
Marco Porschea54fba2013-01-07 16:04:48 +01004794#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4795do { \
4796 if (tb[attr]) { \
4797 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4798 return -EINVAL; \
4799 cfg->param = fn(tb[attr]); \
4800 mask |= (1 << (attr - 1)); \
4801 } \
4802} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004803
4804
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004805 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004806 return -EINVAL;
4807 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004808 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004809 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004810 return -EINVAL;
4811
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004812 /* This makes sure that there aren't more than 32 mesh config
4813 * parameters (otherwise our bitfield scheme would not work.) */
4814 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4815
4816 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004817 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004818 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4819 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004820 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004821 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4822 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004823 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004824 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4825 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004827 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4828 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004829 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004830 mask, NL80211_MESHCONF_MAX_RETRIES,
4831 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004832 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004833 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004835 mask, NL80211_MESHCONF_ELEMENT_TTL,
4836 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004837 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004838 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4839 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004840 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4841 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004842 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4843 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004844 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004845 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4846 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004847 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004848 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4849 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004851 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4852 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4854 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004855 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4856 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004858 1, 65535, mask,
4859 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004860 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004861 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004862 1, 65535, mask,
4863 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004864 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004865 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004866 dot11MeshHWMPnetDiameterTraversalTime,
4867 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004868 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4869 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4871 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4872 nla_get_u8);
4873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4874 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004875 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004877 dot11MeshGateAnnouncementProtocol, 0, 1,
4878 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004879 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004880 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004881 mask, NL80211_MESHCONF_FORWARDING,
4882 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004883 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004884 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004885 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004886 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004887 mask, NL80211_MESHCONF_HT_OPMODE,
4888 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004889 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004890 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004891 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4892 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004893 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004894 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4895 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004896 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004897 dot11MeshHWMPconfirmationInterval,
4898 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004899 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4900 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004901 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4902 NL80211_MESH_POWER_ACTIVE,
4903 NL80211_MESH_POWER_MAX,
4904 mask, NL80211_MESHCONF_POWER_MODE,
4905 nla_get_u32);
4906 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4907 0, 65535, mask,
4908 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004909 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4910 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4911 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004912 if (mask_out)
4913 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004914
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004915 return 0;
4916
4917#undef FILL_IN_MESH_PARAM_IF_SET
4918}
4919
Javier Cardonac80d5452010-12-16 17:37:49 -08004920static int nl80211_parse_mesh_setup(struct genl_info *info,
4921 struct mesh_setup *setup)
4922{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004924 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4925
4926 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4927 return -EINVAL;
4928 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4929 info->attrs[NL80211_ATTR_MESH_SETUP],
4930 nl80211_mesh_setup_params_policy))
4931 return -EINVAL;
4932
Javier Cardonad299a1f2012-03-31 11:31:33 -07004933 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4934 setup->sync_method =
4935 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4936 IEEE80211_SYNC_METHOD_VENDOR :
4937 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4938
Javier Cardonac80d5452010-12-16 17:37:49 -08004939 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4940 setup->path_sel_proto =
4941 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4942 IEEE80211_PATH_PROTOCOL_VENDOR :
4943 IEEE80211_PATH_PROTOCOL_HWMP;
4944
4945 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4946 setup->path_metric =
4947 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4948 IEEE80211_PATH_METRIC_VENDOR :
4949 IEEE80211_PATH_METRIC_AIRTIME;
4950
Javier Cardona581a8b02011-04-07 15:08:27 -07004951
4952 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004953 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004954 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004955 if (!is_valid_ie_attr(ieattr))
4956 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004957 setup->ie = nla_data(ieattr);
4958 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004959 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004960 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4961 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4962 return -EINVAL;
4963 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004964 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4965 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004966 if (setup->is_secure)
4967 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004968
Colleen Twitty6e16d902013-05-08 11:45:59 -07004969 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4970 if (!setup->user_mpm)
4971 return -EINVAL;
4972 setup->auth_id =
4973 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4974 }
4975
Javier Cardonac80d5452010-12-16 17:37:49 -08004976 return 0;
4977}
4978
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004979static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004980 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004981{
4982 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4983 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004984 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004985 struct mesh_config cfg;
4986 u32 mask;
4987 int err;
4988
Johannes Berg29cbe682010-12-03 09:20:44 +01004989 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4990 return -EOPNOTSUPP;
4991
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004992 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004993 return -EOPNOTSUPP;
4994
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004995 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004996 if (err)
4997 return err;
4998
Johannes Berg29cbe682010-12-03 09:20:44 +01004999 wdev_lock(wdev);
5000 if (!wdev->mesh_id_len)
5001 err = -ENOLINK;
5002
5003 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005004 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005005
5006 wdev_unlock(wdev);
5007
5008 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005009}
5010
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005011static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5012{
Johannes Berg458f4f92012-12-06 15:47:38 +01005013 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005014 struct sk_buff *msg;
5015 void *hdr = NULL;
5016 struct nlattr *nl_reg_rules;
5017 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005018
5019 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005020 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005021
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005022 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005023 if (!msg)
5024 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005025
Eric W. Biederman15e47302012-09-07 20:12:54 +00005026 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005027 NL80211_CMD_GET_REG);
5028 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005029 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005030
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005031 if (reg_last_request_cell_base() &&
5032 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5033 NL80211_USER_REG_HINT_CELL_BASE))
5034 goto nla_put_failure;
5035
Johannes Berg458f4f92012-12-06 15:47:38 +01005036 rcu_read_lock();
5037 regdom = rcu_dereference(cfg80211_regdomain);
5038
5039 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5040 (regdom->dfs_region &&
5041 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5042 goto nla_put_failure_rcu;
5043
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005044 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5045 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005046 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005047
Johannes Berg458f4f92012-12-06 15:47:38 +01005048 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005049 struct nlattr *nl_reg_rule;
5050 const struct ieee80211_reg_rule *reg_rule;
5051 const struct ieee80211_freq_range *freq_range;
5052 const struct ieee80211_power_rule *power_rule;
5053
Johannes Berg458f4f92012-12-06 15:47:38 +01005054 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005055 freq_range = &reg_rule->freq_range;
5056 power_rule = &reg_rule->power_rule;
5057
5058 nl_reg_rule = nla_nest_start(msg, i);
5059 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005060 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005061
David S. Miller9360ffd2012-03-29 04:41:26 -04005062 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5063 reg_rule->flags) ||
5064 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5065 freq_range->start_freq_khz) ||
5066 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5067 freq_range->end_freq_khz) ||
5068 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5069 freq_range->max_bandwidth_khz) ||
5070 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5071 power_rule->max_antenna_gain) ||
5072 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5073 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005074 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005075
5076 nla_nest_end(msg, nl_reg_rule);
5077 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005078 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005079
5080 nla_nest_end(msg, nl_reg_rules);
5081
5082 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005083 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005084
Johannes Berg458f4f92012-12-06 15:47:38 +01005085nla_put_failure_rcu:
5086 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005087nla_put_failure:
5088 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005089put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005090 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005091 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005092}
5093
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005094static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5095{
5096 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5097 struct nlattr *nl_reg_rule;
5098 char *alpha2 = NULL;
5099 int rem_reg_rules = 0, r = 0;
5100 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005101 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005102 struct ieee80211_regdomain *rd = NULL;
5103
5104 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5105 return -EINVAL;
5106
5107 if (!info->attrs[NL80211_ATTR_REG_RULES])
5108 return -EINVAL;
5109
5110 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5111
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005112 if (info->attrs[NL80211_ATTR_DFS_REGION])
5113 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5114
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005115 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005116 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005117 num_rules++;
5118 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005119 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005120 }
5121
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005122 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005123 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005124
5125 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005126 if (!rd)
5127 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005128
5129 rd->n_reg_rules = num_rules;
5130 rd->alpha2[0] = alpha2[0];
5131 rd->alpha2[1] = alpha2[1];
5132
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005133 /*
5134 * Disable DFS master mode if the DFS region was
5135 * not supported or known on this kernel.
5136 */
5137 if (reg_supported_dfs_region(dfs_region))
5138 rd->dfs_region = dfs_region;
5139
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005140 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005141 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005142 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005143 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5144 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005145 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5146 if (r)
5147 goto bad_reg;
5148
5149 rule_idx++;
5150
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005151 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5152 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005153 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005154 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005155 }
5156
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005157 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005158 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005159 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005160
Johannes Bergd2372b32008-10-24 20:32:20 +02005161 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005162 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005163 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005164}
5165
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005166static int validate_scan_freqs(struct nlattr *freqs)
5167{
5168 struct nlattr *attr1, *attr2;
5169 int n_channels = 0, tmp1, tmp2;
5170
5171 nla_for_each_nested(attr1, freqs, tmp1) {
5172 n_channels++;
5173 /*
5174 * Some hardware has a limited channel list for
5175 * scanning, and it is pretty much nonsensical
5176 * to scan for a channel twice, so disallow that
5177 * and don't require drivers to check that the
5178 * channel list they get isn't longer than what
5179 * they can scan, as long as they can scan all
5180 * the channels they registered at once.
5181 */
5182 nla_for_each_nested(attr2, freqs, tmp2)
5183 if (attr1 != attr2 &&
5184 nla_get_u32(attr1) == nla_get_u32(attr2))
5185 return 0;
5186 }
5187
5188 return n_channels;
5189}
5190
Johannes Berg2a519312009-02-10 21:25:55 +01005191static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5192{
Johannes Berg4c476992010-10-04 21:36:35 +02005193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005194 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005195 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005196 struct nlattr *attr;
5197 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005198 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005199 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005200
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005201 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5202 return -EINVAL;
5203
Johannes Berg79c97e92009-07-07 03:56:12 +02005204 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005205
Johannes Berg4c476992010-10-04 21:36:35 +02005206 if (!rdev->ops->scan)
5207 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005208
Johannes Bergf9f47522013-03-19 15:04:07 +01005209 if (rdev->scan_req) {
5210 err = -EBUSY;
5211 goto unlock;
5212 }
Johannes Berg2a519312009-02-10 21:25:55 +01005213
5214 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005215 n_channels = validate_scan_freqs(
5216 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005217 if (!n_channels) {
5218 err = -EINVAL;
5219 goto unlock;
5220 }
Johannes Berg2a519312009-02-10 21:25:55 +01005221 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005222 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005223 n_channels = 0;
5224
Johannes Berg2a519312009-02-10 21:25:55 +01005225 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5226 if (wiphy->bands[band])
5227 n_channels += wiphy->bands[band]->n_channels;
5228 }
5229
5230 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5231 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5232 n_ssids++;
5233
Johannes Bergf9f47522013-03-19 15:04:07 +01005234 if (n_ssids > wiphy->max_scan_ssids) {
5235 err = -EINVAL;
5236 goto unlock;
5237 }
Johannes Berg2a519312009-02-10 21:25:55 +01005238
Jouni Malinen70692ad2009-02-16 19:39:13 +02005239 if (info->attrs[NL80211_ATTR_IE])
5240 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5241 else
5242 ie_len = 0;
5243
Johannes Bergf9f47522013-03-19 15:04:07 +01005244 if (ie_len > wiphy->max_scan_ie_len) {
5245 err = -EINVAL;
5246 goto unlock;
5247 }
Johannes Berg18a83652009-03-31 12:12:05 +02005248
Johannes Berg2a519312009-02-10 21:25:55 +01005249 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005250 + sizeof(*request->ssids) * n_ssids
5251 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005252 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005253 if (!request) {
5254 err = -ENOMEM;
5255 goto unlock;
5256 }
Johannes Berg2a519312009-02-10 21:25:55 +01005257
Johannes Berg2a519312009-02-10 21:25:55 +01005258 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005259 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005260 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005261 if (ie_len) {
5262 if (request->ssids)
5263 request->ie = (void *)(request->ssids + n_ssids);
5264 else
5265 request->ie = (void *)(request->channels + n_channels);
5266 }
Johannes Berg2a519312009-02-10 21:25:55 +01005267
Johannes Berg584991d2009-11-02 13:32:03 +01005268 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005269 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5270 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005271 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005272 struct ieee80211_channel *chan;
5273
5274 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5275
5276 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005277 err = -EINVAL;
5278 goto out_free;
5279 }
Johannes Berg584991d2009-11-02 13:32:03 +01005280
5281 /* ignore disabled channels */
5282 if (chan->flags & IEEE80211_CHAN_DISABLED)
5283 continue;
5284
5285 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005286 i++;
5287 }
5288 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005289 enum ieee80211_band band;
5290
Johannes Berg2a519312009-02-10 21:25:55 +01005291 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005292 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5293 int j;
5294 if (!wiphy->bands[band])
5295 continue;
5296 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005297 struct ieee80211_channel *chan;
5298
5299 chan = &wiphy->bands[band]->channels[j];
5300
5301 if (chan->flags & IEEE80211_CHAN_DISABLED)
5302 continue;
5303
5304 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005305 i++;
5306 }
5307 }
5308 }
5309
Johannes Berg584991d2009-11-02 13:32:03 +01005310 if (!i) {
5311 err = -EINVAL;
5312 goto out_free;
5313 }
5314
5315 request->n_channels = i;
5316
Johannes Berg2a519312009-02-10 21:25:55 +01005317 i = 0;
5318 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5319 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005320 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005321 err = -EINVAL;
5322 goto out_free;
5323 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005324 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005325 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005326 i++;
5327 }
5328 }
5329
Jouni Malinen70692ad2009-02-16 19:39:13 +02005330 if (info->attrs[NL80211_ATTR_IE]) {
5331 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005332 memcpy((void *)request->ie,
5333 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005334 request->ie_len);
5335 }
5336
Johannes Berg34850ab2011-07-18 18:08:35 +02005337 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005338 if (wiphy->bands[i])
5339 request->rates[i] =
5340 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005341
5342 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5343 nla_for_each_nested(attr,
5344 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5345 tmp) {
5346 enum ieee80211_band band = nla_type(attr);
5347
Dan Carpenter84404622011-07-29 11:52:18 +03005348 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005349 err = -EINVAL;
5350 goto out_free;
5351 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005352
5353 if (!wiphy->bands[band])
5354 continue;
5355
Johannes Berg34850ab2011-07-18 18:08:35 +02005356 err = ieee80211_get_ratemask(wiphy->bands[band],
5357 nla_data(attr),
5358 nla_len(attr),
5359 &request->rates[band]);
5360 if (err)
5361 goto out_free;
5362 }
5363 }
5364
Sam Leffler46856bb2012-10-11 21:03:32 -07005365 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005366 request->flags = nla_get_u32(
5367 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005368 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5369 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5370 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5371 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005372 err = -EOPNOTSUPP;
5373 goto out_free;
5374 }
5375 }
Sam Lefflered4737712012-10-11 21:03:31 -07005376
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305377 request->no_cck =
5378 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5379
Johannes Bergfd014282012-06-18 19:17:03 +02005380 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005381 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005382 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005383
Johannes Berg79c97e92009-07-07 03:56:12 +02005384 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005385 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005386
Johannes Berg463d0182009-07-14 00:33:35 +02005387 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005388 nl80211_send_scan_start(rdev, wdev);
5389 if (wdev->netdev)
5390 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005391 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005392 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005393 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005394 kfree(request);
5395 }
Johannes Berg3b858752009-03-12 09:55:09 +01005396
Johannes Bergf9f47522013-03-19 15:04:07 +01005397 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005398 return err;
5399}
5400
Luciano Coelho807f8a82011-05-11 17:09:35 +03005401static int nl80211_start_sched_scan(struct sk_buff *skb,
5402 struct genl_info *info)
5403{
5404 struct cfg80211_sched_scan_request *request;
5405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5406 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005407 struct nlattr *attr;
5408 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005409 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005410 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005411 enum ieee80211_band band;
5412 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005413 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005414
5415 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5416 !rdev->ops->sched_scan_start)
5417 return -EOPNOTSUPP;
5418
5419 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5420 return -EINVAL;
5421
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005422 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5423 return -EINVAL;
5424
5425 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5426 if (interval == 0)
5427 return -EINVAL;
5428
Luciano Coelho807f8a82011-05-11 17:09:35 +03005429 wiphy = &rdev->wiphy;
5430
5431 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5432 n_channels = validate_scan_freqs(
5433 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5434 if (!n_channels)
5435 return -EINVAL;
5436 } else {
5437 n_channels = 0;
5438
5439 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5440 if (wiphy->bands[band])
5441 n_channels += wiphy->bands[band]->n_channels;
5442 }
5443
5444 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5445 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5446 tmp)
5447 n_ssids++;
5448
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005449 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005450 return -EINVAL;
5451
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005452 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5453 nla_for_each_nested(attr,
5454 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5455 tmp)
5456 n_match_sets++;
5457
5458 if (n_match_sets > wiphy->max_match_sets)
5459 return -EINVAL;
5460
Luciano Coelho807f8a82011-05-11 17:09:35 +03005461 if (info->attrs[NL80211_ATTR_IE])
5462 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5463 else
5464 ie_len = 0;
5465
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005466 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005467 return -EINVAL;
5468
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005469 if (rdev->sched_scan_req) {
5470 err = -EINPROGRESS;
5471 goto out;
5472 }
5473
Luciano Coelho807f8a82011-05-11 17:09:35 +03005474 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005475 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005476 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005477 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005478 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005479 if (!request) {
5480 err = -ENOMEM;
5481 goto out;
5482 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005483
5484 if (n_ssids)
5485 request->ssids = (void *)&request->channels[n_channels];
5486 request->n_ssids = n_ssids;
5487 if (ie_len) {
5488 if (request->ssids)
5489 request->ie = (void *)(request->ssids + n_ssids);
5490 else
5491 request->ie = (void *)(request->channels + n_channels);
5492 }
5493
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005494 if (n_match_sets) {
5495 if (request->ie)
5496 request->match_sets = (void *)(request->ie + ie_len);
5497 else if (request->ssids)
5498 request->match_sets =
5499 (void *)(request->ssids + n_ssids);
5500 else
5501 request->match_sets =
5502 (void *)(request->channels + n_channels);
5503 }
5504 request->n_match_sets = n_match_sets;
5505
Luciano Coelho807f8a82011-05-11 17:09:35 +03005506 i = 0;
5507 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5508 /* user specified, bail out if channel not found */
5509 nla_for_each_nested(attr,
5510 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5511 tmp) {
5512 struct ieee80211_channel *chan;
5513
5514 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5515
5516 if (!chan) {
5517 err = -EINVAL;
5518 goto out_free;
5519 }
5520
5521 /* ignore disabled channels */
5522 if (chan->flags & IEEE80211_CHAN_DISABLED)
5523 continue;
5524
5525 request->channels[i] = chan;
5526 i++;
5527 }
5528 } else {
5529 /* all channels */
5530 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5531 int j;
5532 if (!wiphy->bands[band])
5533 continue;
5534 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5535 struct ieee80211_channel *chan;
5536
5537 chan = &wiphy->bands[band]->channels[j];
5538
5539 if (chan->flags & IEEE80211_CHAN_DISABLED)
5540 continue;
5541
5542 request->channels[i] = chan;
5543 i++;
5544 }
5545 }
5546 }
5547
5548 if (!i) {
5549 err = -EINVAL;
5550 goto out_free;
5551 }
5552
5553 request->n_channels = i;
5554
5555 i = 0;
5556 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5557 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5558 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005559 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005560 err = -EINVAL;
5561 goto out_free;
5562 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005563 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005564 memcpy(request->ssids[i].ssid, nla_data(attr),
5565 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005566 i++;
5567 }
5568 }
5569
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005570 i = 0;
5571 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5572 nla_for_each_nested(attr,
5573 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5574 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005575 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005576
5577 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5578 nla_data(attr), nla_len(attr),
5579 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005580 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005581 if (ssid) {
5582 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5583 err = -EINVAL;
5584 goto out_free;
5585 }
5586 memcpy(request->match_sets[i].ssid.ssid,
5587 nla_data(ssid), nla_len(ssid));
5588 request->match_sets[i].ssid.ssid_len =
5589 nla_len(ssid);
5590 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005591 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5592 if (rssi)
5593 request->rssi_thold = nla_get_u32(rssi);
5594 else
5595 request->rssi_thold =
5596 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005597 i++;
5598 }
5599 }
5600
Luciano Coelho807f8a82011-05-11 17:09:35 +03005601 if (info->attrs[NL80211_ATTR_IE]) {
5602 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5603 memcpy((void *)request->ie,
5604 nla_data(info->attrs[NL80211_ATTR_IE]),
5605 request->ie_len);
5606 }
5607
Sam Leffler46856bb2012-10-11 21:03:32 -07005608 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005609 request->flags = nla_get_u32(
5610 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005611 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5612 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5613 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5614 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005615 err = -EOPNOTSUPP;
5616 goto out_free;
5617 }
5618 }
Sam Lefflered4737712012-10-11 21:03:31 -07005619
Luciano Coelho807f8a82011-05-11 17:09:35 +03005620 request->dev = dev;
5621 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005622 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005623 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005624
Hila Gonene35e4d22012-06-27 17:19:42 +03005625 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005626 if (!err) {
5627 rdev->sched_scan_req = request;
5628 nl80211_send_sched_scan(rdev, dev,
5629 NL80211_CMD_START_SCHED_SCAN);
5630 goto out;
5631 }
5632
5633out_free:
5634 kfree(request);
5635out:
5636 return err;
5637}
5638
5639static int nl80211_stop_sched_scan(struct sk_buff *skb,
5640 struct genl_info *info)
5641{
5642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5643
5644 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5645 !rdev->ops->sched_scan_stop)
5646 return -EOPNOTSUPP;
5647
Johannes Berg5fe231e2013-05-08 21:45:15 +02005648 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005649}
5650
Simon Wunderlich04f39042013-02-08 18:16:19 +01005651static int nl80211_start_radar_detection(struct sk_buff *skb,
5652 struct genl_info *info)
5653{
5654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5655 struct net_device *dev = info->user_ptr[1];
5656 struct wireless_dev *wdev = dev->ieee80211_ptr;
5657 struct cfg80211_chan_def chandef;
5658 int err;
5659
5660 err = nl80211_parse_chandef(rdev, info, &chandef);
5661 if (err)
5662 return err;
5663
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005664 if (netif_carrier_ok(dev))
5665 return -EBUSY;
5666
Simon Wunderlich04f39042013-02-08 18:16:19 +01005667 if (wdev->cac_started)
5668 return -EBUSY;
5669
5670 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5671 if (err < 0)
5672 return err;
5673
5674 if (err == 0)
5675 return -EINVAL;
5676
5677 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5678 return -EINVAL;
5679
5680 if (!rdev->ops->start_radar_detection)
5681 return -EOPNOTSUPP;
5682
Simon Wunderlich04f39042013-02-08 18:16:19 +01005683 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5684 chandef.chan, CHAN_MODE_SHARED,
5685 BIT(chandef.width));
5686 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005687 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005688
5689 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5690 if (!err) {
5691 wdev->channel = chandef.chan;
5692 wdev->cac_started = true;
5693 wdev->cac_start_time = jiffies;
5694 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005695 return err;
5696}
5697
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005698static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5699{
5700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5701 struct net_device *dev = info->user_ptr[1];
5702 struct wireless_dev *wdev = dev->ieee80211_ptr;
5703 struct cfg80211_csa_settings params;
5704 /* csa_attrs is defined static to avoid waste of stack size - this
5705 * function is called under RTNL lock, so this should not be a problem.
5706 */
5707 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5708 u8 radar_detect_width = 0;
5709 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005710 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005711
5712 if (!rdev->ops->channel_switch ||
5713 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5714 return -EOPNOTSUPP;
5715
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005716 switch (dev->ieee80211_ptr->iftype) {
5717 case NL80211_IFTYPE_AP:
5718 case NL80211_IFTYPE_P2P_GO:
5719 need_new_beacon = true;
5720
5721 /* useless if AP is not running */
5722 if (!wdev->beacon_interval)
5723 return -EINVAL;
5724 break;
5725 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005726 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005727 break;
5728 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005729 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005730 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005731
5732 memset(&params, 0, sizeof(params));
5733
5734 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5735 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5736 return -EINVAL;
5737
5738 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005739 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005740 return -EINVAL;
5741
5742 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5743
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005744 if (!need_new_beacon)
5745 goto skip_beacons;
5746
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005747 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5748 if (err)
5749 return err;
5750
5751 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5752 info->attrs[NL80211_ATTR_CSA_IES],
5753 nl80211_policy);
5754 if (err)
5755 return err;
5756
5757 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5758 if (err)
5759 return err;
5760
5761 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5762 return -EINVAL;
5763
5764 params.counter_offset_beacon =
5765 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5766 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5767 return -EINVAL;
5768
5769 /* sanity check - counters should be the same */
5770 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5771 params.count)
5772 return -EINVAL;
5773
5774 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5775 params.counter_offset_presp =
5776 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5777 if (params.counter_offset_presp >=
5778 params.beacon_csa.probe_resp_len)
5779 return -EINVAL;
5780
5781 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5782 params.count)
5783 return -EINVAL;
5784 }
5785
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005786skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005787 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5788 if (err)
5789 return err;
5790
5791 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5792 return -EINVAL;
5793
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005794 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005795 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5796 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005797 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5798 &params.chandef);
5799 if (err < 0) {
5800 return err;
5801 } else if (err) {
5802 radar_detect_width = BIT(params.chandef.width);
5803 params.radar_required = true;
5804 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005805 }
5806
5807 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5808 params.chandef.chan,
5809 CHAN_MODE_SHARED,
5810 radar_detect_width);
5811 if (err)
5812 return err;
5813
5814 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5815 params.block_tx = true;
5816
5817 return rdev_channel_switch(rdev, dev, &params);
5818}
5819
Johannes Berg9720bb32011-06-21 09:45:33 +02005820static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5821 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005822 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005823 struct wireless_dev *wdev,
5824 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005825{
Johannes Berg48ab9052009-07-10 18:42:31 +02005826 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005827 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005828 void *hdr;
5829 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005830 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005831
5832 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005833
Eric W. Biederman15e47302012-09-07 20:12:54 +00005834 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005835 NL80211_CMD_NEW_SCAN_RESULTS);
5836 if (!hdr)
5837 return -1;
5838
Johannes Berg9720bb32011-06-21 09:45:33 +02005839 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5840
Johannes Berg97990a02013-04-19 01:02:55 +02005841 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5842 goto nla_put_failure;
5843 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5845 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005846 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5847 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005848
5849 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5850 if (!bss)
5851 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005852 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005853 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005854 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005855
5856 rcu_read_lock();
5857 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005858 if (ies) {
5859 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5860 goto fail_unlock_rcu;
5861 tsf = true;
5862 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5863 ies->len, ies->data))
5864 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005865 }
5866 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005867 if (ies) {
5868 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5869 goto fail_unlock_rcu;
5870 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5871 ies->len, ies->data))
5872 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005873 }
5874 rcu_read_unlock();
5875
David S. Miller9360ffd2012-03-29 04:41:26 -04005876 if (res->beacon_interval &&
5877 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5878 goto nla_put_failure;
5879 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5880 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005881 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005882 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5883 jiffies_to_msecs(jiffies - intbss->ts)))
5884 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005885
Johannes Berg77965c92009-02-18 18:45:06 +01005886 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005887 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005888 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5889 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005890 break;
5891 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005892 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5893 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005894 break;
5895 default:
5896 break;
5897 }
5898
Johannes Berg48ab9052009-07-10 18:42:31 +02005899 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005900 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005901 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005902 if (intbss == wdev->current_bss &&
5903 nla_put_u32(msg, NL80211_BSS_STATUS,
5904 NL80211_BSS_STATUS_ASSOCIATED))
5905 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005906 break;
5907 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005908 if (intbss == wdev->current_bss &&
5909 nla_put_u32(msg, NL80211_BSS_STATUS,
5910 NL80211_BSS_STATUS_IBSS_JOINED))
5911 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005912 break;
5913 default:
5914 break;
5915 }
5916
Johannes Berg2a519312009-02-10 21:25:55 +01005917 nla_nest_end(msg, bss);
5918
5919 return genlmsg_end(msg, hdr);
5920
Johannes Berg8cef2c92013-02-05 16:54:31 +01005921 fail_unlock_rcu:
5922 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005923 nla_put_failure:
5924 genlmsg_cancel(msg, hdr);
5925 return -EMSGSIZE;
5926}
5927
Johannes Berg97990a02013-04-19 01:02:55 +02005928static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005929{
Johannes Berg48ab9052009-07-10 18:42:31 +02005930 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005931 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005932 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005933 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005934 int err;
5935
Johannes Berg97990a02013-04-19 01:02:55 +02005936 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005937 if (err)
5938 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005939
Johannes Berg48ab9052009-07-10 18:42:31 +02005940 wdev_lock(wdev);
5941 spin_lock_bh(&rdev->bss_lock);
5942 cfg80211_bss_expire(rdev);
5943
Johannes Berg9720bb32011-06-21 09:45:33 +02005944 cb->seq = rdev->bss_generation;
5945
Johannes Berg48ab9052009-07-10 18:42:31 +02005946 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005947 if (++idx <= start)
5948 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005949 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005950 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005951 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005952 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005953 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005954 }
5955 }
5956
Johannes Berg48ab9052009-07-10 18:42:31 +02005957 spin_unlock_bh(&rdev->bss_lock);
5958 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005959
Johannes Berg97990a02013-04-19 01:02:55 +02005960 cb->args[2] = idx;
5961 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005962
Johannes Berg67748892010-10-04 21:14:06 +02005963 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005964}
5965
Eric W. Biederman15e47302012-09-07 20:12:54 +00005966static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005967 int flags, struct net_device *dev,
5968 struct survey_info *survey)
5969{
5970 void *hdr;
5971 struct nlattr *infoattr;
5972
Eric W. Biederman15e47302012-09-07 20:12:54 +00005973 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005974 NL80211_CMD_NEW_SURVEY_RESULTS);
5975 if (!hdr)
5976 return -ENOMEM;
5977
David S. Miller9360ffd2012-03-29 04:41:26 -04005978 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5979 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005980
5981 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5982 if (!infoattr)
5983 goto nla_put_failure;
5984
David S. Miller9360ffd2012-03-29 04:41:26 -04005985 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5986 survey->channel->center_freq))
5987 goto nla_put_failure;
5988
5989 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5990 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5991 goto nla_put_failure;
5992 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5993 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5994 goto nla_put_failure;
5995 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5996 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5997 survey->channel_time))
5998 goto nla_put_failure;
5999 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6000 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6001 survey->channel_time_busy))
6002 goto nla_put_failure;
6003 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6004 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6005 survey->channel_time_ext_busy))
6006 goto nla_put_failure;
6007 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6008 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6009 survey->channel_time_rx))
6010 goto nla_put_failure;
6011 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6012 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6013 survey->channel_time_tx))
6014 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006015
6016 nla_nest_end(msg, infoattr);
6017
6018 return genlmsg_end(msg, hdr);
6019
6020 nla_put_failure:
6021 genlmsg_cancel(msg, hdr);
6022 return -EMSGSIZE;
6023}
6024
6025static int nl80211_dump_survey(struct sk_buff *skb,
6026 struct netlink_callback *cb)
6027{
6028 struct survey_info survey;
6029 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006030 struct wireless_dev *wdev;
6031 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006032 int res;
6033
Johannes Berg97990a02013-04-19 01:02:55 +02006034 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006035 if (res)
6036 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006037
Johannes Berg97990a02013-04-19 01:02:55 +02006038 if (!wdev->netdev) {
6039 res = -EINVAL;
6040 goto out_err;
6041 }
6042
Holger Schurig61fa7132009-11-11 12:25:40 +01006043 if (!dev->ops->dump_survey) {
6044 res = -EOPNOTSUPP;
6045 goto out_err;
6046 }
6047
6048 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006049 struct ieee80211_channel *chan;
6050
Johannes Berg97990a02013-04-19 01:02:55 +02006051 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006052 if (res == -ENOENT)
6053 break;
6054 if (res)
6055 goto out_err;
6056
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006057 /* Survey without a channel doesn't make sense */
6058 if (!survey.channel) {
6059 res = -EINVAL;
6060 goto out;
6061 }
6062
6063 chan = ieee80211_get_channel(&dev->wiphy,
6064 survey.channel->center_freq);
6065 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6066 survey_idx++;
6067 continue;
6068 }
6069
Holger Schurig61fa7132009-11-11 12:25:40 +01006070 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006071 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006072 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006073 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006074 goto out;
6075 survey_idx++;
6076 }
6077
6078 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006079 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006080 res = skb->len;
6081 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006082 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006083 return res;
6084}
6085
Samuel Ortizb23aa672009-07-01 21:26:54 +02006086static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6087{
6088 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6089 NL80211_WPA_VERSION_2));
6090}
6091
Jouni Malinen636a5d32009-03-19 13:39:22 +02006092static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6093{
Johannes Berg4c476992010-10-04 21:36:35 +02006094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6095 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006096 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006097 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6098 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006099 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006100 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006101 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006102
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006103 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6104 return -EINVAL;
6105
6106 if (!info->attrs[NL80211_ATTR_MAC])
6107 return -EINVAL;
6108
Jouni Malinen17780922009-03-27 20:52:47 +02006109 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6110 return -EINVAL;
6111
Johannes Berg19957bb2009-07-02 17:20:43 +02006112 if (!info->attrs[NL80211_ATTR_SSID])
6113 return -EINVAL;
6114
6115 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6116 return -EINVAL;
6117
Johannes Bergfffd0932009-07-08 14:22:54 +02006118 err = nl80211_parse_key(info, &key);
6119 if (err)
6120 return err;
6121
6122 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006123 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6124 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006125 if (!key.p.key || !key.p.key_len)
6126 return -EINVAL;
6127 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6128 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6129 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6130 key.p.key_len != WLAN_KEY_LEN_WEP104))
6131 return -EINVAL;
6132 if (key.idx > 4)
6133 return -EINVAL;
6134 } else {
6135 key.p.key_len = 0;
6136 key.p.key = NULL;
6137 }
6138
Johannes Bergafea0b72010-08-10 09:46:42 +02006139 if (key.idx >= 0) {
6140 int i;
6141 bool ok = false;
6142 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6143 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6144 ok = true;
6145 break;
6146 }
6147 }
Johannes Berg4c476992010-10-04 21:36:35 +02006148 if (!ok)
6149 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006150 }
6151
Johannes Berg4c476992010-10-04 21:36:35 +02006152 if (!rdev->ops->auth)
6153 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006154
Johannes Berg074ac8d2010-09-16 14:58:22 +02006155 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006156 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6157 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006158
Johannes Berg19957bb2009-07-02 17:20:43 +02006159 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006160 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006161 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006162 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6163 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006164
Johannes Berg19957bb2009-07-02 17:20:43 +02006165 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6166 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6167
6168 if (info->attrs[NL80211_ATTR_IE]) {
6169 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6170 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6171 }
6172
6173 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006174 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006175 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006176
Jouni Malinene39e5b52012-09-30 19:29:39 +03006177 if (auth_type == NL80211_AUTHTYPE_SAE &&
6178 !info->attrs[NL80211_ATTR_SAE_DATA])
6179 return -EINVAL;
6180
6181 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6182 if (auth_type != NL80211_AUTHTYPE_SAE)
6183 return -EINVAL;
6184 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6185 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6186 /* need to include at least Auth Transaction and Status Code */
6187 if (sae_data_len < 4)
6188 return -EINVAL;
6189 }
6190
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006191 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6192
Johannes Berg95de8172012-01-20 13:55:25 +01006193 /*
6194 * Since we no longer track auth state, ignore
6195 * requests to only change local state.
6196 */
6197 if (local_state_change)
6198 return 0;
6199
Johannes Berg91bf9b22013-05-15 17:44:01 +02006200 wdev_lock(dev->ieee80211_ptr);
6201 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6202 ssid, ssid_len, ie, ie_len,
6203 key.p.key, key.p.key_len, key.idx,
6204 sae_data, sae_data_len);
6205 wdev_unlock(dev->ieee80211_ptr);
6206 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006207}
6208
Johannes Bergc0692b82010-08-27 14:26:53 +03006209static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6210 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006211 struct cfg80211_crypto_settings *settings,
6212 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006213{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006214 memset(settings, 0, sizeof(*settings));
6215
Samuel Ortizb23aa672009-07-01 21:26:54 +02006216 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6217
Johannes Bergc0692b82010-08-27 14:26:53 +03006218 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6219 u16 proto;
6220 proto = nla_get_u16(
6221 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6222 settings->control_port_ethertype = cpu_to_be16(proto);
6223 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6224 proto != ETH_P_PAE)
6225 return -EINVAL;
6226 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6227 settings->control_port_no_encrypt = true;
6228 } else
6229 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6230
Samuel Ortizb23aa672009-07-01 21:26:54 +02006231 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6232 void *data;
6233 int len, i;
6234
6235 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6236 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6237 settings->n_ciphers_pairwise = len / sizeof(u32);
6238
6239 if (len % sizeof(u32))
6240 return -EINVAL;
6241
Johannes Berg3dc27d22009-07-02 21:36:37 +02006242 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006243 return -EINVAL;
6244
6245 memcpy(settings->ciphers_pairwise, data, len);
6246
6247 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006248 if (!cfg80211_supported_cipher_suite(
6249 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006250 settings->ciphers_pairwise[i]))
6251 return -EINVAL;
6252 }
6253
6254 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6255 settings->cipher_group =
6256 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006257 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6258 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006259 return -EINVAL;
6260 }
6261
6262 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6263 settings->wpa_versions =
6264 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6265 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6266 return -EINVAL;
6267 }
6268
6269 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6270 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006271 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006272
6273 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6274 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6275 settings->n_akm_suites = len / sizeof(u32);
6276
6277 if (len % sizeof(u32))
6278 return -EINVAL;
6279
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006280 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6281 return -EINVAL;
6282
Samuel Ortizb23aa672009-07-01 21:26:54 +02006283 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006284 }
6285
6286 return 0;
6287}
6288
Jouni Malinen636a5d32009-03-19 13:39:22 +02006289static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6290{
Johannes Berg4c476992010-10-04 21:36:35 +02006291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6292 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006293 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006294 struct cfg80211_assoc_request req = {};
6295 const u8 *bssid, *ssid;
6296 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006297
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006298 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6299 return -EINVAL;
6300
6301 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006302 !info->attrs[NL80211_ATTR_SSID] ||
6303 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006304 return -EINVAL;
6305
Johannes Berg4c476992010-10-04 21:36:35 +02006306 if (!rdev->ops->assoc)
6307 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006308
Johannes Berg074ac8d2010-09-16 14:58:22 +02006309 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006310 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6311 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006312
Johannes Berg19957bb2009-07-02 17:20:43 +02006313 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006314
Johannes Berg19957bb2009-07-02 17:20:43 +02006315 chan = ieee80211_get_channel(&rdev->wiphy,
6316 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006317 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6318 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006319
Johannes Berg19957bb2009-07-02 17:20:43 +02006320 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6321 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006322
6323 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006324 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6325 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006326 }
6327
Jouni Malinendc6382c2009-05-06 22:09:37 +03006328 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006329 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006330 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006331 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006332 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006333 else if (mfp != NL80211_MFP_NO)
6334 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006335 }
6336
Johannes Berg3e5d7642009-07-07 14:37:26 +02006337 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006338 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006339
Ben Greear7e7c8922011-11-18 11:31:59 -08006340 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006341 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006342
6343 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006344 memcpy(&req.ht_capa_mask,
6345 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6346 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006347
6348 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006349 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006350 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006351 memcpy(&req.ht_capa,
6352 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6353 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006354 }
6355
Johannes Bergee2aca32013-02-21 17:36:01 +01006356 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006357 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006358
6359 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006360 memcpy(&req.vht_capa_mask,
6361 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6362 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006363
6364 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006365 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006366 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006367 memcpy(&req.vht_capa,
6368 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6369 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006370 }
6371
Johannes Bergf62fab72013-02-21 20:09:09 +01006372 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006373 if (!err) {
6374 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006375 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6376 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006377 wdev_unlock(dev->ieee80211_ptr);
6378 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006379
Jouni Malinen636a5d32009-03-19 13:39:22 +02006380 return err;
6381}
6382
6383static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6384{
Johannes Berg4c476992010-10-04 21:36:35 +02006385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6386 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006387 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006388 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006389 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006390 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006391
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006392 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6393 return -EINVAL;
6394
6395 if (!info->attrs[NL80211_ATTR_MAC])
6396 return -EINVAL;
6397
6398 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6399 return -EINVAL;
6400
Johannes Berg4c476992010-10-04 21:36:35 +02006401 if (!rdev->ops->deauth)
6402 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006403
Johannes Berg074ac8d2010-09-16 14:58:22 +02006404 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006405 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6406 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006407
Johannes Berg19957bb2009-07-02 17:20:43 +02006408 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006409
Johannes Berg19957bb2009-07-02 17:20:43 +02006410 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6411 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006412 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006413 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006414 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006415
6416 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006417 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6418 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006419 }
6420
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006421 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6422
Johannes Berg91bf9b22013-05-15 17:44:01 +02006423 wdev_lock(dev->ieee80211_ptr);
6424 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6425 local_state_change);
6426 wdev_unlock(dev->ieee80211_ptr);
6427 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006428}
6429
6430static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6431{
Johannes Berg4c476992010-10-04 21:36:35 +02006432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6433 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006434 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006435 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006436 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006437 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006438
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006439 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6440 return -EINVAL;
6441
6442 if (!info->attrs[NL80211_ATTR_MAC])
6443 return -EINVAL;
6444
6445 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6446 return -EINVAL;
6447
Johannes Berg4c476992010-10-04 21:36:35 +02006448 if (!rdev->ops->disassoc)
6449 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006450
Johannes Berg074ac8d2010-09-16 14:58:22 +02006451 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006452 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6453 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006454
Johannes Berg19957bb2009-07-02 17:20:43 +02006455 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006456
Johannes Berg19957bb2009-07-02 17:20:43 +02006457 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6458 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006459 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006460 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006461 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006462
6463 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006464 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6465 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006466 }
6467
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006468 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6469
Johannes Berg91bf9b22013-05-15 17:44:01 +02006470 wdev_lock(dev->ieee80211_ptr);
6471 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6472 local_state_change);
6473 wdev_unlock(dev->ieee80211_ptr);
6474 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006475}
6476
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006477static bool
6478nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6479 int mcast_rate[IEEE80211_NUM_BANDS],
6480 int rateval)
6481{
6482 struct wiphy *wiphy = &rdev->wiphy;
6483 bool found = false;
6484 int band, i;
6485
6486 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6487 struct ieee80211_supported_band *sband;
6488
6489 sband = wiphy->bands[band];
6490 if (!sband)
6491 continue;
6492
6493 for (i = 0; i < sband->n_bitrates; i++) {
6494 if (sband->bitrates[i].bitrate == rateval) {
6495 mcast_rate[band] = i + 1;
6496 found = true;
6497 break;
6498 }
6499 }
6500 }
6501
6502 return found;
6503}
6504
Johannes Berg04a773a2009-04-19 21:24:32 +02006505static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6506{
Johannes Berg4c476992010-10-04 21:36:35 +02006507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6508 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006509 struct cfg80211_ibss_params ibss;
6510 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006511 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006512 int err;
6513
Johannes Berg8e30bc52009-04-22 17:45:38 +02006514 memset(&ibss, 0, sizeof(ibss));
6515
Johannes Berg04a773a2009-04-19 21:24:32 +02006516 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6517 return -EINVAL;
6518
Johannes Berg683b6d32012-11-08 21:25:48 +01006519 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006520 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6521 return -EINVAL;
6522
Johannes Berg8e30bc52009-04-22 17:45:38 +02006523 ibss.beacon_interval = 100;
6524
6525 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6526 ibss.beacon_interval =
6527 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6528 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6529 return -EINVAL;
6530 }
6531
Johannes Berg4c476992010-10-04 21:36:35 +02006532 if (!rdev->ops->join_ibss)
6533 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006534
Johannes Berg4c476992010-10-04 21:36:35 +02006535 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6536 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006537
Johannes Berg79c97e92009-07-07 03:56:12 +02006538 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006539
Johannes Berg39193492011-09-16 13:45:25 +02006540 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006541 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006542
6543 if (!is_valid_ether_addr(ibss.bssid))
6544 return -EINVAL;
6545 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006546 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6547 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6548
6549 if (info->attrs[NL80211_ATTR_IE]) {
6550 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6551 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6552 }
6553
Johannes Berg683b6d32012-11-08 21:25:48 +01006554 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6555 if (err)
6556 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006557
Johannes Berg683b6d32012-11-08 21:25:48 +01006558 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006559 return -EINVAL;
6560
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006561 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006562 case NL80211_CHAN_WIDTH_5:
6563 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006564 case NL80211_CHAN_WIDTH_20_NOHT:
6565 break;
6566 case NL80211_CHAN_WIDTH_20:
6567 case NL80211_CHAN_WIDTH_40:
6568 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6569 break;
6570 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006571 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006572 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006573
Johannes Berg04a773a2009-04-19 21:24:32 +02006574 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006575 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006576
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006577 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6578 u8 *rates =
6579 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6580 int n_rates =
6581 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6582 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006583 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006584
Johannes Berg34850ab2011-07-18 18:08:35 +02006585 err = ieee80211_get_ratemask(sband, rates, n_rates,
6586 &ibss.basic_rates);
6587 if (err)
6588 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006589 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006590
Simon Wunderlich803768f2013-06-28 10:39:58 +02006591 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6592 memcpy(&ibss.ht_capa_mask,
6593 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6594 sizeof(ibss.ht_capa_mask));
6595
6596 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6597 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6598 return -EINVAL;
6599 memcpy(&ibss.ht_capa,
6600 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6601 sizeof(ibss.ht_capa));
6602 }
6603
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006604 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6605 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6606 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6607 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006608
Johannes Berg4c476992010-10-04 21:36:35 +02006609 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306610 bool no_ht = false;
6611
Johannes Berg4c476992010-10-04 21:36:35 +02006612 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306613 info->attrs[NL80211_ATTR_KEYS],
6614 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006615 if (IS_ERR(connkeys))
6616 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306617
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006618 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6619 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306620 kfree(connkeys);
6621 return -EINVAL;
6622 }
Johannes Berg4c476992010-10-04 21:36:35 +02006623 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006624
Antonio Quartulli267335d2012-01-31 20:25:47 +01006625 ibss.control_port =
6626 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6627
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006628 ibss.userspace_handles_dfs =
6629 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6630
Johannes Berg4c476992010-10-04 21:36:35 +02006631 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006632 if (err)
6633 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006634 return err;
6635}
6636
6637static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6638{
Johannes Berg4c476992010-10-04 21:36:35 +02006639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6640 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006641
Johannes Berg4c476992010-10-04 21:36:35 +02006642 if (!rdev->ops->leave_ibss)
6643 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006644
Johannes Berg4c476992010-10-04 21:36:35 +02006645 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6646 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006647
Johannes Berg4c476992010-10-04 21:36:35 +02006648 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006649}
6650
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006651static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6652{
6653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6654 struct net_device *dev = info->user_ptr[1];
6655 int mcast_rate[IEEE80211_NUM_BANDS];
6656 u32 nla_rate;
6657 int err;
6658
6659 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6660 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6661 return -EOPNOTSUPP;
6662
6663 if (!rdev->ops->set_mcast_rate)
6664 return -EOPNOTSUPP;
6665
6666 memset(mcast_rate, 0, sizeof(mcast_rate));
6667
6668 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6669 return -EINVAL;
6670
6671 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6672 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6673 return -EINVAL;
6674
6675 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6676
6677 return err;
6678}
6679
6680
Johannes Bergaff89a92009-07-01 21:26:51 +02006681#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006682static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6683{
Johannes Berg4c476992010-10-04 21:36:35 +02006684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006685 struct wireless_dev *wdev =
6686 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006687 int err;
6688
David Spinadelfc73f112013-07-31 18:04:15 +03006689 if (!rdev->ops->testmode_cmd)
6690 return -EOPNOTSUPP;
6691
6692 if (IS_ERR(wdev)) {
6693 err = PTR_ERR(wdev);
6694 if (err != -EINVAL)
6695 return err;
6696 wdev = NULL;
6697 } else if (wdev->wiphy != &rdev->wiphy) {
6698 return -EINVAL;
6699 }
6700
Johannes Bergaff89a92009-07-01 21:26:51 +02006701 if (!info->attrs[NL80211_ATTR_TESTDATA])
6702 return -EINVAL;
6703
David Spinadelfc73f112013-07-31 18:04:15 +03006704 rdev->testmode_info = info;
6705 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006706 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6707 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
David Spinadelfc73f112013-07-31 18:04:15 +03006708 rdev->testmode_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006709
Johannes Bergaff89a92009-07-01 21:26:51 +02006710 return err;
6711}
6712
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006713static int nl80211_testmode_dump(struct sk_buff *skb,
6714 struct netlink_callback *cb)
6715{
Johannes Berg00918d32011-12-13 17:22:05 +01006716 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006717 int err;
6718 long phy_idx;
6719 void *data = NULL;
6720 int data_len = 0;
6721
Johannes Berg5fe231e2013-05-08 21:45:15 +02006722 rtnl_lock();
6723
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006724 if (cb->args[0]) {
6725 /*
6726 * 0 is a valid index, but not valid for args[0],
6727 * so we need to offset by 1.
6728 */
6729 phy_idx = cb->args[0] - 1;
6730 } else {
6731 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6732 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6733 nl80211_policy);
6734 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006735 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006736
Johannes Berg2bd7e352012-06-15 14:23:16 +02006737 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6738 nl80211_fam.attrbuf);
6739 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006740 err = PTR_ERR(rdev);
6741 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006742 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006743 phy_idx = rdev->wiphy_idx;
6744 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006745
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006746 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6747 cb->args[1] =
6748 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6749 }
6750
6751 if (cb->args[1]) {
6752 data = nla_data((void *)cb->args[1]);
6753 data_len = nla_len((void *)cb->args[1]);
6754 }
6755
Johannes Berg00918d32011-12-13 17:22:05 +01006756 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6757 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006758 err = -ENOENT;
6759 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006760 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006761
Johannes Berg00918d32011-12-13 17:22:05 +01006762 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006763 err = -EOPNOTSUPP;
6764 goto out_err;
6765 }
6766
6767 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006768 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006769 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6770 NL80211_CMD_TESTMODE);
6771 struct nlattr *tmdata;
6772
Dan Carpentercb35fba2013-08-14 14:50:01 +03006773 if (!hdr)
6774 break;
6775
David S. Miller9360ffd2012-03-29 04:41:26 -04006776 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006777 genlmsg_cancel(skb, hdr);
6778 break;
6779 }
6780
6781 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6782 if (!tmdata) {
6783 genlmsg_cancel(skb, hdr);
6784 break;
6785 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006786 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006787 nla_nest_end(skb, tmdata);
6788
6789 if (err == -ENOBUFS || err == -ENOENT) {
6790 genlmsg_cancel(skb, hdr);
6791 break;
6792 } else if (err) {
6793 genlmsg_cancel(skb, hdr);
6794 goto out_err;
6795 }
6796
6797 genlmsg_end(skb, hdr);
6798 }
6799
6800 err = skb->len;
6801 /* see above */
6802 cb->args[0] = phy_idx + 1;
6803 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006804 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006805 return err;
6806}
6807
Johannes Bergaff89a92009-07-01 21:26:51 +02006808static struct sk_buff *
6809__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006810 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006811{
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
Eric W. Biederman15e47302012-09-07 20:12:54 +00006820 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006821 if (!hdr) {
6822 kfree_skb(skb);
6823 return NULL;
6824 }
6825
David S. Miller9360ffd2012-03-29 04:41:26 -04006826 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6827 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006828 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6829
6830 ((void **)skb->cb)[0] = rdev;
6831 ((void **)skb->cb)[1] = hdr;
6832 ((void **)skb->cb)[2] = data;
6833
6834 return skb;
6835
6836 nla_put_failure:
6837 kfree_skb(skb);
6838 return NULL;
6839}
6840
6841struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6842 int approxlen)
6843{
6844 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6845
6846 if (WARN_ON(!rdev->testmode_info))
6847 return NULL;
6848
6849 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006850 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006851 rdev->testmode_info->snd_seq,
6852 GFP_KERNEL);
6853}
6854EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6855
6856int cfg80211_testmode_reply(struct sk_buff *skb)
6857{
6858 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6859 void *hdr = ((void **)skb->cb)[1];
6860 struct nlattr *data = ((void **)skb->cb)[2];
6861
6862 if (WARN_ON(!rdev->testmode_info)) {
6863 kfree_skb(skb);
6864 return -EINVAL;
6865 }
6866
6867 nla_nest_end(skb, data);
6868 genlmsg_end(skb, hdr);
6869 return genlmsg_reply(skb, rdev->testmode_info);
6870}
6871EXPORT_SYMBOL(cfg80211_testmode_reply);
6872
6873struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6874 int approxlen, gfp_t gfp)
6875{
6876 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6877
6878 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6879}
6880EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6881
6882void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6883{
Michal Kaziora0ec5702013-06-25 09:17:17 +02006884 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006885 void *hdr = ((void **)skb->cb)[1];
6886 struct nlattr *data = ((void **)skb->cb)[2];
6887
6888 nla_nest_end(skb, data);
6889 genlmsg_end(skb, hdr);
Johannes Berg68eb5502013-11-19 15:19:38 +01006890 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01006891 NL80211_MCGRP_TESTMODE, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006892}
6893EXPORT_SYMBOL(cfg80211_testmode_event);
6894#endif
6895
Samuel Ortizb23aa672009-07-01 21:26:54 +02006896static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6897{
Johannes Berg4c476992010-10-04 21:36:35 +02006898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6899 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006900 struct cfg80211_connect_params connect;
6901 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006902 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006903 int err;
6904
6905 memset(&connect, 0, sizeof(connect));
6906
6907 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6908 return -EINVAL;
6909
6910 if (!info->attrs[NL80211_ATTR_SSID] ||
6911 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6912 return -EINVAL;
6913
6914 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6915 connect.auth_type =
6916 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006917 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6918 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006919 return -EINVAL;
6920 } else
6921 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6922
6923 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6924
Johannes Bergc0692b82010-08-27 14:26:53 +03006925 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006926 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006927 if (err)
6928 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006929
Johannes Berg074ac8d2010-09-16 14:58:22 +02006930 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006931 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6932 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006933
Johannes Berg79c97e92009-07-07 03:56:12 +02006934 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006935
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306936 connect.bg_scan_period = -1;
6937 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6938 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6939 connect.bg_scan_period =
6940 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6941 }
6942
Samuel Ortizb23aa672009-07-01 21:26:54 +02006943 if (info->attrs[NL80211_ATTR_MAC])
6944 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6945 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6946 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6947
6948 if (info->attrs[NL80211_ATTR_IE]) {
6949 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6950 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6951 }
6952
Jouni Malinencee00a92013-01-15 17:15:57 +02006953 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6954 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6955 if (connect.mfp != NL80211_MFP_REQUIRED &&
6956 connect.mfp != NL80211_MFP_NO)
6957 return -EINVAL;
6958 } else {
6959 connect.mfp = NL80211_MFP_NO;
6960 }
6961
Samuel Ortizb23aa672009-07-01 21:26:54 +02006962 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6963 connect.channel =
6964 ieee80211_get_channel(wiphy,
6965 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6966 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006967 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6968 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006969 }
6970
Johannes Bergfffd0932009-07-08 14:22:54 +02006971 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6972 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306973 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006974 if (IS_ERR(connkeys))
6975 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006976 }
6977
Ben Greear7e7c8922011-11-18 11:31:59 -08006978 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6979 connect.flags |= ASSOC_REQ_DISABLE_HT;
6980
6981 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6982 memcpy(&connect.ht_capa_mask,
6983 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6984 sizeof(connect.ht_capa_mask));
6985
6986 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006987 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6988 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006989 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006990 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006991 memcpy(&connect.ht_capa,
6992 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6993 sizeof(connect.ht_capa));
6994 }
6995
Johannes Bergee2aca32013-02-21 17:36:01 +01006996 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6997 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6998
6999 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7000 memcpy(&connect.vht_capa_mask,
7001 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7002 sizeof(connect.vht_capa_mask));
7003
7004 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7005 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7006 kfree(connkeys);
7007 return -EINVAL;
7008 }
7009 memcpy(&connect.vht_capa,
7010 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7011 sizeof(connect.vht_capa));
7012 }
7013
Johannes Berg83739b02013-05-15 17:44:01 +02007014 wdev_lock(dev->ieee80211_ptr);
7015 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7016 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007017 if (err)
7018 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007019 return err;
7020}
7021
7022static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7023{
Johannes Berg4c476992010-10-04 21:36:35 +02007024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7025 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007026 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007027 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007028
7029 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7030 reason = WLAN_REASON_DEAUTH_LEAVING;
7031 else
7032 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7033
7034 if (reason == 0)
7035 return -EINVAL;
7036
Johannes Berg074ac8d2010-09-16 14:58:22 +02007037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007038 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7039 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007040
Johannes Berg83739b02013-05-15 17:44:01 +02007041 wdev_lock(dev->ieee80211_ptr);
7042 ret = cfg80211_disconnect(rdev, dev, reason, true);
7043 wdev_unlock(dev->ieee80211_ptr);
7044 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007045}
7046
Johannes Berg463d0182009-07-14 00:33:35 +02007047static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7048{
Johannes Berg4c476992010-10-04 21:36:35 +02007049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007050 struct net *net;
7051 int err;
7052 u32 pid;
7053
7054 if (!info->attrs[NL80211_ATTR_PID])
7055 return -EINVAL;
7056
7057 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7058
Johannes Berg463d0182009-07-14 00:33:35 +02007059 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007060 if (IS_ERR(net))
7061 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007062
7063 err = 0;
7064
7065 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007066 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7067 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007068
Johannes Berg463d0182009-07-14 00:33:35 +02007069 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007070 return err;
7071}
7072
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007073static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7074{
Johannes Berg4c476992010-10-04 21:36:35 +02007075 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007076 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7077 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007078 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007079 struct cfg80211_pmksa pmksa;
7080
7081 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7082
7083 if (!info->attrs[NL80211_ATTR_MAC])
7084 return -EINVAL;
7085
7086 if (!info->attrs[NL80211_ATTR_PMKID])
7087 return -EINVAL;
7088
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007089 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7090 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7091
Johannes Berg074ac8d2010-09-16 14:58:22 +02007092 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007093 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7094 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007095
7096 switch (info->genlhdr->cmd) {
7097 case NL80211_CMD_SET_PMKSA:
7098 rdev_ops = rdev->ops->set_pmksa;
7099 break;
7100 case NL80211_CMD_DEL_PMKSA:
7101 rdev_ops = rdev->ops->del_pmksa;
7102 break;
7103 default:
7104 WARN_ON(1);
7105 break;
7106 }
7107
Johannes Berg4c476992010-10-04 21:36:35 +02007108 if (!rdev_ops)
7109 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007110
Johannes Berg4c476992010-10-04 21:36:35 +02007111 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007112}
7113
7114static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7115{
Johannes Berg4c476992010-10-04 21:36:35 +02007116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7117 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007118
Johannes Berg074ac8d2010-09-16 14:58:22 +02007119 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007120 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7121 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007122
Johannes Berg4c476992010-10-04 21:36:35 +02007123 if (!rdev->ops->flush_pmksa)
7124 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007125
Hila Gonene35e4d22012-06-27 17:19:42 +03007126 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007127}
7128
Arik Nemtsov109086c2011-09-28 14:12:50 +03007129static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7130{
7131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7132 struct net_device *dev = info->user_ptr[1];
7133 u8 action_code, dialog_token;
7134 u16 status_code;
7135 u8 *peer;
7136
7137 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7138 !rdev->ops->tdls_mgmt)
7139 return -EOPNOTSUPP;
7140
7141 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7142 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7143 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7144 !info->attrs[NL80211_ATTR_IE] ||
7145 !info->attrs[NL80211_ATTR_MAC])
7146 return -EINVAL;
7147
7148 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7149 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7150 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7151 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7152
Hila Gonene35e4d22012-06-27 17:19:42 +03007153 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7154 dialog_token, status_code,
7155 nla_data(info->attrs[NL80211_ATTR_IE]),
7156 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007157}
7158
7159static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7160{
7161 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7162 struct net_device *dev = info->user_ptr[1];
7163 enum nl80211_tdls_operation operation;
7164 u8 *peer;
7165
7166 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7167 !rdev->ops->tdls_oper)
7168 return -EOPNOTSUPP;
7169
7170 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7171 !info->attrs[NL80211_ATTR_MAC])
7172 return -EINVAL;
7173
7174 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7175 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7176
Hila Gonene35e4d22012-06-27 17:19:42 +03007177 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007178}
7179
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007180static int nl80211_remain_on_channel(struct sk_buff *skb,
7181 struct genl_info *info)
7182{
Johannes Berg4c476992010-10-04 21:36:35 +02007183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007184 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007185 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007186 struct sk_buff *msg;
7187 void *hdr;
7188 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007189 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007190 int err;
7191
7192 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7193 !info->attrs[NL80211_ATTR_DURATION])
7194 return -EINVAL;
7195
7196 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7197
Johannes Berg7c4ef712011-11-18 15:33:48 +01007198 if (!rdev->ops->remain_on_channel ||
7199 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007200 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007201
Johannes Bergebf348f2012-06-01 12:50:54 +02007202 /*
7203 * We should be on that channel for at least a minimum amount of
7204 * time (10ms) but no longer than the driver supports.
7205 */
7206 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7207 duration > rdev->wiphy.max_remain_on_channel_duration)
7208 return -EINVAL;
7209
Johannes Berg683b6d32012-11-08 21:25:48 +01007210 err = nl80211_parse_chandef(rdev, info, &chandef);
7211 if (err)
7212 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007213
7214 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007215 if (!msg)
7216 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007217
Eric W. Biederman15e47302012-09-07 20:12:54 +00007218 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007219 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007220 if (!hdr) {
7221 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007222 goto free_msg;
7223 }
7224
Johannes Berg683b6d32012-11-08 21:25:48 +01007225 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7226 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007227
7228 if (err)
7229 goto free_msg;
7230
David S. Miller9360ffd2012-03-29 04:41:26 -04007231 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7232 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007233
7234 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007235
7236 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007237
7238 nla_put_failure:
7239 err = -ENOBUFS;
7240 free_msg:
7241 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007242 return err;
7243}
7244
7245static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7246 struct genl_info *info)
7247{
Johannes Berg4c476992010-10-04 21:36:35 +02007248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007249 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007250 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007251
7252 if (!info->attrs[NL80211_ATTR_COOKIE])
7253 return -EINVAL;
7254
Johannes Berg4c476992010-10-04 21:36:35 +02007255 if (!rdev->ops->cancel_remain_on_channel)
7256 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007257
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007258 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7259
Hila Gonene35e4d22012-06-27 17:19:42 +03007260 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007261}
7262
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007263static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7264 u8 *rates, u8 rates_len)
7265{
7266 u8 i;
7267 u32 mask = 0;
7268
7269 for (i = 0; i < rates_len; i++) {
7270 int rate = (rates[i] & 0x7f) * 5;
7271 int ridx;
7272 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7273 struct ieee80211_rate *srate =
7274 &sband->bitrates[ridx];
7275 if (rate == srate->bitrate) {
7276 mask |= 1 << ridx;
7277 break;
7278 }
7279 }
7280 if (ridx == sband->n_bitrates)
7281 return 0; /* rate not found */
7282 }
7283
7284 return mask;
7285}
7286
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007287static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7288 u8 *rates, u8 rates_len,
7289 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7290{
7291 u8 i;
7292
7293 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7294
7295 for (i = 0; i < rates_len; i++) {
7296 int ridx, rbit;
7297
7298 ridx = rates[i] / 8;
7299 rbit = BIT(rates[i] % 8);
7300
7301 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007302 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007303 return false;
7304
7305 /* check availability */
7306 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7307 mcs[ridx] |= rbit;
7308 else
7309 return false;
7310 }
7311
7312 return true;
7313}
7314
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007315static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007316 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7317 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007318 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7319 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007320};
7321
7322static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7323 struct genl_info *info)
7324{
7325 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007327 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007328 int rem, i;
7329 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007330 struct nlattr *tx_rates;
7331 struct ieee80211_supported_band *sband;
7332
7333 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7334 return -EINVAL;
7335
Johannes Berg4c476992010-10-04 21:36:35 +02007336 if (!rdev->ops->set_bitrate_mask)
7337 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007338
7339 memset(&mask, 0, sizeof(mask));
7340 /* Default to all rates enabled */
7341 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7342 sband = rdev->wiphy.bands[i];
7343 mask.control[i].legacy =
7344 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007345 if (sband)
7346 memcpy(mask.control[i].mcs,
7347 sband->ht_cap.mcs.rx_mask,
7348 sizeof(mask.control[i].mcs));
7349 else
7350 memset(mask.control[i].mcs, 0,
7351 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007352 }
7353
7354 /*
7355 * The nested attribute uses enum nl80211_band as the index. This maps
7356 * directly to the enum ieee80211_band values used in cfg80211.
7357 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007358 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007359 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7360 {
7361 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007362 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7363 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007364 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007365 if (sband == NULL)
7366 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007367 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7368 nla_len(tx_rates), nl80211_txattr_policy);
7369 if (tb[NL80211_TXRATE_LEGACY]) {
7370 mask.control[band].legacy = rateset_to_mask(
7371 sband,
7372 nla_data(tb[NL80211_TXRATE_LEGACY]),
7373 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307374 if ((mask.control[band].legacy == 0) &&
7375 nla_len(tb[NL80211_TXRATE_LEGACY]))
7376 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007377 }
7378 if (tb[NL80211_TXRATE_MCS]) {
7379 if (!ht_rateset_to_mask(
7380 sband,
7381 nla_data(tb[NL80211_TXRATE_MCS]),
7382 nla_len(tb[NL80211_TXRATE_MCS]),
7383 mask.control[band].mcs))
7384 return -EINVAL;
7385 }
7386
7387 if (mask.control[band].legacy == 0) {
7388 /* don't allow empty legacy rates if HT
7389 * is not even supported. */
7390 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7391 return -EINVAL;
7392
7393 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7394 if (mask.control[band].mcs[i])
7395 break;
7396
7397 /* legacy and mcs rates may not be both empty */
7398 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007399 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007400 }
7401 }
7402
Hila Gonene35e4d22012-06-27 17:19:42 +03007403 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007404}
7405
Johannes Berg2e161f72010-08-12 15:38:38 +02007406static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007407{
Johannes Berg4c476992010-10-04 21:36:35 +02007408 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007409 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007410 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007411
7412 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7413 return -EINVAL;
7414
Johannes Berg2e161f72010-08-12 15:38:38 +02007415 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7416 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007417
Johannes Berg71bbc992012-06-15 15:30:18 +02007418 switch (wdev->iftype) {
7419 case NL80211_IFTYPE_STATION:
7420 case NL80211_IFTYPE_ADHOC:
7421 case NL80211_IFTYPE_P2P_CLIENT:
7422 case NL80211_IFTYPE_AP:
7423 case NL80211_IFTYPE_AP_VLAN:
7424 case NL80211_IFTYPE_MESH_POINT:
7425 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007426 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007427 break;
7428 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007429 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007430 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007431
7432 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007433 if (!rdev->ops->mgmt_tx)
7434 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007435
Eric W. Biederman15e47302012-09-07 20:12:54 +00007436 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007437 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7438 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007439}
7440
Johannes Berg2e161f72010-08-12 15:38:38 +02007441static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007442{
Johannes Berg4c476992010-10-04 21:36:35 +02007443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007444 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007445 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007446 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007447 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007448 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007449 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007450 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007451 bool offchan, no_cck, dont_wait_for_ack;
7452
7453 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007454
Johannes Berg683b6d32012-11-08 21:25:48 +01007455 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007456 return -EINVAL;
7457
Johannes Berg4c476992010-10-04 21:36:35 +02007458 if (!rdev->ops->mgmt_tx)
7459 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007460
Johannes Berg71bbc992012-06-15 15:30:18 +02007461 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007462 case NL80211_IFTYPE_P2P_DEVICE:
7463 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7464 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007465 case NL80211_IFTYPE_STATION:
7466 case NL80211_IFTYPE_ADHOC:
7467 case NL80211_IFTYPE_P2P_CLIENT:
7468 case NL80211_IFTYPE_AP:
7469 case NL80211_IFTYPE_AP_VLAN:
7470 case NL80211_IFTYPE_MESH_POINT:
7471 case NL80211_IFTYPE_P2P_GO:
7472 break;
7473 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007474 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007475 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007476
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007477 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007478 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007479 return -EINVAL;
7480 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007481
7482 /*
7483 * We should wait on the channel for at least a minimum amount
7484 * of time (10ms) but no longer than the driver supports.
7485 */
7486 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7487 wait > rdev->wiphy.max_remain_on_channel_duration)
7488 return -EINVAL;
7489
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007490 }
7491
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007492 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7493
Johannes Berg7c4ef712011-11-18 15:33:48 +01007494 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7495 return -EINVAL;
7496
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307497 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7498
Antonio Quartulliea141b752013-06-11 14:20:03 +02007499 /* get the channel if any has been specified, otherwise pass NULL to
7500 * the driver. The latter will use the current one
7501 */
7502 chandef.chan = NULL;
7503 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7504 err = nl80211_parse_chandef(rdev, info, &chandef);
7505 if (err)
7506 return err;
7507 }
7508
7509 if (!chandef.chan && offchan)
7510 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007511
Johannes Berge247bd902011-11-04 11:18:21 +01007512 if (!dont_wait_for_ack) {
7513 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7514 if (!msg)
7515 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007516
Eric W. Biederman15e47302012-09-07 20:12:54 +00007517 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007518 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007519 if (!hdr) {
7520 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007521 goto free_msg;
7522 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007523 }
Johannes Berge247bd902011-11-04 11:18:21 +01007524
Johannes Berg683b6d32012-11-08 21:25:48 +01007525 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007526 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7527 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007528 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007529 if (err)
7530 goto free_msg;
7531
Johannes Berge247bd902011-11-04 11:18:21 +01007532 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007533 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7534 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007535
Johannes Berge247bd902011-11-04 11:18:21 +01007536 genlmsg_end(msg, hdr);
7537 return genlmsg_reply(msg, info);
7538 }
7539
7540 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007541
7542 nla_put_failure:
7543 err = -ENOBUFS;
7544 free_msg:
7545 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007546 return err;
7547}
7548
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007549static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7550{
7551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007552 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007553 u64 cookie;
7554
7555 if (!info->attrs[NL80211_ATTR_COOKIE])
7556 return -EINVAL;
7557
7558 if (!rdev->ops->mgmt_tx_cancel_wait)
7559 return -EOPNOTSUPP;
7560
Johannes Berg71bbc992012-06-15 15:30:18 +02007561 switch (wdev->iftype) {
7562 case NL80211_IFTYPE_STATION:
7563 case NL80211_IFTYPE_ADHOC:
7564 case NL80211_IFTYPE_P2P_CLIENT:
7565 case NL80211_IFTYPE_AP:
7566 case NL80211_IFTYPE_AP_VLAN:
7567 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007568 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007569 break;
7570 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007571 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007572 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007573
7574 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7575
Hila Gonene35e4d22012-06-27 17:19:42 +03007576 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007577}
7578
Kalle Valoffb9eb32010-02-17 17:58:10 +02007579static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7580{
Johannes Berg4c476992010-10-04 21:36:35 +02007581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007582 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007583 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007584 u8 ps_state;
7585 bool state;
7586 int err;
7587
Johannes Berg4c476992010-10-04 21:36:35 +02007588 if (!info->attrs[NL80211_ATTR_PS_STATE])
7589 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007590
7591 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7592
Johannes Berg4c476992010-10-04 21:36:35 +02007593 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7594 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007595
7596 wdev = dev->ieee80211_ptr;
7597
Johannes Berg4c476992010-10-04 21:36:35 +02007598 if (!rdev->ops->set_power_mgmt)
7599 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007600
7601 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7602
7603 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007604 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007605
Hila Gonene35e4d22012-06-27 17:19:42 +03007606 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007607 if (!err)
7608 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007609 return err;
7610}
7611
7612static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7613{
Johannes Berg4c476992010-10-04 21:36:35 +02007614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007615 enum nl80211_ps_state ps_state;
7616 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007617 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007618 struct sk_buff *msg;
7619 void *hdr;
7620 int err;
7621
Kalle Valoffb9eb32010-02-17 17:58:10 +02007622 wdev = dev->ieee80211_ptr;
7623
Johannes Berg4c476992010-10-04 21:36:35 +02007624 if (!rdev->ops->set_power_mgmt)
7625 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007626
7627 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007628 if (!msg)
7629 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007630
Eric W. Biederman15e47302012-09-07 20:12:54 +00007631 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007632 NL80211_CMD_GET_POWER_SAVE);
7633 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007634 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007635 goto free_msg;
7636 }
7637
7638 if (wdev->ps)
7639 ps_state = NL80211_PS_ENABLED;
7640 else
7641 ps_state = NL80211_PS_DISABLED;
7642
David S. Miller9360ffd2012-03-29 04:41:26 -04007643 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7644 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007645
7646 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007647 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007648
Johannes Berg4c476992010-10-04 21:36:35 +02007649 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007650 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007651 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007652 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007653 return err;
7654}
7655
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007656static struct nla_policy
7657nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7658 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7659 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7660 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007661 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7662 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7663 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007664};
7665
Thomas Pedersen84f10702012-07-12 16:17:33 -07007666static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007667 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007668{
7669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007670 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007671 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007672
Johannes Bergd9d8b012012-11-26 12:51:52 +01007673 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007674 return -EINVAL;
7675
Thomas Pedersen84f10702012-07-12 16:17:33 -07007676 if (!rdev->ops->set_cqm_txe_config)
7677 return -EOPNOTSUPP;
7678
7679 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7680 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7681 return -EOPNOTSUPP;
7682
Hila Gonene35e4d22012-06-27 17:19:42 +03007683 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007684}
7685
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007686static int nl80211_set_cqm_rssi(struct genl_info *info,
7687 s32 threshold, u32 hysteresis)
7688{
Johannes Berg4c476992010-10-04 21:36:35 +02007689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007690 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007691 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007692
7693 if (threshold > 0)
7694 return -EINVAL;
7695
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007696 /* disabling - hysteresis should also be zero then */
7697 if (threshold == 0)
7698 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007699
Johannes Berg4c476992010-10-04 21:36:35 +02007700 if (!rdev->ops->set_cqm_rssi_config)
7701 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007702
Johannes Berg074ac8d2010-09-16 14:58:22 +02007703 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007704 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7705 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007706
Hila Gonene35e4d22012-06-27 17:19:42 +03007707 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007708}
7709
7710static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7711{
7712 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7713 struct nlattr *cqm;
7714 int err;
7715
7716 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007717 if (!cqm)
7718 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007719
7720 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7721 nl80211_attr_cqm_policy);
7722 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007723 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007724
7725 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7726 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007727 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7728 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007729
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007730 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7731 }
7732
7733 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7734 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7735 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7736 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7737 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7738 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7739
7740 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7741 }
7742
7743 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007744}
7745
Johannes Berg29cbe682010-12-03 09:20:44 +01007746static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7747{
7748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7749 struct net_device *dev = info->user_ptr[1];
7750 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007751 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007752 int err;
7753
7754 /* start with default */
7755 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007756 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007757
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007758 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007759 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007760 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007761 if (err)
7762 return err;
7763 }
7764
7765 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7766 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7767 return -EINVAL;
7768
Javier Cardonac80d5452010-12-16 17:37:49 -08007769 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7770 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7771
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007772 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7773 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7774 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7775 return -EINVAL;
7776
Marco Porsch9bdbf042013-01-07 16:04:51 +01007777 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7778 setup.beacon_interval =
7779 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7780 if (setup.beacon_interval < 10 ||
7781 setup.beacon_interval > 10000)
7782 return -EINVAL;
7783 }
7784
7785 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7786 setup.dtim_period =
7787 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7788 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7789 return -EINVAL;
7790 }
7791
Javier Cardonac80d5452010-12-16 17:37:49 -08007792 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7793 /* parse additional setup parameters if given */
7794 err = nl80211_parse_mesh_setup(info, &setup);
7795 if (err)
7796 return err;
7797 }
7798
Thomas Pedersend37bb182013-03-04 13:06:13 -08007799 if (setup.user_mpm)
7800 cfg.auto_open_plinks = false;
7801
Johannes Bergcc1d2802012-05-16 23:50:20 +02007802 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007803 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7804 if (err)
7805 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007806 } else {
7807 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007808 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007809 }
7810
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007811 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7812 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7813 int n_rates =
7814 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7815 struct ieee80211_supported_band *sband;
7816
7817 if (!setup.chandef.chan)
7818 return -EINVAL;
7819
7820 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7821
7822 err = ieee80211_get_ratemask(sband, rates, n_rates,
7823 &setup.basic_rates);
7824 if (err)
7825 return err;
7826 }
7827
Javier Cardonac80d5452010-12-16 17:37:49 -08007828 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007829}
7830
7831static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7832{
7833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7834 struct net_device *dev = info->user_ptr[1];
7835
7836 return cfg80211_leave_mesh(rdev, dev);
7837}
7838
Johannes Bergdfb89c52012-06-27 09:23:48 +02007839#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007840static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7841 struct cfg80211_registered_device *rdev)
7842{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007843 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007844 struct nlattr *nl_pats, *nl_pat;
7845 int i, pat_len;
7846
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007847 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007848 return 0;
7849
7850 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7851 if (!nl_pats)
7852 return -ENOBUFS;
7853
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007854 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007855 nl_pat = nla_nest_start(msg, i + 1);
7856 if (!nl_pat)
7857 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007858 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007859 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007860 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007861 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7862 wowlan->patterns[i].pattern) ||
7863 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007864 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007865 return -ENOBUFS;
7866 nla_nest_end(msg, nl_pat);
7867 }
7868 nla_nest_end(msg, nl_pats);
7869
7870 return 0;
7871}
7872
Johannes Berg2a0e0472013-01-23 22:57:40 +01007873static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7874 struct cfg80211_wowlan_tcp *tcp)
7875{
7876 struct nlattr *nl_tcp;
7877
7878 if (!tcp)
7879 return 0;
7880
7881 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7882 if (!nl_tcp)
7883 return -ENOBUFS;
7884
7885 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7886 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7887 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7888 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7889 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7890 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7891 tcp->payload_len, tcp->payload) ||
7892 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7893 tcp->data_interval) ||
7894 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7895 tcp->wake_len, tcp->wake_data) ||
7896 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7897 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7898 return -ENOBUFS;
7899
7900 if (tcp->payload_seq.len &&
7901 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7902 sizeof(tcp->payload_seq), &tcp->payload_seq))
7903 return -ENOBUFS;
7904
7905 if (tcp->payload_tok.len &&
7906 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7907 sizeof(tcp->payload_tok) + tcp->tokens_size,
7908 &tcp->payload_tok))
7909 return -ENOBUFS;
7910
Johannes Berge248ad32013-05-16 10:24:28 +02007911 nla_nest_end(msg, nl_tcp);
7912
Johannes Berg2a0e0472013-01-23 22:57:40 +01007913 return 0;
7914}
7915
Johannes Bergff1b6e62011-05-04 15:37:28 +02007916static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7917{
7918 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7919 struct sk_buff *msg;
7920 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007921 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007922
Johannes Berg964dc9e2013-06-03 17:25:34 +02007923 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007924 return -EOPNOTSUPP;
7925
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007926 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007927 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007928 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7929 rdev->wiphy.wowlan_config->tcp->payload_len +
7930 rdev->wiphy.wowlan_config->tcp->wake_len +
7931 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007932 }
7933
7934 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007935 if (!msg)
7936 return -ENOMEM;
7937
Eric W. Biederman15e47302012-09-07 20:12:54 +00007938 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007939 NL80211_CMD_GET_WOWLAN);
7940 if (!hdr)
7941 goto nla_put_failure;
7942
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007943 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007944 struct nlattr *nl_wowlan;
7945
7946 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7947 if (!nl_wowlan)
7948 goto nla_put_failure;
7949
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007950 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007951 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007952 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007953 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007954 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007955 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007956 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007957 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007958 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007960 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007962 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7964 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007965
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007966 if (nl80211_send_wowlan_patterns(msg, rdev))
7967 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007968
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007969 if (nl80211_send_wowlan_tcp(msg,
7970 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007971 goto nla_put_failure;
7972
Johannes Bergff1b6e62011-05-04 15:37:28 +02007973 nla_nest_end(msg, nl_wowlan);
7974 }
7975
7976 genlmsg_end(msg, hdr);
7977 return genlmsg_reply(msg, info);
7978
7979nla_put_failure:
7980 nlmsg_free(msg);
7981 return -ENOBUFS;
7982}
7983
Johannes Berg2a0e0472013-01-23 22:57:40 +01007984static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7985 struct nlattr *attr,
7986 struct cfg80211_wowlan *trig)
7987{
7988 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7989 struct cfg80211_wowlan_tcp *cfg;
7990 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7991 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7992 u32 size;
7993 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7994 int err, port;
7995
Johannes Berg964dc9e2013-06-03 17:25:34 +02007996 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007997 return -EINVAL;
7998
7999 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8000 nla_data(attr), nla_len(attr),
8001 nl80211_wowlan_tcp_policy);
8002 if (err)
8003 return err;
8004
8005 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8006 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8007 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8008 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8009 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8010 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8011 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8012 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8013 return -EINVAL;
8014
8015 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008016 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008017 return -EINVAL;
8018
8019 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008020 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008021 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008022 return -EINVAL;
8023
8024 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008025 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008026 return -EINVAL;
8027
8028 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8029 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8030 return -EINVAL;
8031
8032 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8033 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8034
8035 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8036 tokens_size = tokln - sizeof(*tok);
8037
8038 if (!tok->len || tokens_size % tok->len)
8039 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008040 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008041 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008042 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008043 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008044 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008045 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008046 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008047 return -EINVAL;
8048 if (tok->offset + tok->len > data_size)
8049 return -EINVAL;
8050 }
8051
8052 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8053 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008054 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008055 return -EINVAL;
8056 if (seq->len == 0 || seq->len > 4)
8057 return -EINVAL;
8058 if (seq->len + seq->offset > data_size)
8059 return -EINVAL;
8060 }
8061
8062 size = sizeof(*cfg);
8063 size += data_size;
8064 size += wake_size + wake_mask_size;
8065 size += tokens_size;
8066
8067 cfg = kzalloc(size, GFP_KERNEL);
8068 if (!cfg)
8069 return -ENOMEM;
8070 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8071 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8072 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8073 ETH_ALEN);
8074 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8075 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8076 else
8077 port = 0;
8078#ifdef CONFIG_INET
8079 /* allocate a socket and port for it and use it */
8080 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8081 IPPROTO_TCP, &cfg->sock, 1);
8082 if (err) {
8083 kfree(cfg);
8084 return err;
8085 }
8086 if (inet_csk_get_port(cfg->sock->sk, port)) {
8087 sock_release(cfg->sock);
8088 kfree(cfg);
8089 return -EADDRINUSE;
8090 }
8091 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8092#else
8093 if (!port) {
8094 kfree(cfg);
8095 return -EINVAL;
8096 }
8097 cfg->src_port = port;
8098#endif
8099
8100 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8101 cfg->payload_len = data_size;
8102 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8103 memcpy((void *)cfg->payload,
8104 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8105 data_size);
8106 if (seq)
8107 cfg->payload_seq = *seq;
8108 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8109 cfg->wake_len = wake_size;
8110 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8111 memcpy((void *)cfg->wake_data,
8112 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8113 wake_size);
8114 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8115 data_size + wake_size;
8116 memcpy((void *)cfg->wake_mask,
8117 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8118 wake_mask_size);
8119 if (tok) {
8120 cfg->tokens_size = tokens_size;
8121 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8122 }
8123
8124 trig->tcp = cfg;
8125
8126 return 0;
8127}
8128
Johannes Bergff1b6e62011-05-04 15:37:28 +02008129static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8130{
8131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8132 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008133 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008134 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008135 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008136 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008137 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008138
Johannes Berg964dc9e2013-06-03 17:25:34 +02008139 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008140 return -EOPNOTSUPP;
8141
Johannes Bergae33bd82012-07-12 16:25:02 +02008142 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8143 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008144 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008145 goto set_wakeup;
8146 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008147
8148 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8149 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8150 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8151 nl80211_wowlan_policy);
8152 if (err)
8153 return err;
8154
8155 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8156 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8157 return -EINVAL;
8158 new_triggers.any = true;
8159 }
8160
8161 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8162 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8163 return -EINVAL;
8164 new_triggers.disconnect = true;
8165 }
8166
8167 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8168 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8169 return -EINVAL;
8170 new_triggers.magic_pkt = true;
8171 }
8172
Johannes Berg77dbbb12011-07-13 10:48:55 +02008173 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8174 return -EINVAL;
8175
8176 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8177 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8178 return -EINVAL;
8179 new_triggers.gtk_rekey_failure = true;
8180 }
8181
8182 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8183 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8184 return -EINVAL;
8185 new_triggers.eap_identity_req = true;
8186 }
8187
8188 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8189 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8190 return -EINVAL;
8191 new_triggers.four_way_handshake = true;
8192 }
8193
8194 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8195 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8196 return -EINVAL;
8197 new_triggers.rfkill_release = true;
8198 }
8199
Johannes Bergff1b6e62011-05-04 15:37:28 +02008200 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8201 struct nlattr *pat;
8202 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008203 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008204 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008205
8206 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8207 rem)
8208 n_patterns++;
8209 if (n_patterns > wowlan->n_patterns)
8210 return -EINVAL;
8211
8212 new_triggers.patterns = kcalloc(n_patterns,
8213 sizeof(new_triggers.patterns[0]),
8214 GFP_KERNEL);
8215 if (!new_triggers.patterns)
8216 return -ENOMEM;
8217
8218 new_triggers.n_patterns = n_patterns;
8219 i = 0;
8220
8221 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8222 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008223 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8224 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008225 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008226 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8227 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008228 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008229 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008230 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008231 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008232 goto error;
8233 if (pat_len > wowlan->pattern_max_len ||
8234 pat_len < wowlan->pattern_min_len)
8235 goto error;
8236
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008237 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008238 pkt_offset = 0;
8239 else
8240 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008241 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008242 if (pkt_offset > wowlan->max_pkt_offset)
8243 goto error;
8244 new_triggers.patterns[i].pkt_offset = pkt_offset;
8245
Johannes Bergff1b6e62011-05-04 15:37:28 +02008246 new_triggers.patterns[i].mask =
8247 kmalloc(mask_len + pat_len, GFP_KERNEL);
8248 if (!new_triggers.patterns[i].mask) {
8249 err = -ENOMEM;
8250 goto error;
8251 }
8252 new_triggers.patterns[i].pattern =
8253 new_triggers.patterns[i].mask + mask_len;
8254 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008255 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008256 mask_len);
8257 new_triggers.patterns[i].pattern_len = pat_len;
8258 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008259 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008260 pat_len);
8261 i++;
8262 }
8263 }
8264
Johannes Berg2a0e0472013-01-23 22:57:40 +01008265 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8266 err = nl80211_parse_wowlan_tcp(
8267 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8268 &new_triggers);
8269 if (err)
8270 goto error;
8271 }
8272
Johannes Bergae33bd82012-07-12 16:25:02 +02008273 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8274 if (!ntrig) {
8275 err = -ENOMEM;
8276 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008277 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008278 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008279 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008280
Johannes Bergae33bd82012-07-12 16:25:02 +02008281 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008282 if (rdev->ops->set_wakeup &&
8283 prev_enabled != !!rdev->wiphy.wowlan_config)
8284 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008285
Johannes Bergff1b6e62011-05-04 15:37:28 +02008286 return 0;
8287 error:
8288 for (i = 0; i < new_triggers.n_patterns; i++)
8289 kfree(new_triggers.patterns[i].mask);
8290 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008291 if (new_triggers.tcp && new_triggers.tcp->sock)
8292 sock_release(new_triggers.tcp->sock);
8293 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008294 return err;
8295}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008296#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008297
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008298static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8299 struct cfg80211_registered_device *rdev)
8300{
8301 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8302 int i, j, pat_len;
8303 struct cfg80211_coalesce_rules *rule;
8304
8305 if (!rdev->coalesce->n_rules)
8306 return 0;
8307
8308 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8309 if (!nl_rules)
8310 return -ENOBUFS;
8311
8312 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8313 nl_rule = nla_nest_start(msg, i + 1);
8314 if (!nl_rule)
8315 return -ENOBUFS;
8316
8317 rule = &rdev->coalesce->rules[i];
8318 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8319 rule->delay))
8320 return -ENOBUFS;
8321
8322 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8323 rule->condition))
8324 return -ENOBUFS;
8325
8326 nl_pats = nla_nest_start(msg,
8327 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8328 if (!nl_pats)
8329 return -ENOBUFS;
8330
8331 for (j = 0; j < rule->n_patterns; j++) {
8332 nl_pat = nla_nest_start(msg, j + 1);
8333 if (!nl_pat)
8334 return -ENOBUFS;
8335 pat_len = rule->patterns[j].pattern_len;
8336 if (nla_put(msg, NL80211_PKTPAT_MASK,
8337 DIV_ROUND_UP(pat_len, 8),
8338 rule->patterns[j].mask) ||
8339 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8340 rule->patterns[j].pattern) ||
8341 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8342 rule->patterns[j].pkt_offset))
8343 return -ENOBUFS;
8344 nla_nest_end(msg, nl_pat);
8345 }
8346 nla_nest_end(msg, nl_pats);
8347 nla_nest_end(msg, nl_rule);
8348 }
8349 nla_nest_end(msg, nl_rules);
8350
8351 return 0;
8352}
8353
8354static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8355{
8356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8357 struct sk_buff *msg;
8358 void *hdr;
8359
8360 if (!rdev->wiphy.coalesce)
8361 return -EOPNOTSUPP;
8362
8363 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8364 if (!msg)
8365 return -ENOMEM;
8366
8367 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8368 NL80211_CMD_GET_COALESCE);
8369 if (!hdr)
8370 goto nla_put_failure;
8371
8372 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8373 goto nla_put_failure;
8374
8375 genlmsg_end(msg, hdr);
8376 return genlmsg_reply(msg, info);
8377
8378nla_put_failure:
8379 nlmsg_free(msg);
8380 return -ENOBUFS;
8381}
8382
8383void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8384{
8385 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8386 int i, j;
8387 struct cfg80211_coalesce_rules *rule;
8388
8389 if (!coalesce)
8390 return;
8391
8392 for (i = 0; i < coalesce->n_rules; i++) {
8393 rule = &coalesce->rules[i];
8394 for (j = 0; j < rule->n_patterns; j++)
8395 kfree(rule->patterns[j].mask);
8396 kfree(rule->patterns);
8397 }
8398 kfree(coalesce->rules);
8399 kfree(coalesce);
8400 rdev->coalesce = NULL;
8401}
8402
8403static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8404 struct nlattr *rule,
8405 struct cfg80211_coalesce_rules *new_rule)
8406{
8407 int err, i;
8408 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8409 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8410 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8411 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8412
8413 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8414 nla_len(rule), nl80211_coalesce_policy);
8415 if (err)
8416 return err;
8417
8418 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8419 new_rule->delay =
8420 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8421 if (new_rule->delay > coalesce->max_delay)
8422 return -EINVAL;
8423
8424 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8425 new_rule->condition =
8426 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8427 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8428 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8429 return -EINVAL;
8430
8431 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8432 return -EINVAL;
8433
8434 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8435 rem)
8436 n_patterns++;
8437 if (n_patterns > coalesce->n_patterns)
8438 return -EINVAL;
8439
8440 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8441 GFP_KERNEL);
8442 if (!new_rule->patterns)
8443 return -ENOMEM;
8444
8445 new_rule->n_patterns = n_patterns;
8446 i = 0;
8447
8448 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8449 rem) {
8450 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8451 nla_len(pat), NULL);
8452 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8453 !pat_tb[NL80211_PKTPAT_PATTERN])
8454 return -EINVAL;
8455 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8456 mask_len = DIV_ROUND_UP(pat_len, 8);
8457 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8458 return -EINVAL;
8459 if (pat_len > coalesce->pattern_max_len ||
8460 pat_len < coalesce->pattern_min_len)
8461 return -EINVAL;
8462
8463 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8464 pkt_offset = 0;
8465 else
8466 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8467 if (pkt_offset > coalesce->max_pkt_offset)
8468 return -EINVAL;
8469 new_rule->patterns[i].pkt_offset = pkt_offset;
8470
8471 new_rule->patterns[i].mask =
8472 kmalloc(mask_len + pat_len, GFP_KERNEL);
8473 if (!new_rule->patterns[i].mask)
8474 return -ENOMEM;
8475 new_rule->patterns[i].pattern =
8476 new_rule->patterns[i].mask + mask_len;
8477 memcpy(new_rule->patterns[i].mask,
8478 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8479 new_rule->patterns[i].pattern_len = pat_len;
8480 memcpy(new_rule->patterns[i].pattern,
8481 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8482 i++;
8483 }
8484
8485 return 0;
8486}
8487
8488static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8489{
8490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8491 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8492 struct cfg80211_coalesce new_coalesce = {};
8493 struct cfg80211_coalesce *n_coalesce;
8494 int err, rem_rule, n_rules = 0, i, j;
8495 struct nlattr *rule;
8496 struct cfg80211_coalesce_rules *tmp_rule;
8497
8498 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8499 return -EOPNOTSUPP;
8500
8501 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8502 cfg80211_rdev_free_coalesce(rdev);
8503 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8504 return 0;
8505 }
8506
8507 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8508 rem_rule)
8509 n_rules++;
8510 if (n_rules > coalesce->n_rules)
8511 return -EINVAL;
8512
8513 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8514 GFP_KERNEL);
8515 if (!new_coalesce.rules)
8516 return -ENOMEM;
8517
8518 new_coalesce.n_rules = n_rules;
8519 i = 0;
8520
8521 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8522 rem_rule) {
8523 err = nl80211_parse_coalesce_rule(rdev, rule,
8524 &new_coalesce.rules[i]);
8525 if (err)
8526 goto error;
8527
8528 i++;
8529 }
8530
8531 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8532 if (err)
8533 goto error;
8534
8535 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8536 if (!n_coalesce) {
8537 err = -ENOMEM;
8538 goto error;
8539 }
8540 cfg80211_rdev_free_coalesce(rdev);
8541 rdev->coalesce = n_coalesce;
8542
8543 return 0;
8544error:
8545 for (i = 0; i < new_coalesce.n_rules; i++) {
8546 tmp_rule = &new_coalesce.rules[i];
8547 for (j = 0; j < tmp_rule->n_patterns; j++)
8548 kfree(tmp_rule->patterns[j].mask);
8549 kfree(tmp_rule->patterns);
8550 }
8551 kfree(new_coalesce.rules);
8552
8553 return err;
8554}
8555
Johannes Berge5497d72011-07-05 16:35:40 +02008556static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8557{
8558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8559 struct net_device *dev = info->user_ptr[1];
8560 struct wireless_dev *wdev = dev->ieee80211_ptr;
8561 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8562 struct cfg80211_gtk_rekey_data rekey_data;
8563 int err;
8564
8565 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8566 return -EINVAL;
8567
8568 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8569 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8570 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8571 nl80211_rekey_policy);
8572 if (err)
8573 return err;
8574
8575 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8576 return -ERANGE;
8577 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8578 return -ERANGE;
8579 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8580 return -ERANGE;
8581
8582 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8583 NL80211_KEK_LEN);
8584 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8585 NL80211_KCK_LEN);
8586 memcpy(rekey_data.replay_ctr,
8587 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8588 NL80211_REPLAY_CTR_LEN);
8589
8590 wdev_lock(wdev);
8591 if (!wdev->current_bss) {
8592 err = -ENOTCONN;
8593 goto out;
8594 }
8595
8596 if (!rdev->ops->set_rekey_data) {
8597 err = -EOPNOTSUPP;
8598 goto out;
8599 }
8600
Hila Gonene35e4d22012-06-27 17:19:42 +03008601 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008602 out:
8603 wdev_unlock(wdev);
8604 return err;
8605}
8606
Johannes Berg28946da2011-11-04 11:18:12 +01008607static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8608 struct genl_info *info)
8609{
8610 struct net_device *dev = info->user_ptr[1];
8611 struct wireless_dev *wdev = dev->ieee80211_ptr;
8612
8613 if (wdev->iftype != NL80211_IFTYPE_AP &&
8614 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8615 return -EINVAL;
8616
Eric W. Biederman15e47302012-09-07 20:12:54 +00008617 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008618 return -EBUSY;
8619
Eric W. Biederman15e47302012-09-07 20:12:54 +00008620 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008621 return 0;
8622}
8623
Johannes Berg7f6cf312011-11-04 11:18:15 +01008624static int nl80211_probe_client(struct sk_buff *skb,
8625 struct genl_info *info)
8626{
8627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8628 struct net_device *dev = info->user_ptr[1];
8629 struct wireless_dev *wdev = dev->ieee80211_ptr;
8630 struct sk_buff *msg;
8631 void *hdr;
8632 const u8 *addr;
8633 u64 cookie;
8634 int err;
8635
8636 if (wdev->iftype != NL80211_IFTYPE_AP &&
8637 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8638 return -EOPNOTSUPP;
8639
8640 if (!info->attrs[NL80211_ATTR_MAC])
8641 return -EINVAL;
8642
8643 if (!rdev->ops->probe_client)
8644 return -EOPNOTSUPP;
8645
8646 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8647 if (!msg)
8648 return -ENOMEM;
8649
Eric W. Biederman15e47302012-09-07 20:12:54 +00008650 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008651 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008652 if (!hdr) {
8653 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008654 goto free_msg;
8655 }
8656
8657 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8658
Hila Gonene35e4d22012-06-27 17:19:42 +03008659 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008660 if (err)
8661 goto free_msg;
8662
David S. Miller9360ffd2012-03-29 04:41:26 -04008663 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8664 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008665
8666 genlmsg_end(msg, hdr);
8667
8668 return genlmsg_reply(msg, info);
8669
8670 nla_put_failure:
8671 err = -ENOBUFS;
8672 free_msg:
8673 nlmsg_free(msg);
8674 return err;
8675}
8676
Johannes Berg5e7602302011-11-04 11:18:17 +01008677static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8678{
8679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008680 struct cfg80211_beacon_registration *reg, *nreg;
8681 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008682
8683 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8684 return -EOPNOTSUPP;
8685
Ben Greear37c73b52012-10-26 14:49:25 -07008686 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8687 if (!nreg)
8688 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008689
Ben Greear37c73b52012-10-26 14:49:25 -07008690 /* First, check if already registered. */
8691 spin_lock_bh(&rdev->beacon_registrations_lock);
8692 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8693 if (reg->nlportid == info->snd_portid) {
8694 rv = -EALREADY;
8695 goto out_err;
8696 }
8697 }
8698 /* Add it to the list */
8699 nreg->nlportid = info->snd_portid;
8700 list_add(&nreg->list, &rdev->beacon_registrations);
8701
8702 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008703
8704 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008705out_err:
8706 spin_unlock_bh(&rdev->beacon_registrations_lock);
8707 kfree(nreg);
8708 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008709}
8710
Johannes Berg98104fde2012-06-16 00:19:54 +02008711static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8712{
8713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8714 struct wireless_dev *wdev = info->user_ptr[1];
8715 int err;
8716
8717 if (!rdev->ops->start_p2p_device)
8718 return -EOPNOTSUPP;
8719
8720 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8721 return -EOPNOTSUPP;
8722
8723 if (wdev->p2p_started)
8724 return 0;
8725
Johannes Berg98104fde2012-06-16 00:19:54 +02008726 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008727 if (err)
8728 return err;
8729
Johannes Bergeeb126e2012-10-23 15:16:50 +02008730 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008731 if (err)
8732 return err;
8733
8734 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008735 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008736
8737 return 0;
8738}
8739
8740static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8741{
8742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8743 struct wireless_dev *wdev = info->user_ptr[1];
8744
8745 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8746 return -EOPNOTSUPP;
8747
8748 if (!rdev->ops->stop_p2p_device)
8749 return -EOPNOTSUPP;
8750
Johannes Bergf9f47522013-03-19 15:04:07 +01008751 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008752
8753 return 0;
8754}
8755
Johannes Berg3713b4e2013-02-14 16:19:38 +01008756static int nl80211_get_protocol_features(struct sk_buff *skb,
8757 struct genl_info *info)
8758{
8759 void *hdr;
8760 struct sk_buff *msg;
8761
8762 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8763 if (!msg)
8764 return -ENOMEM;
8765
8766 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8767 NL80211_CMD_GET_PROTOCOL_FEATURES);
8768 if (!hdr)
8769 goto nla_put_failure;
8770
8771 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8772 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8773 goto nla_put_failure;
8774
8775 genlmsg_end(msg, hdr);
8776 return genlmsg_reply(msg, info);
8777
8778 nla_put_failure:
8779 kfree_skb(msg);
8780 return -ENOBUFS;
8781}
8782
Jouni Malinen355199e2013-02-27 17:14:27 +02008783static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8784{
8785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8786 struct cfg80211_update_ft_ies_params ft_params;
8787 struct net_device *dev = info->user_ptr[1];
8788
8789 if (!rdev->ops->update_ft_ies)
8790 return -EOPNOTSUPP;
8791
8792 if (!info->attrs[NL80211_ATTR_MDID] ||
8793 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8794 return -EINVAL;
8795
8796 memset(&ft_params, 0, sizeof(ft_params));
8797 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8798 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8799 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8800
8801 return rdev_update_ft_ies(rdev, dev, &ft_params);
8802}
8803
Arend van Spriel5de17982013-04-18 15:49:00 +02008804static int nl80211_crit_protocol_start(struct sk_buff *skb,
8805 struct genl_info *info)
8806{
8807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8808 struct wireless_dev *wdev = info->user_ptr[1];
8809 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8810 u16 duration;
8811 int ret;
8812
8813 if (!rdev->ops->crit_proto_start)
8814 return -EOPNOTSUPP;
8815
8816 if (WARN_ON(!rdev->ops->crit_proto_stop))
8817 return -EINVAL;
8818
8819 if (rdev->crit_proto_nlportid)
8820 return -EBUSY;
8821
8822 /* determine protocol if provided */
8823 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8824 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8825
8826 if (proto >= NUM_NL80211_CRIT_PROTO)
8827 return -EINVAL;
8828
8829 /* timeout must be provided */
8830 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8831 return -EINVAL;
8832
8833 duration =
8834 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8835
8836 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8837 return -ERANGE;
8838
8839 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8840 if (!ret)
8841 rdev->crit_proto_nlportid = info->snd_portid;
8842
8843 return ret;
8844}
8845
8846static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8847 struct genl_info *info)
8848{
8849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8850 struct wireless_dev *wdev = info->user_ptr[1];
8851
8852 if (!rdev->ops->crit_proto_stop)
8853 return -EOPNOTSUPP;
8854
8855 if (rdev->crit_proto_nlportid) {
8856 rdev->crit_proto_nlportid = 0;
8857 rdev_crit_proto_stop(rdev, wdev);
8858 }
8859 return 0;
8860}
8861
Johannes Berg4c476992010-10-04 21:36:35 +02008862#define NL80211_FLAG_NEED_WIPHY 0x01
8863#define NL80211_FLAG_NEED_NETDEV 0x02
8864#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008865#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8866#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8867 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008868#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008869/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008870#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8871 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008872
Johannes Bergf84f7712013-11-14 17:14:45 +01008873static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02008874 struct genl_info *info)
8875{
8876 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008877 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008878 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008879 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8880
8881 if (rtnl)
8882 rtnl_lock();
8883
8884 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008885 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008886 if (IS_ERR(rdev)) {
8887 if (rtnl)
8888 rtnl_unlock();
8889 return PTR_ERR(rdev);
8890 }
8891 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008892 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8893 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008894 ASSERT_RTNL();
8895
Johannes Berg89a54e42012-06-15 14:33:17 +02008896 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8897 info->attrs);
8898 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008899 if (rtnl)
8900 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008901 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008902 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008903
Johannes Berg89a54e42012-06-15 14:33:17 +02008904 dev = wdev->netdev;
8905 rdev = wiphy_to_dev(wdev->wiphy);
8906
Johannes Berg1bf614e2012-06-15 15:23:36 +02008907 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8908 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008909 if (rtnl)
8910 rtnl_unlock();
8911 return -EINVAL;
8912 }
8913
8914 info->user_ptr[1] = dev;
8915 } else {
8916 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008917 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008918
Johannes Berg1bf614e2012-06-15 15:23:36 +02008919 if (dev) {
8920 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8921 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008922 if (rtnl)
8923 rtnl_unlock();
8924 return -ENETDOWN;
8925 }
8926
8927 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008928 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8929 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008930 if (rtnl)
8931 rtnl_unlock();
8932 return -ENETDOWN;
8933 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008934 }
8935
Johannes Berg4c476992010-10-04 21:36:35 +02008936 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008937 }
8938
8939 return 0;
8940}
8941
Johannes Bergf84f7712013-11-14 17:14:45 +01008942static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02008943 struct genl_info *info)
8944{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008945 if (info->user_ptr[1]) {
8946 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8947 struct wireless_dev *wdev = info->user_ptr[1];
8948
8949 if (wdev->netdev)
8950 dev_put(wdev->netdev);
8951 } else {
8952 dev_put(info->user_ptr[1]);
8953 }
8954 }
Johannes Berg4c476992010-10-04 21:36:35 +02008955 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8956 rtnl_unlock();
8957}
8958
Johannes Berg4534de82013-11-14 17:14:46 +01008959static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04008960 {
8961 .cmd = NL80211_CMD_GET_WIPHY,
8962 .doit = nl80211_get_wiphy,
8963 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008964 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008965 .policy = nl80211_policy,
8966 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008967 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8968 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008969 },
8970 {
8971 .cmd = NL80211_CMD_SET_WIPHY,
8972 .doit = nl80211_set_wiphy,
8973 .policy = nl80211_policy,
8974 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008975 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008976 },
8977 {
8978 .cmd = NL80211_CMD_GET_INTERFACE,
8979 .doit = nl80211_get_interface,
8980 .dumpit = nl80211_dump_interface,
8981 .policy = nl80211_policy,
8982 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008983 .internal_flags = NL80211_FLAG_NEED_WDEV |
8984 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008985 },
8986 {
8987 .cmd = NL80211_CMD_SET_INTERFACE,
8988 .doit = nl80211_set_interface,
8989 .policy = nl80211_policy,
8990 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008991 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8992 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008993 },
8994 {
8995 .cmd = NL80211_CMD_NEW_INTERFACE,
8996 .doit = nl80211_new_interface,
8997 .policy = nl80211_policy,
8998 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008999 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9000 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009001 },
9002 {
9003 .cmd = NL80211_CMD_DEL_INTERFACE,
9004 .doit = nl80211_del_interface,
9005 .policy = nl80211_policy,
9006 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009007 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009008 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009009 },
Johannes Berg41ade002007-12-19 02:03:29 +01009010 {
9011 .cmd = NL80211_CMD_GET_KEY,
9012 .doit = nl80211_get_key,
9013 .policy = nl80211_policy,
9014 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009016 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009017 },
9018 {
9019 .cmd = NL80211_CMD_SET_KEY,
9020 .doit = nl80211_set_key,
9021 .policy = nl80211_policy,
9022 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009024 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009025 },
9026 {
9027 .cmd = NL80211_CMD_NEW_KEY,
9028 .doit = nl80211_new_key,
9029 .policy = nl80211_policy,
9030 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009032 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009033 },
9034 {
9035 .cmd = NL80211_CMD_DEL_KEY,
9036 .doit = nl80211_del_key,
9037 .policy = nl80211_policy,
9038 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009040 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009041 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009042 {
9043 .cmd = NL80211_CMD_SET_BEACON,
9044 .policy = nl80211_policy,
9045 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009046 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009048 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009049 },
9050 {
Johannes Berg88600202012-02-13 15:17:18 +01009051 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009052 .policy = nl80211_policy,
9053 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009054 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009056 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009057 },
9058 {
Johannes Berg88600202012-02-13 15:17:18 +01009059 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009060 .policy = nl80211_policy,
9061 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009062 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009064 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009065 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009066 {
9067 .cmd = NL80211_CMD_GET_STATION,
9068 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009069 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009070 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009071 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9072 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009073 },
9074 {
9075 .cmd = NL80211_CMD_SET_STATION,
9076 .doit = nl80211_set_station,
9077 .policy = nl80211_policy,
9078 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009080 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009081 },
9082 {
9083 .cmd = NL80211_CMD_NEW_STATION,
9084 .doit = nl80211_new_station,
9085 .policy = nl80211_policy,
9086 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009087 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009088 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009089 },
9090 {
9091 .cmd = NL80211_CMD_DEL_STATION,
9092 .doit = nl80211_del_station,
9093 .policy = nl80211_policy,
9094 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009096 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009097 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009098 {
9099 .cmd = NL80211_CMD_GET_MPATH,
9100 .doit = nl80211_get_mpath,
9101 .dumpit = nl80211_dump_mpath,
9102 .policy = nl80211_policy,
9103 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009105 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009106 },
9107 {
9108 .cmd = NL80211_CMD_SET_MPATH,
9109 .doit = nl80211_set_mpath,
9110 .policy = nl80211_policy,
9111 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009112 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009113 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009114 },
9115 {
9116 .cmd = NL80211_CMD_NEW_MPATH,
9117 .doit = nl80211_new_mpath,
9118 .policy = nl80211_policy,
9119 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009120 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009121 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009122 },
9123 {
9124 .cmd = NL80211_CMD_DEL_MPATH,
9125 .doit = nl80211_del_mpath,
9126 .policy = nl80211_policy,
9127 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009128 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009129 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009130 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009131 {
9132 .cmd = NL80211_CMD_SET_BSS,
9133 .doit = nl80211_set_bss,
9134 .policy = nl80211_policy,
9135 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009136 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009137 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009138 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009139 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009140 .cmd = NL80211_CMD_GET_REG,
9141 .doit = nl80211_get_reg,
9142 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009143 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009144 /* can be retrieved by unprivileged users */
9145 },
9146 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009147 .cmd = NL80211_CMD_SET_REG,
9148 .doit = nl80211_set_reg,
9149 .policy = nl80211_policy,
9150 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009151 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009152 },
9153 {
9154 .cmd = NL80211_CMD_REQ_SET_REG,
9155 .doit = nl80211_req_set_reg,
9156 .policy = nl80211_policy,
9157 .flags = GENL_ADMIN_PERM,
9158 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009159 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009160 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9161 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009162 .policy = nl80211_policy,
9163 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009165 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009166 },
9167 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009168 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9169 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009170 .policy = nl80211_policy,
9171 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009173 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009174 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009175 {
Johannes Berg2a519312009-02-10 21:25:55 +01009176 .cmd = NL80211_CMD_TRIGGER_SCAN,
9177 .doit = nl80211_trigger_scan,
9178 .policy = nl80211_policy,
9179 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009180 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009181 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009182 },
9183 {
9184 .cmd = NL80211_CMD_GET_SCAN,
9185 .policy = nl80211_policy,
9186 .dumpit = nl80211_dump_scan,
9187 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009188 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009189 .cmd = NL80211_CMD_START_SCHED_SCAN,
9190 .doit = nl80211_start_sched_scan,
9191 .policy = nl80211_policy,
9192 .flags = GENL_ADMIN_PERM,
9193 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9194 NL80211_FLAG_NEED_RTNL,
9195 },
9196 {
9197 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9198 .doit = nl80211_stop_sched_scan,
9199 .policy = nl80211_policy,
9200 .flags = GENL_ADMIN_PERM,
9201 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9202 NL80211_FLAG_NEED_RTNL,
9203 },
9204 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009205 .cmd = NL80211_CMD_AUTHENTICATE,
9206 .doit = nl80211_authenticate,
9207 .policy = nl80211_policy,
9208 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009209 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009210 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009211 },
9212 {
9213 .cmd = NL80211_CMD_ASSOCIATE,
9214 .doit = nl80211_associate,
9215 .policy = nl80211_policy,
9216 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009218 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009219 },
9220 {
9221 .cmd = NL80211_CMD_DEAUTHENTICATE,
9222 .doit = nl80211_deauthenticate,
9223 .policy = nl80211_policy,
9224 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009225 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009226 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009227 },
9228 {
9229 .cmd = NL80211_CMD_DISASSOCIATE,
9230 .doit = nl80211_disassociate,
9231 .policy = nl80211_policy,
9232 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009234 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009235 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009236 {
9237 .cmd = NL80211_CMD_JOIN_IBSS,
9238 .doit = nl80211_join_ibss,
9239 .policy = nl80211_policy,
9240 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009242 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009243 },
9244 {
9245 .cmd = NL80211_CMD_LEAVE_IBSS,
9246 .doit = nl80211_leave_ibss,
9247 .policy = nl80211_policy,
9248 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009250 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009251 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009252#ifdef CONFIG_NL80211_TESTMODE
9253 {
9254 .cmd = NL80211_CMD_TESTMODE,
9255 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009256 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009257 .policy = nl80211_policy,
9258 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009259 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9260 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009261 },
9262#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009263 {
9264 .cmd = NL80211_CMD_CONNECT,
9265 .doit = nl80211_connect,
9266 .policy = nl80211_policy,
9267 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009268 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009269 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009270 },
9271 {
9272 .cmd = NL80211_CMD_DISCONNECT,
9273 .doit = nl80211_disconnect,
9274 .policy = nl80211_policy,
9275 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009277 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009278 },
Johannes Berg463d0182009-07-14 00:33:35 +02009279 {
9280 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9281 .doit = nl80211_wiphy_netns,
9282 .policy = nl80211_policy,
9283 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009284 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9285 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009286 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009287 {
9288 .cmd = NL80211_CMD_GET_SURVEY,
9289 .policy = nl80211_policy,
9290 .dumpit = nl80211_dump_survey,
9291 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009292 {
9293 .cmd = NL80211_CMD_SET_PMKSA,
9294 .doit = nl80211_setdel_pmksa,
9295 .policy = nl80211_policy,
9296 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009297 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009298 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009299 },
9300 {
9301 .cmd = NL80211_CMD_DEL_PMKSA,
9302 .doit = nl80211_setdel_pmksa,
9303 .policy = nl80211_policy,
9304 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009305 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009306 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009307 },
9308 {
9309 .cmd = NL80211_CMD_FLUSH_PMKSA,
9310 .doit = nl80211_flush_pmksa,
9311 .policy = nl80211_policy,
9312 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009313 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009314 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009315 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009316 {
9317 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9318 .doit = nl80211_remain_on_channel,
9319 .policy = nl80211_policy,
9320 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009321 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009322 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009323 },
9324 {
9325 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9326 .doit = nl80211_cancel_remain_on_channel,
9327 .policy = nl80211_policy,
9328 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009329 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009330 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009331 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009332 {
9333 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9334 .doit = nl80211_set_tx_bitrate_mask,
9335 .policy = nl80211_policy,
9336 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009337 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9338 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009339 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009340 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009341 .cmd = NL80211_CMD_REGISTER_FRAME,
9342 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009343 .policy = nl80211_policy,
9344 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009345 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009346 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009347 },
9348 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009349 .cmd = NL80211_CMD_FRAME,
9350 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009351 .policy = nl80211_policy,
9352 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009353 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009354 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009355 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009356 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009357 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9358 .doit = nl80211_tx_mgmt_cancel_wait,
9359 .policy = nl80211_policy,
9360 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009361 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009362 NL80211_FLAG_NEED_RTNL,
9363 },
9364 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009365 .cmd = NL80211_CMD_SET_POWER_SAVE,
9366 .doit = nl80211_set_power_save,
9367 .policy = nl80211_policy,
9368 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009369 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9370 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009371 },
9372 {
9373 .cmd = NL80211_CMD_GET_POWER_SAVE,
9374 .doit = nl80211_get_power_save,
9375 .policy = nl80211_policy,
9376 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009377 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9378 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009379 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009380 {
9381 .cmd = NL80211_CMD_SET_CQM,
9382 .doit = nl80211_set_cqm,
9383 .policy = nl80211_policy,
9384 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009385 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9386 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009387 },
Johannes Bergf444de02010-05-05 15:25:02 +02009388 {
9389 .cmd = NL80211_CMD_SET_CHANNEL,
9390 .doit = nl80211_set_channel,
9391 .policy = nl80211_policy,
9392 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009393 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9394 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009395 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009396 {
9397 .cmd = NL80211_CMD_SET_WDS_PEER,
9398 .doit = nl80211_set_wds_peer,
9399 .policy = nl80211_policy,
9400 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009401 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9402 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009403 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009404 {
9405 .cmd = NL80211_CMD_JOIN_MESH,
9406 .doit = nl80211_join_mesh,
9407 .policy = nl80211_policy,
9408 .flags = GENL_ADMIN_PERM,
9409 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9410 NL80211_FLAG_NEED_RTNL,
9411 },
9412 {
9413 .cmd = NL80211_CMD_LEAVE_MESH,
9414 .doit = nl80211_leave_mesh,
9415 .policy = nl80211_policy,
9416 .flags = GENL_ADMIN_PERM,
9417 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9418 NL80211_FLAG_NEED_RTNL,
9419 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009420#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009421 {
9422 .cmd = NL80211_CMD_GET_WOWLAN,
9423 .doit = nl80211_get_wowlan,
9424 .policy = nl80211_policy,
9425 /* can be retrieved by unprivileged users */
9426 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9427 NL80211_FLAG_NEED_RTNL,
9428 },
9429 {
9430 .cmd = NL80211_CMD_SET_WOWLAN,
9431 .doit = nl80211_set_wowlan,
9432 .policy = nl80211_policy,
9433 .flags = GENL_ADMIN_PERM,
9434 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9435 NL80211_FLAG_NEED_RTNL,
9436 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009437#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009438 {
9439 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9440 .doit = nl80211_set_rekey_data,
9441 .policy = nl80211_policy,
9442 .flags = GENL_ADMIN_PERM,
9443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9444 NL80211_FLAG_NEED_RTNL,
9445 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009446 {
9447 .cmd = NL80211_CMD_TDLS_MGMT,
9448 .doit = nl80211_tdls_mgmt,
9449 .policy = nl80211_policy,
9450 .flags = GENL_ADMIN_PERM,
9451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9452 NL80211_FLAG_NEED_RTNL,
9453 },
9454 {
9455 .cmd = NL80211_CMD_TDLS_OPER,
9456 .doit = nl80211_tdls_oper,
9457 .policy = nl80211_policy,
9458 .flags = GENL_ADMIN_PERM,
9459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9460 NL80211_FLAG_NEED_RTNL,
9461 },
Johannes Berg28946da2011-11-04 11:18:12 +01009462 {
9463 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9464 .doit = nl80211_register_unexpected_frame,
9465 .policy = nl80211_policy,
9466 .flags = GENL_ADMIN_PERM,
9467 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9468 NL80211_FLAG_NEED_RTNL,
9469 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009470 {
9471 .cmd = NL80211_CMD_PROBE_CLIENT,
9472 .doit = nl80211_probe_client,
9473 .policy = nl80211_policy,
9474 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009475 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009476 NL80211_FLAG_NEED_RTNL,
9477 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009478 {
9479 .cmd = NL80211_CMD_REGISTER_BEACONS,
9480 .doit = nl80211_register_beacons,
9481 .policy = nl80211_policy,
9482 .flags = GENL_ADMIN_PERM,
9483 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9484 NL80211_FLAG_NEED_RTNL,
9485 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009486 {
9487 .cmd = NL80211_CMD_SET_NOACK_MAP,
9488 .doit = nl80211_set_noack_map,
9489 .policy = nl80211_policy,
9490 .flags = GENL_ADMIN_PERM,
9491 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9492 NL80211_FLAG_NEED_RTNL,
9493 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009494 {
9495 .cmd = NL80211_CMD_START_P2P_DEVICE,
9496 .doit = nl80211_start_p2p_device,
9497 .policy = nl80211_policy,
9498 .flags = GENL_ADMIN_PERM,
9499 .internal_flags = NL80211_FLAG_NEED_WDEV |
9500 NL80211_FLAG_NEED_RTNL,
9501 },
9502 {
9503 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9504 .doit = nl80211_stop_p2p_device,
9505 .policy = nl80211_policy,
9506 .flags = GENL_ADMIN_PERM,
9507 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9508 NL80211_FLAG_NEED_RTNL,
9509 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009510 {
9511 .cmd = NL80211_CMD_SET_MCAST_RATE,
9512 .doit = nl80211_set_mcast_rate,
9513 .policy = nl80211_policy,
9514 .flags = GENL_ADMIN_PERM,
9515 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9516 NL80211_FLAG_NEED_RTNL,
9517 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309518 {
9519 .cmd = NL80211_CMD_SET_MAC_ACL,
9520 .doit = nl80211_set_mac_acl,
9521 .policy = nl80211_policy,
9522 .flags = GENL_ADMIN_PERM,
9523 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9524 NL80211_FLAG_NEED_RTNL,
9525 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009526 {
9527 .cmd = NL80211_CMD_RADAR_DETECT,
9528 .doit = nl80211_start_radar_detection,
9529 .policy = nl80211_policy,
9530 .flags = GENL_ADMIN_PERM,
9531 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9532 NL80211_FLAG_NEED_RTNL,
9533 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009534 {
9535 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9536 .doit = nl80211_get_protocol_features,
9537 .policy = nl80211_policy,
9538 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009539 {
9540 .cmd = NL80211_CMD_UPDATE_FT_IES,
9541 .doit = nl80211_update_ft_ies,
9542 .policy = nl80211_policy,
9543 .flags = GENL_ADMIN_PERM,
9544 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9545 NL80211_FLAG_NEED_RTNL,
9546 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009547 {
9548 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9549 .doit = nl80211_crit_protocol_start,
9550 .policy = nl80211_policy,
9551 .flags = GENL_ADMIN_PERM,
9552 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9553 NL80211_FLAG_NEED_RTNL,
9554 },
9555 {
9556 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9557 .doit = nl80211_crit_protocol_stop,
9558 .policy = nl80211_policy,
9559 .flags = GENL_ADMIN_PERM,
9560 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9561 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009562 },
9563 {
9564 .cmd = NL80211_CMD_GET_COALESCE,
9565 .doit = nl80211_get_coalesce,
9566 .policy = nl80211_policy,
9567 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9568 NL80211_FLAG_NEED_RTNL,
9569 },
9570 {
9571 .cmd = NL80211_CMD_SET_COALESCE,
9572 .doit = nl80211_set_coalesce,
9573 .policy = nl80211_policy,
9574 .flags = GENL_ADMIN_PERM,
9575 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9576 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009577 },
9578 {
9579 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9580 .doit = nl80211_channel_switch,
9581 .policy = nl80211_policy,
9582 .flags = GENL_ADMIN_PERM,
9583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9584 NL80211_FLAG_NEED_RTNL,
9585 },
Johannes Berg55682962007-09-20 13:09:35 -04009586};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009587
Johannes Berg55682962007-09-20 13:09:35 -04009588/* notification functions */
9589
9590void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9591{
9592 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009593 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009594
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009596 if (!msg)
9597 return;
9598
Johannes Berg86e8cf92013-06-19 10:57:22 +02009599 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009600 nlmsg_free(msg);
9601 return;
9602 }
9603
Johannes Berg68eb5502013-11-19 15:19:38 +01009604 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009605 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009606}
9607
Johannes Berg362a4152009-05-24 16:43:15 +02009608static int nl80211_add_scan_req(struct sk_buff *msg,
9609 struct cfg80211_registered_device *rdev)
9610{
9611 struct cfg80211_scan_request *req = rdev->scan_req;
9612 struct nlattr *nest;
9613 int i;
9614
9615 if (WARN_ON(!req))
9616 return 0;
9617
9618 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9619 if (!nest)
9620 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009621 for (i = 0; i < req->n_ssids; i++) {
9622 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9623 goto nla_put_failure;
9624 }
Johannes Berg362a4152009-05-24 16:43:15 +02009625 nla_nest_end(msg, nest);
9626
9627 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9628 if (!nest)
9629 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009630 for (i = 0; i < req->n_channels; i++) {
9631 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9632 goto nla_put_failure;
9633 }
Johannes Berg362a4152009-05-24 16:43:15 +02009634 nla_nest_end(msg, nest);
9635
David S. Miller9360ffd2012-03-29 04:41:26 -04009636 if (req->ie &&
9637 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9638 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009639
Johannes Bergae917c92013-10-25 11:05:22 +02009640 if (req->flags &&
9641 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
9642 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -07009643
Johannes Berg362a4152009-05-24 16:43:15 +02009644 return 0;
9645 nla_put_failure:
9646 return -ENOBUFS;
9647}
9648
Johannes Berga538e2d2009-06-16 19:56:42 +02009649static int nl80211_send_scan_msg(struct sk_buff *msg,
9650 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009651 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009652 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009653 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009654{
9655 void *hdr;
9656
Eric W. Biederman15e47302012-09-07 20:12:54 +00009657 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009658 if (!hdr)
9659 return -1;
9660
David S. Miller9360ffd2012-03-29 04:41:26 -04009661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009662 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9663 wdev->netdev->ifindex)) ||
9664 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009665 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009666
Johannes Berg362a4152009-05-24 16:43:15 +02009667 /* ignore errors and send incomplete event anyway */
9668 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009669
9670 return genlmsg_end(msg, hdr);
9671
9672 nla_put_failure:
9673 genlmsg_cancel(msg, hdr);
9674 return -EMSGSIZE;
9675}
9676
Luciano Coelho807f8a82011-05-11 17:09:35 +03009677static int
9678nl80211_send_sched_scan_msg(struct sk_buff *msg,
9679 struct cfg80211_registered_device *rdev,
9680 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009681 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009682{
9683 void *hdr;
9684
Eric W. Biederman15e47302012-09-07 20:12:54 +00009685 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009686 if (!hdr)
9687 return -1;
9688
David S. Miller9360ffd2012-03-29 04:41:26 -04009689 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9690 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9691 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009692
9693 return genlmsg_end(msg, hdr);
9694
9695 nla_put_failure:
9696 genlmsg_cancel(msg, hdr);
9697 return -EMSGSIZE;
9698}
9699
Johannes Berga538e2d2009-06-16 19:56:42 +02009700void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009701 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009702{
9703 struct sk_buff *msg;
9704
Thomas Graf58050fc2012-06-28 03:57:45 +00009705 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009706 if (!msg)
9707 return;
9708
Johannes Bergfd014282012-06-18 19:17:03 +02009709 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009710 NL80211_CMD_TRIGGER_SCAN) < 0) {
9711 nlmsg_free(msg);
9712 return;
9713 }
9714
Johannes Berg68eb5502013-11-19 15:19:38 +01009715 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009716 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009717}
9718
Johannes Berg2a519312009-02-10 21:25:55 +01009719void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009720 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009721{
9722 struct sk_buff *msg;
9723
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009725 if (!msg)
9726 return;
9727
Johannes Bergfd014282012-06-18 19:17:03 +02009728 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009729 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009730 nlmsg_free(msg);
9731 return;
9732 }
9733
Johannes Berg68eb5502013-11-19 15:19:38 +01009734 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009735 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009736}
9737
9738void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009739 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009740{
9741 struct sk_buff *msg;
9742
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009743 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009744 if (!msg)
9745 return;
9746
Johannes Bergfd014282012-06-18 19:17:03 +02009747 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009748 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009749 nlmsg_free(msg);
9750 return;
9751 }
9752
Johannes Berg68eb5502013-11-19 15:19:38 +01009753 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009754 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009755}
9756
Luciano Coelho807f8a82011-05-11 17:09:35 +03009757void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9758 struct net_device *netdev)
9759{
9760 struct sk_buff *msg;
9761
9762 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9763 if (!msg)
9764 return;
9765
9766 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9767 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9768 nlmsg_free(msg);
9769 return;
9770 }
9771
Johannes Berg68eb5502013-11-19 15:19:38 +01009772 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009773 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009774}
9775
9776void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9777 struct net_device *netdev, u32 cmd)
9778{
9779 struct sk_buff *msg;
9780
Thomas Graf58050fc2012-06-28 03:57:45 +00009781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009782 if (!msg)
9783 return;
9784
9785 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9786 nlmsg_free(msg);
9787 return;
9788 }
9789
Johannes Berg68eb5502013-11-19 15:19:38 +01009790 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009791 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009792}
9793
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009794/*
9795 * This can happen on global regulatory changes or device specific settings
9796 * based on custom world regulatory domains.
9797 */
9798void nl80211_send_reg_change_event(struct regulatory_request *request)
9799{
9800 struct sk_buff *msg;
9801 void *hdr;
9802
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009804 if (!msg)
9805 return;
9806
9807 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9808 if (!hdr) {
9809 nlmsg_free(msg);
9810 return;
9811 }
9812
9813 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009814 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9815 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009816
David S. Miller9360ffd2012-03-29 04:41:26 -04009817 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9818 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9819 NL80211_REGDOM_TYPE_WORLD))
9820 goto nla_put_failure;
9821 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9822 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9823 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9824 goto nla_put_failure;
9825 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9826 request->intersect) {
9827 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9828 NL80211_REGDOM_TYPE_INTERSECTION))
9829 goto nla_put_failure;
9830 } else {
9831 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9832 NL80211_REGDOM_TYPE_COUNTRY) ||
9833 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9834 request->alpha2))
9835 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009836 }
9837
Johannes Bergf4173762012-12-03 18:23:37 +01009838 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009839 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9840 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009841
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009842 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009843
Johannes Bergbc43b282009-07-25 10:54:13 +02009844 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +01009845 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009846 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +02009847 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009848
9849 return;
9850
9851nla_put_failure:
9852 genlmsg_cancel(msg, hdr);
9853 nlmsg_free(msg);
9854}
9855
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009856static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9857 struct net_device *netdev,
9858 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009859 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009860{
9861 struct sk_buff *msg;
9862 void *hdr;
9863
Johannes Berge6d6e342009-07-01 21:26:47 +02009864 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009865 if (!msg)
9866 return;
9867
9868 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9869 if (!hdr) {
9870 nlmsg_free(msg);
9871 return;
9872 }
9873
David S. Miller9360ffd2012-03-29 04:41:26 -04009874 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9875 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9876 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9877 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009878
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009879 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009880
Johannes Berg68eb5502013-11-19 15:19:38 +01009881 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009882 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009883 return;
9884
9885 nla_put_failure:
9886 genlmsg_cancel(msg, hdr);
9887 nlmsg_free(msg);
9888}
9889
9890void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009891 struct net_device *netdev, const u8 *buf,
9892 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009893{
9894 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009895 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009896}
9897
9898void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9899 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009900 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009901{
Johannes Berge6d6e342009-07-01 21:26:47 +02009902 nl80211_send_mlme_event(rdev, netdev, buf, len,
9903 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009904}
9905
Jouni Malinen53b46b82009-03-27 20:53:56 +02009906void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009907 struct net_device *netdev, const u8 *buf,
9908 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009909{
9910 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009911 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009912}
9913
Jouni Malinen53b46b82009-03-27 20:53:56 +02009914void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9915 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009916 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009917{
9918 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009919 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009920}
9921
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009922void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9923 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009924{
Johannes Berg947add32013-02-22 22:05:20 +01009925 struct wireless_dev *wdev = dev->ieee80211_ptr;
9926 struct wiphy *wiphy = wdev->wiphy;
9927 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009928 const struct ieee80211_mgmt *mgmt = (void *)buf;
9929 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009930
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009931 if (WARN_ON(len < 2))
9932 return;
9933
9934 if (ieee80211_is_deauth(mgmt->frame_control))
9935 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9936 else
9937 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9938
9939 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9940 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009941}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009942EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009943
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009944static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9945 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009946 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009947{
9948 struct sk_buff *msg;
9949 void *hdr;
9950
Johannes Berge6d6e342009-07-01 21:26:47 +02009951 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009952 if (!msg)
9953 return;
9954
9955 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9956 if (!hdr) {
9957 nlmsg_free(msg);
9958 return;
9959 }
9960
David S. Miller9360ffd2012-03-29 04:41:26 -04009961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9962 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9963 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9964 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9965 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009966
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009967 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009968
Johannes Berg68eb5502013-11-19 15:19:38 +01009969 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009970 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009971 return;
9972
9973 nla_put_failure:
9974 genlmsg_cancel(msg, hdr);
9975 nlmsg_free(msg);
9976}
9977
9978void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009979 struct net_device *netdev, const u8 *addr,
9980 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009981{
9982 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009983 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009984}
9985
9986void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009987 struct net_device *netdev, const u8 *addr,
9988 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009989{
Johannes Berge6d6e342009-07-01 21:26:47 +02009990 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9991 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009992}
9993
Samuel Ortizb23aa672009-07-01 21:26:54 +02009994void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9995 struct net_device *netdev, const u8 *bssid,
9996 const u8 *req_ie, size_t req_ie_len,
9997 const u8 *resp_ie, size_t resp_ie_len,
9998 u16 status, gfp_t gfp)
9999{
10000 struct sk_buff *msg;
10001 void *hdr;
10002
Thomas Graf58050fc2012-06-28 03:57:45 +000010003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010004 if (!msg)
10005 return;
10006
10007 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10008 if (!hdr) {
10009 nlmsg_free(msg);
10010 return;
10011 }
10012
David S. Miller9360ffd2012-03-29 04:41:26 -040010013 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10014 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10015 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10016 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10017 (req_ie &&
10018 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10019 (resp_ie &&
10020 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10021 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010022
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010023 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010024
Johannes Berg68eb5502013-11-19 15:19:38 +010010025 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010026 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010027 return;
10028
10029 nla_put_failure:
10030 genlmsg_cancel(msg, hdr);
10031 nlmsg_free(msg);
10032
10033}
10034
10035void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10036 struct net_device *netdev, const u8 *bssid,
10037 const u8 *req_ie, size_t req_ie_len,
10038 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10039{
10040 struct sk_buff *msg;
10041 void *hdr;
10042
Thomas Graf58050fc2012-06-28 03:57:45 +000010043 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010044 if (!msg)
10045 return;
10046
10047 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10048 if (!hdr) {
10049 nlmsg_free(msg);
10050 return;
10051 }
10052
David S. Miller9360ffd2012-03-29 04:41:26 -040010053 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10054 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10055 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10056 (req_ie &&
10057 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10058 (resp_ie &&
10059 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10060 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010061
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010062 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010063
Johannes Berg68eb5502013-11-19 15:19:38 +010010064 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010065 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010066 return;
10067
10068 nla_put_failure:
10069 genlmsg_cancel(msg, hdr);
10070 nlmsg_free(msg);
10071
10072}
10073
10074void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10075 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010076 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010077{
10078 struct sk_buff *msg;
10079 void *hdr;
10080
Thomas Graf58050fc2012-06-28 03:57:45 +000010081 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010082 if (!msg)
10083 return;
10084
10085 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10086 if (!hdr) {
10087 nlmsg_free(msg);
10088 return;
10089 }
10090
David S. Miller9360ffd2012-03-29 04:41:26 -040010091 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10092 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10093 (from_ap && reason &&
10094 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10095 (from_ap &&
10096 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10097 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10098 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010099
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010100 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010101
Johannes Berg68eb5502013-11-19 15:19:38 +010010102 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010103 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010104 return;
10105
10106 nla_put_failure:
10107 genlmsg_cancel(msg, hdr);
10108 nlmsg_free(msg);
10109
10110}
10111
Johannes Berg04a773a2009-04-19 21:24:32 +020010112void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10113 struct net_device *netdev, const u8 *bssid,
10114 gfp_t gfp)
10115{
10116 struct sk_buff *msg;
10117 void *hdr;
10118
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010119 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010120 if (!msg)
10121 return;
10122
10123 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10124 if (!hdr) {
10125 nlmsg_free(msg);
10126 return;
10127 }
10128
David S. Miller9360ffd2012-03-29 04:41:26 -040010129 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10130 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10131 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10132 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010133
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010134 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010135
Johannes Berg68eb5502013-11-19 15:19:38 +010010136 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010137 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010138 return;
10139
10140 nla_put_failure:
10141 genlmsg_cancel(msg, hdr);
10142 nlmsg_free(msg);
10143}
10144
Johannes Berg947add32013-02-22 22:05:20 +010010145void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10146 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010147{
Johannes Berg947add32013-02-22 22:05:20 +010010148 struct wireless_dev *wdev = dev->ieee80211_ptr;
10149 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010150 struct sk_buff *msg;
10151 void *hdr;
10152
Johannes Berg947add32013-02-22 22:05:20 +010010153 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10154 return;
10155
10156 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10157
Javier Cardonac93b5e72011-04-07 15:08:34 -070010158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10159 if (!msg)
10160 return;
10161
10162 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10163 if (!hdr) {
10164 nlmsg_free(msg);
10165 return;
10166 }
10167
David S. Miller9360ffd2012-03-29 04:41:26 -040010168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010169 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10170 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010171 (ie_len && ie &&
10172 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10173 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010174
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010175 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010176
Johannes Berg68eb5502013-11-19 15:19:38 +010010177 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010178 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010179 return;
10180
10181 nla_put_failure:
10182 genlmsg_cancel(msg, hdr);
10183 nlmsg_free(msg);
10184}
Johannes Berg947add32013-02-22 22:05:20 +010010185EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010186
Jouni Malinena3b8b052009-03-27 21:59:49 +020010187void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10188 struct net_device *netdev, const u8 *addr,
10189 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010190 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010191{
10192 struct sk_buff *msg;
10193 void *hdr;
10194
Johannes Berge6d6e342009-07-01 21:26:47 +020010195 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010196 if (!msg)
10197 return;
10198
10199 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10200 if (!hdr) {
10201 nlmsg_free(msg);
10202 return;
10203 }
10204
David S. Miller9360ffd2012-03-29 04:41:26 -040010205 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10206 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10207 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10208 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10209 (key_id != -1 &&
10210 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10211 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10212 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010213
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010214 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010215
Johannes Berg68eb5502013-11-19 15:19:38 +010010216 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010217 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010218 return;
10219
10220 nla_put_failure:
10221 genlmsg_cancel(msg, hdr);
10222 nlmsg_free(msg);
10223}
10224
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010225void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10226 struct ieee80211_channel *channel_before,
10227 struct ieee80211_channel *channel_after)
10228{
10229 struct sk_buff *msg;
10230 void *hdr;
10231 struct nlattr *nl_freq;
10232
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010234 if (!msg)
10235 return;
10236
10237 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10238 if (!hdr) {
10239 nlmsg_free(msg);
10240 return;
10241 }
10242
10243 /*
10244 * Since we are applying the beacon hint to a wiphy we know its
10245 * wiphy_idx is valid
10246 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010247 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10248 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010249
10250 /* Before */
10251 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10252 if (!nl_freq)
10253 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010254 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010255 goto nla_put_failure;
10256 nla_nest_end(msg, nl_freq);
10257
10258 /* After */
10259 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10260 if (!nl_freq)
10261 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010262 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010263 goto nla_put_failure;
10264 nla_nest_end(msg, nl_freq);
10265
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010266 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010267
Johannes Berg463d0182009-07-14 00:33:35 +020010268 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010269 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010270 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010271 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010272
10273 return;
10274
10275nla_put_failure:
10276 genlmsg_cancel(msg, hdr);
10277 nlmsg_free(msg);
10278}
10279
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010280static void nl80211_send_remain_on_chan_event(
10281 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010282 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010283 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010284 unsigned int duration, gfp_t gfp)
10285{
10286 struct sk_buff *msg;
10287 void *hdr;
10288
10289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10290 if (!msg)
10291 return;
10292
10293 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10294 if (!hdr) {
10295 nlmsg_free(msg);
10296 return;
10297 }
10298
David S. Miller9360ffd2012-03-29 04:41:26 -040010299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010300 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10301 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010302 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010303 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010304 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10305 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010306 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10307 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010308
David S. Miller9360ffd2012-03-29 04:41:26 -040010309 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10310 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10311 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010312
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010313 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010314
Johannes Berg68eb5502013-11-19 15:19:38 +010010315 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010316 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010317 return;
10318
10319 nla_put_failure:
10320 genlmsg_cancel(msg, hdr);
10321 nlmsg_free(msg);
10322}
10323
Johannes Berg947add32013-02-22 22:05:20 +010010324void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10325 struct ieee80211_channel *chan,
10326 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010327{
Johannes Berg947add32013-02-22 22:05:20 +010010328 struct wiphy *wiphy = wdev->wiphy;
10329 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10330
10331 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010332 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010333 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010334 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010335}
Johannes Berg947add32013-02-22 22:05:20 +010010336EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010337
Johannes Berg947add32013-02-22 22:05:20 +010010338void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10339 struct ieee80211_channel *chan,
10340 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010341{
Johannes Berg947add32013-02-22 22:05:20 +010010342 struct wiphy *wiphy = wdev->wiphy;
10343 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10344
10345 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010346 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010347 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010348}
Johannes Berg947add32013-02-22 22:05:20 +010010349EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010350
Johannes Berg947add32013-02-22 22:05:20 +010010351void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10352 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010353{
Johannes Berg947add32013-02-22 22:05:20 +010010354 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10355 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010356 struct sk_buff *msg;
10357
Johannes Berg947add32013-02-22 22:05:20 +010010358 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10359
Thomas Graf58050fc2012-06-28 03:57:45 +000010360 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010361 if (!msg)
10362 return;
10363
John W. Linville66266b32012-03-15 13:25:41 -040010364 if (nl80211_send_station(msg, 0, 0, 0,
10365 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010366 nlmsg_free(msg);
10367 return;
10368 }
10369
Johannes Berg68eb5502013-11-19 15:19:38 +010010370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010371 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010372}
Johannes Berg947add32013-02-22 22:05:20 +010010373EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010374
Johannes Berg947add32013-02-22 22:05:20 +010010375void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010376{
Johannes Berg947add32013-02-22 22:05:20 +010010377 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10378 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010379 struct sk_buff *msg;
10380 void *hdr;
10381
Johannes Berg947add32013-02-22 22:05:20 +010010382 trace_cfg80211_del_sta(dev, mac_addr);
10383
Thomas Graf58050fc2012-06-28 03:57:45 +000010384 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010385 if (!msg)
10386 return;
10387
10388 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10389 if (!hdr) {
10390 nlmsg_free(msg);
10391 return;
10392 }
10393
David S. Miller9360ffd2012-03-29 04:41:26 -040010394 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10395 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10396 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010397
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010398 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010399
Johannes Berg68eb5502013-11-19 15:19:38 +010010400 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010401 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010402 return;
10403
10404 nla_put_failure:
10405 genlmsg_cancel(msg, hdr);
10406 nlmsg_free(msg);
10407}
Johannes Berg947add32013-02-22 22:05:20 +010010408EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010409
Johannes Berg947add32013-02-22 22:05:20 +010010410void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10411 enum nl80211_connect_failed_reason reason,
10412 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010413{
Johannes Berg947add32013-02-22 22:05:20 +010010414 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10415 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010416 struct sk_buff *msg;
10417 void *hdr;
10418
10419 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10420 if (!msg)
10421 return;
10422
10423 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10424 if (!hdr) {
10425 nlmsg_free(msg);
10426 return;
10427 }
10428
10429 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10430 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10431 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10432 goto nla_put_failure;
10433
10434 genlmsg_end(msg, hdr);
10435
Johannes Berg68eb5502013-11-19 15:19:38 +010010436 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010437 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010438 return;
10439
10440 nla_put_failure:
10441 genlmsg_cancel(msg, hdr);
10442 nlmsg_free(msg);
10443}
Johannes Berg947add32013-02-22 22:05:20 +010010444EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010445
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010446static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10447 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010448{
10449 struct wireless_dev *wdev = dev->ieee80211_ptr;
10450 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10451 struct sk_buff *msg;
10452 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010453 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010454
Eric W. Biederman15e47302012-09-07 20:12:54 +000010455 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010456 return false;
10457
10458 msg = nlmsg_new(100, gfp);
10459 if (!msg)
10460 return true;
10461
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010462 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010463 if (!hdr) {
10464 nlmsg_free(msg);
10465 return true;
10466 }
10467
David S. Miller9360ffd2012-03-29 04:41:26 -040010468 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10470 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10471 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010472
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010473 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010474 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010475 return true;
10476
10477 nla_put_failure:
10478 genlmsg_cancel(msg, hdr);
10479 nlmsg_free(msg);
10480 return true;
10481}
10482
Johannes Berg947add32013-02-22 22:05:20 +010010483bool cfg80211_rx_spurious_frame(struct net_device *dev,
10484 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010485{
Johannes Berg947add32013-02-22 22:05:20 +010010486 struct wireless_dev *wdev = dev->ieee80211_ptr;
10487 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010488
Johannes Berg947add32013-02-22 22:05:20 +010010489 trace_cfg80211_rx_spurious_frame(dev, addr);
10490
10491 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10492 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10493 trace_cfg80211_return_bool(false);
10494 return false;
10495 }
10496 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10497 addr, gfp);
10498 trace_cfg80211_return_bool(ret);
10499 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010500}
Johannes Berg947add32013-02-22 22:05:20 +010010501EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10502
10503bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10504 const u8 *addr, gfp_t gfp)
10505{
10506 struct wireless_dev *wdev = dev->ieee80211_ptr;
10507 bool ret;
10508
10509 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10510
10511 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10512 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10513 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10514 trace_cfg80211_return_bool(false);
10515 return false;
10516 }
10517 ret = __nl80211_unexpected_frame(dev,
10518 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10519 addr, gfp);
10520 trace_cfg80211_return_bool(ret);
10521 return ret;
10522}
10523EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010524
Johannes Berg2e161f72010-08-12 15:38:38 +020010525int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010526 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010527 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010528 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010529{
Johannes Berg71bbc992012-06-15 15:30:18 +020010530 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010531 struct sk_buff *msg;
10532 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010533
10534 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10535 if (!msg)
10536 return -ENOMEM;
10537
Johannes Berg2e161f72010-08-12 15:38:38 +020010538 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010539 if (!hdr) {
10540 nlmsg_free(msg);
10541 return -ENOMEM;
10542 }
10543
David S. Miller9360ffd2012-03-29 04:41:26 -040010544 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010545 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10546 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010547 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010548 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10549 (sig_dbm &&
10550 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010551 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10552 (flags &&
10553 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010554 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010555
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010556 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010557
Eric W. Biederman15e47302012-09-07 20:12:54 +000010558 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010559
10560 nla_put_failure:
10561 genlmsg_cancel(msg, hdr);
10562 nlmsg_free(msg);
10563 return -ENOBUFS;
10564}
10565
Johannes Berg947add32013-02-22 22:05:20 +010010566void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10567 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010568{
Johannes Berg947add32013-02-22 22:05:20 +010010569 struct wiphy *wiphy = wdev->wiphy;
10570 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010571 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010572 struct sk_buff *msg;
10573 void *hdr;
10574
Johannes Berg947add32013-02-22 22:05:20 +010010575 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10576
Jouni Malinen026331c2010-02-15 12:53:10 +020010577 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10578 if (!msg)
10579 return;
10580
Johannes Berg2e161f72010-08-12 15:38:38 +020010581 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010582 if (!hdr) {
10583 nlmsg_free(msg);
10584 return;
10585 }
10586
David S. Miller9360ffd2012-03-29 04:41:26 -040010587 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010588 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10589 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010590 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010591 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10592 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10593 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10594 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010595
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010596 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010597
Johannes Berg68eb5502013-11-19 15:19:38 +010010598 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010599 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010600 return;
10601
10602 nla_put_failure:
10603 genlmsg_cancel(msg, hdr);
10604 nlmsg_free(msg);
10605}
Johannes Berg947add32013-02-22 22:05:20 +010010606EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010607
Johannes Berg947add32013-02-22 22:05:20 +010010608void cfg80211_cqm_rssi_notify(struct net_device *dev,
10609 enum nl80211_cqm_rssi_threshold_event rssi_event,
10610 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010611{
Johannes Berg947add32013-02-22 22:05:20 +010010612 struct wireless_dev *wdev = dev->ieee80211_ptr;
10613 struct wiphy *wiphy = wdev->wiphy;
10614 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010615 struct sk_buff *msg;
10616 struct nlattr *pinfoattr;
10617 void *hdr;
10618
Johannes Berg947add32013-02-22 22:05:20 +010010619 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10620
Thomas Graf58050fc2012-06-28 03:57:45 +000010621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010622 if (!msg)
10623 return;
10624
10625 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10626 if (!hdr) {
10627 nlmsg_free(msg);
10628 return;
10629 }
10630
David S. Miller9360ffd2012-03-29 04:41:26 -040010631 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010632 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010633 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010634
10635 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10636 if (!pinfoattr)
10637 goto nla_put_failure;
10638
David S. Miller9360ffd2012-03-29 04:41:26 -040010639 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10640 rssi_event))
10641 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010642
10643 nla_nest_end(msg, pinfoattr);
10644
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010645 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010646
Johannes Berg68eb5502013-11-19 15:19:38 +010010647 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010648 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010649 return;
10650
10651 nla_put_failure:
10652 genlmsg_cancel(msg, hdr);
10653 nlmsg_free(msg);
10654}
Johannes Berg947add32013-02-22 22:05:20 +010010655EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010656
Johannes Berg947add32013-02-22 22:05:20 +010010657static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10658 struct net_device *netdev, const u8 *bssid,
10659 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010660{
10661 struct sk_buff *msg;
10662 struct nlattr *rekey_attr;
10663 void *hdr;
10664
Thomas Graf58050fc2012-06-28 03:57:45 +000010665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010666 if (!msg)
10667 return;
10668
10669 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10670 if (!hdr) {
10671 nlmsg_free(msg);
10672 return;
10673 }
10674
David S. Miller9360ffd2012-03-29 04:41:26 -040010675 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10676 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10677 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10678 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010679
10680 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10681 if (!rekey_attr)
10682 goto nla_put_failure;
10683
David S. Miller9360ffd2012-03-29 04:41:26 -040010684 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10685 NL80211_REPLAY_CTR_LEN, replay_ctr))
10686 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010687
10688 nla_nest_end(msg, rekey_attr);
10689
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010690 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010691
Johannes Berg68eb5502013-11-19 15:19:38 +010010692 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010693 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010694 return;
10695
10696 nla_put_failure:
10697 genlmsg_cancel(msg, hdr);
10698 nlmsg_free(msg);
10699}
10700
Johannes Berg947add32013-02-22 22:05:20 +010010701void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10702 const u8 *replay_ctr, gfp_t gfp)
10703{
10704 struct wireless_dev *wdev = dev->ieee80211_ptr;
10705 struct wiphy *wiphy = wdev->wiphy;
10706 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10707
10708 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10709 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10710}
10711EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10712
10713static void
10714nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10715 struct net_device *netdev, int index,
10716 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010717{
10718 struct sk_buff *msg;
10719 struct nlattr *attr;
10720 void *hdr;
10721
Thomas Graf58050fc2012-06-28 03:57:45 +000010722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010723 if (!msg)
10724 return;
10725
10726 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10727 if (!hdr) {
10728 nlmsg_free(msg);
10729 return;
10730 }
10731
David S. Miller9360ffd2012-03-29 04:41:26 -040010732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10733 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10734 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010735
10736 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10737 if (!attr)
10738 goto nla_put_failure;
10739
David S. Miller9360ffd2012-03-29 04:41:26 -040010740 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10741 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10742 (preauth &&
10743 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10744 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010745
10746 nla_nest_end(msg, attr);
10747
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010748 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010749
Johannes Berg68eb5502013-11-19 15:19:38 +010010750 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010751 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010752 return;
10753
10754 nla_put_failure:
10755 genlmsg_cancel(msg, hdr);
10756 nlmsg_free(msg);
10757}
10758
Johannes Berg947add32013-02-22 22:05:20 +010010759void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10760 const u8 *bssid, bool preauth, gfp_t gfp)
10761{
10762 struct wireless_dev *wdev = dev->ieee80211_ptr;
10763 struct wiphy *wiphy = wdev->wiphy;
10764 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10765
10766 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10767 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10768}
10769EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10770
10771static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10772 struct net_device *netdev,
10773 struct cfg80211_chan_def *chandef,
10774 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010775{
10776 struct sk_buff *msg;
10777 void *hdr;
10778
Thomas Graf58050fc2012-06-28 03:57:45 +000010779 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010780 if (!msg)
10781 return;
10782
10783 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10784 if (!hdr) {
10785 nlmsg_free(msg);
10786 return;
10787 }
10788
Johannes Berg683b6d32012-11-08 21:25:48 +010010789 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10790 goto nla_put_failure;
10791
10792 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010793 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010794
10795 genlmsg_end(msg, hdr);
10796
Johannes Berg68eb5502013-11-19 15:19:38 +010010797 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010798 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010799 return;
10800
10801 nla_put_failure:
10802 genlmsg_cancel(msg, hdr);
10803 nlmsg_free(msg);
10804}
10805
Johannes Berg947add32013-02-22 22:05:20 +010010806void cfg80211_ch_switch_notify(struct net_device *dev,
10807 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010808{
Johannes Berg947add32013-02-22 22:05:20 +010010809 struct wireless_dev *wdev = dev->ieee80211_ptr;
10810 struct wiphy *wiphy = wdev->wiphy;
10811 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10812
10813 trace_cfg80211_ch_switch_notify(dev, chandef);
10814
10815 wdev_lock(wdev);
10816
10817 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020010818 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070010819 wdev->iftype != NL80211_IFTYPE_ADHOC &&
10820 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Johannes Berg947add32013-02-22 22:05:20 +010010821 goto out;
10822
10823 wdev->channel = chandef->chan;
10824 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10825out:
10826 wdev_unlock(wdev);
10827 return;
10828}
10829EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10830
10831void cfg80211_cqm_txe_notify(struct net_device *dev,
10832 const u8 *peer, u32 num_packets,
10833 u32 rate, u32 intvl, gfp_t gfp)
10834{
10835 struct wireless_dev *wdev = dev->ieee80211_ptr;
10836 struct wiphy *wiphy = wdev->wiphy;
10837 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010838 struct sk_buff *msg;
10839 struct nlattr *pinfoattr;
10840 void *hdr;
10841
10842 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10843 if (!msg)
10844 return;
10845
10846 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10847 if (!hdr) {
10848 nlmsg_free(msg);
10849 return;
10850 }
10851
10852 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010853 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010854 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10855 goto nla_put_failure;
10856
10857 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10858 if (!pinfoattr)
10859 goto nla_put_failure;
10860
10861 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10862 goto nla_put_failure;
10863
10864 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10865 goto nla_put_failure;
10866
10867 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10868 goto nla_put_failure;
10869
10870 nla_nest_end(msg, pinfoattr);
10871
10872 genlmsg_end(msg, hdr);
10873
Johannes Berg68eb5502013-11-19 15:19:38 +010010874 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010875 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010876 return;
10877
10878 nla_put_failure:
10879 genlmsg_cancel(msg, hdr);
10880 nlmsg_free(msg);
10881}
Johannes Berg947add32013-02-22 22:05:20 +010010882EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010883
10884void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010885nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10886 struct cfg80211_chan_def *chandef,
10887 enum nl80211_radar_event event,
10888 struct net_device *netdev, gfp_t gfp)
10889{
10890 struct sk_buff *msg;
10891 void *hdr;
10892
10893 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10894 if (!msg)
10895 return;
10896
10897 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10898 if (!hdr) {
10899 nlmsg_free(msg);
10900 return;
10901 }
10902
10903 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10904 goto nla_put_failure;
10905
10906 /* NOP and radar events don't need a netdev parameter */
10907 if (netdev) {
10908 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10909
10910 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10911 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10912 goto nla_put_failure;
10913 }
10914
10915 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10916 goto nla_put_failure;
10917
10918 if (nl80211_send_chandef(msg, chandef))
10919 goto nla_put_failure;
10920
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010921 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010922
Johannes Berg68eb5502013-11-19 15:19:38 +010010923 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010924 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010925 return;
10926
10927 nla_put_failure:
10928 genlmsg_cancel(msg, hdr);
10929 nlmsg_free(msg);
10930}
10931
Johannes Berg947add32013-02-22 22:05:20 +010010932void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10933 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010934{
Johannes Berg947add32013-02-22 22:05:20 +010010935 struct wireless_dev *wdev = dev->ieee80211_ptr;
10936 struct wiphy *wiphy = wdev->wiphy;
10937 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010938 struct sk_buff *msg;
10939 struct nlattr *pinfoattr;
10940 void *hdr;
10941
Johannes Berg947add32013-02-22 22:05:20 +010010942 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10943
Thomas Graf58050fc2012-06-28 03:57:45 +000010944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010945 if (!msg)
10946 return;
10947
10948 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10949 if (!hdr) {
10950 nlmsg_free(msg);
10951 return;
10952 }
10953
David S. Miller9360ffd2012-03-29 04:41:26 -040010954 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010955 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010956 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10957 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010958
10959 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10960 if (!pinfoattr)
10961 goto nla_put_failure;
10962
David S. Miller9360ffd2012-03-29 04:41:26 -040010963 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10964 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010965
10966 nla_nest_end(msg, pinfoattr);
10967
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010968 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010969
Johannes Berg68eb5502013-11-19 15:19:38 +010010970 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010971 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010972 return;
10973
10974 nla_put_failure:
10975 genlmsg_cancel(msg, hdr);
10976 nlmsg_free(msg);
10977}
Johannes Berg947add32013-02-22 22:05:20 +010010978EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010979
Johannes Berg7f6cf312011-11-04 11:18:15 +010010980void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10981 u64 cookie, bool acked, gfp_t gfp)
10982{
10983 struct wireless_dev *wdev = dev->ieee80211_ptr;
10984 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10985 struct sk_buff *msg;
10986 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010987
Beni Lev4ee3e062012-08-27 12:49:39 +030010988 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10989
Thomas Graf58050fc2012-06-28 03:57:45 +000010990 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010991
Johannes Berg7f6cf312011-11-04 11:18:15 +010010992 if (!msg)
10993 return;
10994
10995 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10996 if (!hdr) {
10997 nlmsg_free(msg);
10998 return;
10999 }
11000
David S. Miller9360ffd2012-03-29 04:41:26 -040011001 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11002 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11003 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11004 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11005 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11006 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011007
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011008 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011009
Johannes Berg68eb5502013-11-19 15:19:38 +010011010 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011011 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011012 return;
11013
11014 nla_put_failure:
11015 genlmsg_cancel(msg, hdr);
11016 nlmsg_free(msg);
11017}
11018EXPORT_SYMBOL(cfg80211_probe_status);
11019
Johannes Berg5e7602302011-11-04 11:18:17 +010011020void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11021 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011022 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010011023{
11024 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11025 struct sk_buff *msg;
11026 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011027 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010011028
Beni Lev4ee3e062012-08-27 12:49:39 +030011029 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11030
Ben Greear37c73b52012-10-26 14:49:25 -070011031 spin_lock_bh(&rdev->beacon_registrations_lock);
11032 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11033 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11034 if (!msg) {
11035 spin_unlock_bh(&rdev->beacon_registrations_lock);
11036 return;
11037 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011038
Ben Greear37c73b52012-10-26 14:49:25 -070011039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11040 if (!hdr)
11041 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010011042
Ben Greear37c73b52012-10-26 14:49:25 -070011043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11044 (freq &&
11045 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11046 (sig_dbm &&
11047 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11048 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11049 goto nla_put_failure;
11050
11051 genlmsg_end(msg, hdr);
11052
11053 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010011054 }
Ben Greear37c73b52012-10-26 14:49:25 -070011055 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011056 return;
11057
11058 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011059 spin_unlock_bh(&rdev->beacon_registrations_lock);
11060 if (hdr)
11061 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011062 nlmsg_free(msg);
11063}
11064EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11065
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011066#ifdef CONFIG_PM
11067void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11068 struct cfg80211_wowlan_wakeup *wakeup,
11069 gfp_t gfp)
11070{
11071 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11072 struct sk_buff *msg;
11073 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011074 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011075
11076 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11077
11078 if (wakeup)
11079 size += wakeup->packet_present_len;
11080
11081 msg = nlmsg_new(size, gfp);
11082 if (!msg)
11083 return;
11084
11085 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11086 if (!hdr)
11087 goto free_msg;
11088
11089 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11090 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11091 goto free_msg;
11092
11093 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11094 wdev->netdev->ifindex))
11095 goto free_msg;
11096
11097 if (wakeup) {
11098 struct nlattr *reasons;
11099
11100 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011101 if (!reasons)
11102 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011103
11104 if (wakeup->disconnect &&
11105 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11106 goto free_msg;
11107 if (wakeup->magic_pkt &&
11108 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11109 goto free_msg;
11110 if (wakeup->gtk_rekey_failure &&
11111 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11112 goto free_msg;
11113 if (wakeup->eap_identity_req &&
11114 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11115 goto free_msg;
11116 if (wakeup->four_way_handshake &&
11117 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11118 goto free_msg;
11119 if (wakeup->rfkill_release &&
11120 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11121 goto free_msg;
11122
11123 if (wakeup->pattern_idx >= 0 &&
11124 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11125 wakeup->pattern_idx))
11126 goto free_msg;
11127
Johannes Bergae917c92013-10-25 11:05:22 +020011128 if (wakeup->tcp_match &&
11129 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11130 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011131
Johannes Bergae917c92013-10-25 11:05:22 +020011132 if (wakeup->tcp_connlost &&
11133 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11134 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011135
Johannes Bergae917c92013-10-25 11:05:22 +020011136 if (wakeup->tcp_nomoretokens &&
11137 nla_put_flag(msg,
11138 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11139 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011140
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011141 if (wakeup->packet) {
11142 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11143 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11144
11145 if (!wakeup->packet_80211) {
11146 pkt_attr =
11147 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11148 len_attr =
11149 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11150 }
11151
11152 if (wakeup->packet_len &&
11153 nla_put_u32(msg, len_attr, wakeup->packet_len))
11154 goto free_msg;
11155
11156 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11157 wakeup->packet))
11158 goto free_msg;
11159 }
11160
11161 nla_nest_end(msg, reasons);
11162 }
11163
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011164 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011165
Johannes Berg68eb5502013-11-19 15:19:38 +010011166 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011167 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011168 return;
11169
11170 free_msg:
11171 nlmsg_free(msg);
11172}
11173EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11174#endif
11175
Jouni Malinen3475b092012-11-16 22:49:57 +020011176void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11177 enum nl80211_tdls_operation oper,
11178 u16 reason_code, gfp_t gfp)
11179{
11180 struct wireless_dev *wdev = dev->ieee80211_ptr;
11181 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11182 struct sk_buff *msg;
11183 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011184
11185 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11186 reason_code);
11187
11188 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11189 if (!msg)
11190 return;
11191
11192 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11193 if (!hdr) {
11194 nlmsg_free(msg);
11195 return;
11196 }
11197
11198 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11199 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11200 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11201 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11202 (reason_code > 0 &&
11203 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11204 goto nla_put_failure;
11205
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011206 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011207
Johannes Berg68eb5502013-11-19 15:19:38 +010011208 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011209 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011210 return;
11211
11212 nla_put_failure:
11213 genlmsg_cancel(msg, hdr);
11214 nlmsg_free(msg);
11215}
11216EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11217
Jouni Malinen026331c2010-02-15 12:53:10 +020011218static int nl80211_netlink_notify(struct notifier_block * nb,
11219 unsigned long state,
11220 void *_notify)
11221{
11222 struct netlink_notify *notify = _notify;
11223 struct cfg80211_registered_device *rdev;
11224 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011225 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011226
11227 if (state != NETLINK_URELEASE)
11228 return NOTIFY_DONE;
11229
11230 rcu_read_lock();
11231
Johannes Berg5e7602302011-11-04 11:18:17 +010011232 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011233 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011234 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011235
11236 spin_lock_bh(&rdev->beacon_registrations_lock);
11237 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11238 list) {
11239 if (reg->nlportid == notify->portid) {
11240 list_del(&reg->list);
11241 kfree(reg);
11242 break;
11243 }
11244 }
11245 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011246 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011247
11248 rcu_read_unlock();
11249
11250 return NOTIFY_DONE;
11251}
11252
11253static struct notifier_block nl80211_netlink_notifier = {
11254 .notifier_call = nl80211_netlink_notify,
11255};
11256
Jouni Malinen355199e2013-02-27 17:14:27 +020011257void cfg80211_ft_event(struct net_device *netdev,
11258 struct cfg80211_ft_event_params *ft_event)
11259{
11260 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11261 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11262 struct sk_buff *msg;
11263 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011264
11265 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11266
11267 if (!ft_event->target_ap)
11268 return;
11269
11270 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11271 if (!msg)
11272 return;
11273
11274 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011275 if (!hdr)
11276 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011277
Johannes Bergae917c92013-10-25 11:05:22 +020011278 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11279 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11280 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11281 goto out;
11282
11283 if (ft_event->ies &&
11284 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11285 goto out;
11286 if (ft_event->ric_ies &&
11287 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11288 ft_event->ric_ies))
11289 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011290
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011291 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011292
Johannes Berg68eb5502013-11-19 15:19:38 +010011293 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011294 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011295 return;
11296 out:
11297 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011298}
11299EXPORT_SYMBOL(cfg80211_ft_event);
11300
Arend van Spriel5de17982013-04-18 15:49:00 +020011301void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11302{
11303 struct cfg80211_registered_device *rdev;
11304 struct sk_buff *msg;
11305 void *hdr;
11306 u32 nlportid;
11307
11308 rdev = wiphy_to_dev(wdev->wiphy);
11309 if (!rdev->crit_proto_nlportid)
11310 return;
11311
11312 nlportid = rdev->crit_proto_nlportid;
11313 rdev->crit_proto_nlportid = 0;
11314
11315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11316 if (!msg)
11317 return;
11318
11319 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11320 if (!hdr)
11321 goto nla_put_failure;
11322
11323 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11324 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11325 goto nla_put_failure;
11326
11327 genlmsg_end(msg, hdr);
11328
11329 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11330 return;
11331
11332 nla_put_failure:
11333 if (hdr)
11334 genlmsg_cancel(msg, hdr);
11335 nlmsg_free(msg);
11336
11337}
11338EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11339
Johannes Berg55682962007-09-20 13:09:35 -040011340/* initialisation/exit functions */
11341
11342int nl80211_init(void)
11343{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011344 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011345
Johannes Berg2a94fe42013-11-19 15:19:39 +010011346 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11347 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011348 if (err)
11349 return err;
11350
Jouni Malinen026331c2010-02-15 12:53:10 +020011351 err = netlink_register_notifier(&nl80211_netlink_notifier);
11352 if (err)
11353 goto err_out;
11354
Johannes Berg55682962007-09-20 13:09:35 -040011355 return 0;
11356 err_out:
11357 genl_unregister_family(&nl80211_fam);
11358 return err;
11359}
11360
11361void nl80211_exit(void)
11362{
Jouni Malinen026331c2010-02-15 12:53:10 +020011363 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011364 genl_unregister_family(&nl80211_fam);
11365}