blob: 6dca5a700174dd25f0a5eb4ba682ae2f74436e3c [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 Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 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 Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee47782012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700406/* policy for coalesce rule attributes */
407static const struct nla_policy
408nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
409 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
410 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
411 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
412};
413
Johannes Berge5497d72011-07-05 16:35:40 +0200414/* policy for GTK rekey offload attributes */
415static const struct nla_policy
416nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
417 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
418 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
419 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
420};
421
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300422static const struct nla_policy
423nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200424 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300425 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700426 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300427};
428
Johannes Berg97990a02013-04-19 01:02:55 +0200429static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
430 struct netlink_callback *cb,
431 struct cfg80211_registered_device **rdev,
432 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100433{
Johannes Berg67748892010-10-04 21:14:06 +0200434 int err;
435
Johannes Berg67748892010-10-04 21:14:06 +0200436 rtnl_lock();
437
Johannes Berg97990a02013-04-19 01:02:55 +0200438 if (!cb->args[0]) {
439 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
440 nl80211_fam.attrbuf, nl80211_fam.maxattr,
441 nl80211_policy);
442 if (err)
443 goto out_unlock;
444
445 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
446 nl80211_fam.attrbuf);
447 if (IS_ERR(*wdev)) {
448 err = PTR_ERR(*wdev);
449 goto out_unlock;
450 }
451 *rdev = wiphy_to_dev((*wdev)->wiphy);
452 cb->args[0] = (*rdev)->wiphy_idx;
453 cb->args[1] = (*wdev)->identifier;
454 } else {
455 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
456 struct wireless_dev *tmp;
457
458 if (!wiphy) {
459 err = -ENODEV;
460 goto out_unlock;
461 }
462 *rdev = wiphy_to_dev(wiphy);
463 *wdev = NULL;
464
Johannes Berg97990a02013-04-19 01:02:55 +0200465 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
466 if (tmp->identifier == cb->args[1]) {
467 *wdev = tmp;
468 break;
469 }
470 }
Johannes Berg97990a02013-04-19 01:02:55 +0200471
472 if (!*wdev) {
473 err = -ENODEV;
474 goto out_unlock;
475 }
Johannes Berg67748892010-10-04 21:14:06 +0200476 }
477
Johannes Berg67748892010-10-04 21:14:06 +0200478 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200479 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200480 rtnl_unlock();
481 return err;
482}
483
Johannes Berg97990a02013-04-19 01:02:55 +0200484static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 rtnl_unlock();
487}
488
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100489/* IE validation */
490static bool is_valid_ie_attr(const struct nlattr *attr)
491{
492 const u8 *pos;
493 int len;
494
495 if (!attr)
496 return true;
497
498 pos = nla_data(attr);
499 len = nla_len(attr);
500
501 while (len) {
502 u8 elemlen;
503
504 if (len < 2)
505 return false;
506 len -= 2;
507
508 elemlen = pos[1];
509 if (elemlen > len)
510 return false;
511
512 len -= elemlen;
513 pos += 2 + elemlen;
514 }
515
516 return true;
517}
518
Johannes Berg55682962007-09-20 13:09:35 -0400519/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000520static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400521 int flags, u8 cmd)
522{
523 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000524 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400525}
526
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400527static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100528 struct ieee80211_channel *chan,
529 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400530{
David S. Miller9360ffd2012-03-29 04:41:26 -0400531 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
532 chan->center_freq))
533 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400534
David S. Miller9360ffd2012-03-29 04:41:26 -0400535 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
536 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
537 goto nla_put_failure;
538 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
539 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
540 goto nla_put_failure;
541 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
542 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
543 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100544 if (chan->flags & IEEE80211_CHAN_RADAR) {
545 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
546 goto nla_put_failure;
547 if (large) {
548 u32 time;
549
550 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
551
552 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
553 chan->dfs_state))
554 goto nla_put_failure;
555 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
556 time))
557 goto nla_put_failure;
558 }
559 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400560
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100561 if (large) {
562 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
563 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
564 goto nla_put_failure;
565 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
566 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
567 goto nla_put_failure;
568 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
569 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
570 goto nla_put_failure;
571 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
572 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
573 goto nla_put_failure;
574 }
575
David S. Miller9360ffd2012-03-29 04:41:26 -0400576 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
577 DBM_TO_MBM(chan->max_power)))
578 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400579
580 return 0;
581
582 nla_put_failure:
583 return -ENOBUFS;
584}
585
Johannes Berg55682962007-09-20 13:09:35 -0400586/* netlink command implementations */
587
Johannes Bergb9454e82009-07-08 13:29:08 +0200588struct key_parse {
589 struct key_params p;
590 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200591 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200592 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100593 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200594};
595
596static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
597{
598 struct nlattr *tb[NL80211_KEY_MAX + 1];
599 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
600 nl80211_key_policy);
601 if (err)
602 return err;
603
604 k->def = !!tb[NL80211_KEY_DEFAULT];
605 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
606
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100607 if (k->def) {
608 k->def_uni = true;
609 k->def_multi = true;
610 }
611 if (k->defmgmt)
612 k->def_multi = true;
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (tb[NL80211_KEY_IDX])
615 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
616
617 if (tb[NL80211_KEY_DATA]) {
618 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
619 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
620 }
621
622 if (tb[NL80211_KEY_SEQ]) {
623 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
624 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
625 }
626
627 if (tb[NL80211_KEY_CIPHER])
628 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
629
Johannes Berge31b8212010-10-05 19:39:30 +0200630 if (tb[NL80211_KEY_TYPE]) {
631 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
632 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
633 return -EINVAL;
634 }
635
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100636 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
637 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100638 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
639 tb[NL80211_KEY_DEFAULT_TYPES],
640 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100641 if (err)
642 return err;
643
644 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
645 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
646 }
647
Johannes Bergb9454e82009-07-08 13:29:08 +0200648 return 0;
649}
650
651static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
652{
653 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
654 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
655 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
656 }
657
658 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
659 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
660 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
661 }
662
663 if (info->attrs[NL80211_ATTR_KEY_IDX])
664 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
665
666 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
667 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
668
669 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
670 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
671
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100672 if (k->def) {
673 k->def_uni = true;
674 k->def_multi = true;
675 }
676 if (k->defmgmt)
677 k->def_multi = true;
678
Johannes Berge31b8212010-10-05 19:39:30 +0200679 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
680 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
681 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
682 return -EINVAL;
683 }
684
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100685 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
686 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
687 int err = nla_parse_nested(
688 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
689 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
690 nl80211_key_default_policy);
691 if (err)
692 return err;
693
694 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
695 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
696 }
697
Johannes Bergb9454e82009-07-08 13:29:08 +0200698 return 0;
699}
700
701static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
702{
703 int err;
704
705 memset(k, 0, sizeof(*k));
706 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200707 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200708
709 if (info->attrs[NL80211_ATTR_KEY])
710 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
711 else
712 err = nl80211_parse_key_old(info, k);
713
714 if (err)
715 return err;
716
717 if (k->def && k->defmgmt)
718 return -EINVAL;
719
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100720 if (k->defmgmt) {
721 if (k->def_uni || !k->def_multi)
722 return -EINVAL;
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 if (k->idx != -1) {
726 if (k->defmgmt) {
727 if (k->idx < 4 || k->idx > 5)
728 return -EINVAL;
729 } else if (k->def) {
730 if (k->idx < 0 || k->idx > 3)
731 return -EINVAL;
732 } else {
733 if (k->idx < 0 || k->idx > 5)
734 return -EINVAL;
735 }
736 }
737
738 return 0;
739}
740
Johannes Bergfffd0932009-07-08 14:22:54 +0200741static struct cfg80211_cached_keys *
742nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530743 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200744{
745 struct key_parse parse;
746 struct nlattr *key;
747 struct cfg80211_cached_keys *result;
748 int rem, err, def = 0;
749
750 result = kzalloc(sizeof(*result), GFP_KERNEL);
751 if (!result)
752 return ERR_PTR(-ENOMEM);
753
754 result->def = -1;
755 result->defmgmt = -1;
756
757 nla_for_each_nested(key, keys, rem) {
758 memset(&parse, 0, sizeof(parse));
759 parse.idx = -1;
760
761 err = nl80211_parse_key_new(key, &parse);
762 if (err)
763 goto error;
764 err = -EINVAL;
765 if (!parse.p.key)
766 goto error;
767 if (parse.idx < 0 || parse.idx > 4)
768 goto error;
769 if (parse.def) {
770 if (def)
771 goto error;
772 def = 1;
773 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (!parse.def_uni || !parse.def_multi)
775 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200776 } else if (parse.defmgmt)
777 goto error;
778 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200779 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200780 if (err)
781 goto error;
782 result->params[parse.idx].cipher = parse.p.cipher;
783 result->params[parse.idx].key_len = parse.p.key_len;
784 result->params[parse.idx].key = result->data[parse.idx];
785 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530786
787 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
788 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
789 if (no_ht)
790 *no_ht = true;
791 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200792 }
793
794 return result;
795 error:
796 kfree(result);
797 return ERR_PTR(err);
798}
799
800static int nl80211_key_allowed(struct wireless_dev *wdev)
801{
802 ASSERT_WDEV_LOCK(wdev);
803
Johannes Bergfffd0932009-07-08 14:22:54 +0200804 switch (wdev->iftype) {
805 case NL80211_IFTYPE_AP:
806 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700808 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 break;
810 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200811 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200812 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200813 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 return -ENOLINK;
815 break;
816 default:
817 return -EINVAL;
818 }
819
820 return 0;
821}
822
Johannes Berg7527a782011-05-13 10:58:57 +0200823static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
824{
825 struct nlattr *nl_modes = nla_nest_start(msg, attr);
826 int i;
827
828 if (!nl_modes)
829 goto nla_put_failure;
830
831 i = 0;
832 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400833 if ((ifmodes & 1) && nla_put_flag(msg, i))
834 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200835 ifmodes >>= 1;
836 i++;
837 }
838
839 nla_nest_end(msg, nl_modes);
840 return 0;
841
842nla_put_failure:
843 return -ENOBUFS;
844}
845
846static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100847 struct sk_buff *msg,
848 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200849{
850 struct nlattr *nl_combis;
851 int i, j;
852
853 nl_combis = nla_nest_start(msg,
854 NL80211_ATTR_INTERFACE_COMBINATIONS);
855 if (!nl_combis)
856 goto nla_put_failure;
857
858 for (i = 0; i < wiphy->n_iface_combinations; i++) {
859 const struct ieee80211_iface_combination *c;
860 struct nlattr *nl_combi, *nl_limits;
861
862 c = &wiphy->iface_combinations[i];
863
864 nl_combi = nla_nest_start(msg, i + 1);
865 if (!nl_combi)
866 goto nla_put_failure;
867
868 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
869 if (!nl_limits)
870 goto nla_put_failure;
871
872 for (j = 0; j < c->n_limits; j++) {
873 struct nlattr *nl_limit;
874
875 nl_limit = nla_nest_start(msg, j + 1);
876 if (!nl_limit)
877 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400878 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
879 c->limits[j].max))
880 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200881 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
882 c->limits[j].types))
883 goto nla_put_failure;
884 nla_nest_end(msg, nl_limit);
885 }
886
887 nla_nest_end(msg, nl_limits);
888
David S. Miller9360ffd2012-03-29 04:41:26 -0400889 if (c->beacon_int_infra_match &&
890 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
891 goto nla_put_failure;
892 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
893 c->num_different_channels) ||
894 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
895 c->max_interfaces))
896 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100897 if (large &&
898 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
899 c->radar_detect_widths))
900 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200901
902 nla_nest_end(msg, nl_combi);
903 }
904
905 nla_nest_end(msg, nl_combis);
906
907 return 0;
908nla_put_failure:
909 return -ENOBUFS;
910}
911
Johannes Berg3713b4e2013-02-14 16:19:38 +0100912#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100913static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
914 struct sk_buff *msg)
915{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200916 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100917 struct nlattr *nl_tcp;
918
919 if (!tcp)
920 return 0;
921
922 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
923 if (!nl_tcp)
924 return -ENOBUFS;
925
926 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
927 tcp->data_payload_max))
928 return -ENOBUFS;
929
930 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
931 tcp->data_payload_max))
932 return -ENOBUFS;
933
934 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
935 return -ENOBUFS;
936
937 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
938 sizeof(*tcp->tok), tcp->tok))
939 return -ENOBUFS;
940
941 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
942 tcp->data_interval_max))
943 return -ENOBUFS;
944
945 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
946 tcp->wake_payload_max))
947 return -ENOBUFS;
948
949 nla_nest_end(msg, nl_tcp);
950 return 0;
951}
952
Johannes Berg3713b4e2013-02-14 16:19:38 +0100953static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100954 struct cfg80211_registered_device *dev,
955 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100956{
957 struct nlattr *nl_wowlan;
958
Johannes Berg964dc9e2013-06-03 17:25:34 +0200959 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100960 return 0;
961
962 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
963 if (!nl_wowlan)
964 return -ENOBUFS;
965
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200974 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100975 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100979 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200980 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
982 return -ENOBUFS;
983
Johannes Berg964dc9e2013-06-03 17:25:34 +0200984 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700985 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200986 .max_patterns = dev->wiphy.wowlan->n_patterns,
987 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
988 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
989 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990 };
991
992 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
993 sizeof(pat), &pat))
994 return -ENOBUFS;
995 }
996
Johannes Bergb56cf722013-02-20 01:02:38 +0100997 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
998 return -ENOBUFS;
999
Johannes Berg3713b4e2013-02-14 16:19:38 +01001000 nla_nest_end(msg, nl_wowlan);
1001
1002 return 0;
1003}
1004#endif
1005
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001006static int nl80211_send_coalesce(struct sk_buff *msg,
1007 struct cfg80211_registered_device *dev)
1008{
1009 struct nl80211_coalesce_rule_support rule;
1010
1011 if (!dev->wiphy.coalesce)
1012 return 0;
1013
1014 rule.max_rules = dev->wiphy.coalesce->n_rules;
1015 rule.max_delay = dev->wiphy.coalesce->max_delay;
1016 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1017 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1018 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1019 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1020
1021 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1022 return -ENOBUFS;
1023
1024 return 0;
1025}
1026
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1028 struct ieee80211_supported_band *sband)
1029{
1030 struct nlattr *nl_rates, *nl_rate;
1031 struct ieee80211_rate *rate;
1032 int i;
1033
1034 /* add HT info */
1035 if (sband->ht_cap.ht_supported &&
1036 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1037 sizeof(sband->ht_cap.mcs),
1038 &sband->ht_cap.mcs) ||
1039 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1040 sband->ht_cap.cap) ||
1041 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1042 sband->ht_cap.ampdu_factor) ||
1043 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1044 sband->ht_cap.ampdu_density)))
1045 return -ENOBUFS;
1046
1047 /* add VHT info */
1048 if (sband->vht_cap.vht_supported &&
1049 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1050 sizeof(sband->vht_cap.vht_mcs),
1051 &sband->vht_cap.vht_mcs) ||
1052 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1053 sband->vht_cap.cap)))
1054 return -ENOBUFS;
1055
1056 /* add bitrates */
1057 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1058 if (!nl_rates)
1059 return -ENOBUFS;
1060
1061 for (i = 0; i < sband->n_bitrates; i++) {
1062 nl_rate = nla_nest_start(msg, i);
1063 if (!nl_rate)
1064 return -ENOBUFS;
1065
1066 rate = &sband->bitrates[i];
1067 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1068 rate->bitrate))
1069 return -ENOBUFS;
1070 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1071 nla_put_flag(msg,
1072 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1073 return -ENOBUFS;
1074
1075 nla_nest_end(msg, nl_rate);
1076 }
1077
1078 nla_nest_end(msg, nl_rates);
1079
1080 return 0;
1081}
1082
1083static int
1084nl80211_send_mgmt_stypes(struct sk_buff *msg,
1085 const struct ieee80211_txrx_stypes *mgmt_stypes)
1086{
1087 u16 stypes;
1088 struct nlattr *nl_ftypes, *nl_ifs;
1089 enum nl80211_iftype ift;
1090 int i;
1091
1092 if (!mgmt_stypes)
1093 return 0;
1094
1095 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1096 if (!nl_ifs)
1097 return -ENOBUFS;
1098
1099 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1100 nl_ftypes = nla_nest_start(msg, ift);
1101 if (!nl_ftypes)
1102 return -ENOBUFS;
1103 i = 0;
1104 stypes = mgmt_stypes[ift].tx;
1105 while (stypes) {
1106 if ((stypes & 1) &&
1107 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1108 (i << 4) | IEEE80211_FTYPE_MGMT))
1109 return -ENOBUFS;
1110 stypes >>= 1;
1111 i++;
1112 }
1113 nla_nest_end(msg, nl_ftypes);
1114 }
1115
1116 nla_nest_end(msg, nl_ifs);
1117
1118 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1119 if (!nl_ifs)
1120 return -ENOBUFS;
1121
1122 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1123 nl_ftypes = nla_nest_start(msg, ift);
1124 if (!nl_ftypes)
1125 return -ENOBUFS;
1126 i = 0;
1127 stypes = mgmt_stypes[ift].rx;
1128 while (stypes) {
1129 if ((stypes & 1) &&
1130 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1131 (i << 4) | IEEE80211_FTYPE_MGMT))
1132 return -ENOBUFS;
1133 stypes >>= 1;
1134 i++;
1135 }
1136 nla_nest_end(msg, nl_ftypes);
1137 }
1138 nla_nest_end(msg, nl_ifs);
1139
1140 return 0;
1141}
1142
Johannes Berg86e8cf92013-06-19 10:57:22 +02001143struct nl80211_dump_wiphy_state {
1144 s64 filter_wiphy;
1145 long start;
1146 long split_start, band_start, chan_start;
1147 bool split;
1148};
1149
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1151 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001152 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001153{
1154 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001155 struct nlattr *nl_bands, *nl_band;
1156 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001157 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001158 enum ieee80211_band band;
1159 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001160 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001161 const struct ieee80211_txrx_stypes *mgmt_stypes =
1162 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001163 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001164
Eric W. Biederman15e47302012-09-07 20:12:54 +00001165 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001166 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001167 return -ENOBUFS;
1168
Johannes Berg86e8cf92013-06-19 10:57:22 +02001169 if (WARN_ON(!state))
1170 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001171
David S. Miller9360ffd2012-03-29 04:41:26 -04001172 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1174 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001177 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001178
Johannes Berg86e8cf92013-06-19 10:57:22 +02001179 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001180 case 0:
1181 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1182 dev->wiphy.retry_short) ||
1183 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1184 dev->wiphy.retry_long) ||
1185 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1186 dev->wiphy.frag_threshold) ||
1187 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1188 dev->wiphy.rts_threshold) ||
1189 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1190 dev->wiphy.coverage_class) ||
1191 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1192 dev->wiphy.max_scan_ssids) ||
1193 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1194 dev->wiphy.max_sched_scan_ssids) ||
1195 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1196 dev->wiphy.max_scan_ie_len) ||
1197 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1198 dev->wiphy.max_sched_scan_ie_len) ||
1199 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1200 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001201 goto nla_put_failure;
1202
Johannes Berg3713b4e2013-02-14 16:19:38 +01001203 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1204 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1205 goto nla_put_failure;
1206 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1213 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1216 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001220 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001221 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1222 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1223 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001224
Johannes Berg86e8cf92013-06-19 10:57:22 +02001225 state->split_start++;
1226 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001227 break;
1228 case 1:
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001232 goto nla_put_failure;
1233
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001236 goto nla_put_failure;
1237
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1257 int res;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1259 if (!res) {
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1262 tx_ant) ||
1263 nla_put_u32(msg,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1265 rx_ant))
1266 goto nla_put_failure;
1267 }
Johannes Bergee688b002008-01-24 19:38:39 +01001268 }
1269
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270 state->split_start++;
1271 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 break;
1273 case 2:
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001277 state->split_start++;
1278 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 break;
1280 case 3:
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1282 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Johannes Berg86e8cf92013-06-19 10:57:22 +02001285 for (band = state->band_start;
1286 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 struct ieee80211_supported_band *sband;
1288
1289 sband = dev->wiphy.bands[band];
1290
1291 if (!sband)
1292 continue;
1293
1294 nl_band = nla_nest_start(msg, band);
1295 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001296 goto nla_put_failure;
1297
Johannes Berg86e8cf92013-06-19 10:57:22 +02001298 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 case 0:
1300 if (nl80211_send_band_rateinfo(msg, sband))
1301 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001302 state->chan_start++;
1303 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 break;
1305 default:
1306 /* add frequencies */
1307 nl_freqs = nla_nest_start(
1308 msg, NL80211_BAND_ATTR_FREQS);
1309 if (!nl_freqs)
1310 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001311
Johannes Berg86e8cf92013-06-19 10:57:22 +02001312 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 i < sband->n_channels;
1314 i++) {
1315 nl_freq = nla_nest_start(msg, i);
1316 if (!nl_freq)
1317 goto nla_put_failure;
1318
1319 chan = &sband->channels[i];
1320
Johannes Berg86e8cf92013-06-19 10:57:22 +02001321 if (nl80211_msg_put_channel(
1322 msg, chan,
1323 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 goto nla_put_failure;
1325
1326 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 break;
1329 }
1330 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001333 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 nla_nest_end(msg, nl_freqs);
1335 }
1336
1337 nla_nest_end(msg, nl_band);
1338
Johannes Berg86e8cf92013-06-19 10:57:22 +02001339 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 band--;
1343 break;
1344 }
Johannes Bergee688b002008-01-24 19:38:39 +01001345 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001347
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001349 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001351 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001352
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 if (state->band_start == 0 && state->chan_start == 0)
1355 state->split_start++;
1356 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 break;
1358 case 4:
1359 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1360 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001361 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362
1363 i = 0;
1364#define CMD(op, n) \
1365 do { \
1366 if (dev->ops->op) { \
1367 i++; \
1368 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1369 goto nla_put_failure; \
1370 } \
1371 } while (0)
1372
1373 CMD(add_virtual_intf, NEW_INTERFACE);
1374 CMD(change_virtual_intf, SET_INTERFACE);
1375 CMD(add_key, NEW_KEY);
1376 CMD(start_ap, START_AP);
1377 CMD(add_station, NEW_STATION);
1378 CMD(add_mpath, NEW_MPATH);
1379 CMD(update_mesh_config, SET_MESH_CONFIG);
1380 CMD(change_bss, SET_BSS);
1381 CMD(auth, AUTHENTICATE);
1382 CMD(assoc, ASSOCIATE);
1383 CMD(deauth, DEAUTHENTICATE);
1384 CMD(disassoc, DISASSOCIATE);
1385 CMD(join_ibss, JOIN_IBSS);
1386 CMD(join_mesh, JOIN_MESH);
1387 CMD(set_pmksa, SET_PMKSA);
1388 CMD(del_pmksa, DEL_PMKSA);
1389 CMD(flush_pmksa, FLUSH_PMKSA);
1390 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1391 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1392 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1393 CMD(mgmt_tx, FRAME);
1394 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1395 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1396 i++;
1397 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1398 goto nla_put_failure;
1399 }
1400 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1401 dev->ops->join_mesh) {
1402 i++;
1403 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1404 goto nla_put_failure;
1405 }
1406 CMD(set_wds_peer, SET_WDS_PEER);
1407 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1408 CMD(tdls_mgmt, TDLS_MGMT);
1409 CMD(tdls_oper, TDLS_OPER);
1410 }
1411 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1412 CMD(sched_scan_start, START_SCHED_SCAN);
1413 CMD(probe_client, PROBE_CLIENT);
1414 CMD(set_noack_map, SET_NOACK_MAP);
1415 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1416 i++;
1417 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1418 goto nla_put_failure;
1419 }
1420 CMD(start_p2p_device, START_P2P_DEVICE);
1421 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001423 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1424 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1425 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001426
Kalle Valo4745fc02011-11-17 19:06:10 +02001427#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001429#endif
1430
Johannes Berg8fdc6212009-03-14 09:34:01 +01001431#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 if (dev->ops->connect || dev->ops->auth) {
1434 i++;
1435 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f782010-08-12 15:38:38 +02001436 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001437 }
1438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 if (dev->ops->disconnect || dev->ops->deauth) {
1440 i++;
1441 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1442 goto nla_put_failure;
1443 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001444
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 state->split_start++;
1447 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 break;
1449 case 5:
1450 if (dev->ops->remain_on_channel &&
1451 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1452 nla_put_u32(msg,
1453 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1454 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001455 goto nla_put_failure;
1456
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1458 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1459 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001460
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1462 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001463 state->split_start++;
1464 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 break;
1466 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001467#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001470 state->split_start++;
1471 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 break;
1473#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001474 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475#endif
1476 case 7:
1477 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1478 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001479 goto nla_put_failure;
1480
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1482 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001484
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->split_start++;
1486 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 break;
1488 case 8:
1489 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1490 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1491 dev->wiphy.ap_sme_capa))
1492 goto nla_put_failure;
1493
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001494 features = dev->wiphy.features;
1495 /*
1496 * We can only add the per-channel limit information if the
1497 * dump is split, otherwise it makes it too big. Therefore
1498 * only advertise it in that case.
1499 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001500 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001501 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1502 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 goto nla_put_failure;
1504
1505 if (dev->wiphy.ht_capa_mod_mask &&
1506 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1507 sizeof(*dev->wiphy.ht_capa_mod_mask),
1508 dev->wiphy.ht_capa_mod_mask))
1509 goto nla_put_failure;
1510
1511 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1512 dev->wiphy.max_acl_mac_addrs &&
1513 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1514 dev->wiphy.max_acl_mac_addrs))
1515 goto nla_put_failure;
1516
1517 /*
1518 * Any information below this point is only available to
1519 * applications that can deal with it being split. This
1520 * helps ensure that newly added capabilities don't break
1521 * older tools by overrunning their buffers.
1522 *
1523 * We still increment split_start so that in the split
1524 * case we'll continue with more data in the next round,
1525 * but break unconditionally so unsplit data stops here.
1526 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 break;
1529 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001530 if (dev->wiphy.extended_capabilities &&
1531 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1532 dev->wiphy.extended_capabilities_len,
1533 dev->wiphy.extended_capabilities) ||
1534 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1535 dev->wiphy.extended_capabilities_len,
1536 dev->wiphy.extended_capabilities_mask)))
1537 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538
Johannes Bergee2aca32013-02-21 17:36:01 +01001539 if (dev->wiphy.vht_capa_mod_mask &&
1540 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1541 sizeof(*dev->wiphy.vht_capa_mod_mask),
1542 dev->wiphy.vht_capa_mod_mask))
1543 goto nla_put_failure;
1544
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001545 state->split_start++;
1546 break;
1547 case 10:
1548 if (nl80211_send_coalesce(msg, dev))
1549 goto nla_put_failure;
1550
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001554 }
Johannes Berg55682962007-09-20 13:09:35 -04001555 return genlmsg_end(msg, hdr);
1556
1557 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001558 genlmsg_cancel(msg, hdr);
1559 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001560}
1561
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1563 struct netlink_callback *cb,
1564 struct nl80211_dump_wiphy_state *state)
1565{
1566 struct nlattr **tb = nl80211_fam.attrbuf;
1567 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1568 tb, nl80211_fam.maxattr, nl80211_policy);
1569 /* ignore parse errors for backward compatibility */
1570 if (ret)
1571 return 0;
1572
1573 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1574 if (tb[NL80211_ATTR_WIPHY])
1575 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1576 if (tb[NL80211_ATTR_WDEV])
1577 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1578 if (tb[NL80211_ATTR_IFINDEX]) {
1579 struct net_device *netdev;
1580 struct cfg80211_registered_device *rdev;
1581 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1582
1583 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1584 if (!netdev)
1585 return -ENODEV;
1586 if (netdev->ieee80211_ptr) {
1587 rdev = wiphy_to_dev(
1588 netdev->ieee80211_ptr->wiphy);
1589 state->filter_wiphy = rdev->wiphy_idx;
1590 }
1591 dev_put(netdev);
1592 }
1593
1594 return 0;
1595}
1596
Johannes Berg55682962007-09-20 13:09:35 -04001597static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1598{
Johannes Berg645e77d2013-03-01 14:03:49 +01001599 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001600 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001601 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001602
Johannes Berg5fe231e2013-05-08 21:45:15 +02001603 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001604 if (!state) {
1605 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001606 if (!state) {
1607 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001610 state->filter_wiphy = -1;
1611 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1612 if (ret) {
1613 kfree(state);
1614 rtnl_unlock();
1615 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 }
1619
Johannes Berg79c97e92009-07-07 03:56:12 +02001620 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001621 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1622 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001624 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001625 if (state->filter_wiphy != -1 &&
1626 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 continue;
1628 /* attempt to fit multiple wiphy data chunks into the skb */
1629 do {
1630 ret = nl80211_send_wiphy(dev, skb,
1631 NETLINK_CB(cb->skb).portid,
1632 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001633 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 if (ret < 0) {
1635 /*
1636 * If sending the wiphy data didn't fit (ENOBUFS
1637 * or EMSGSIZE returned), this SKB is still
1638 * empty (so it's not too big because another
1639 * wiphy dataset is already in the skb) and
1640 * we've not tried to adjust the dump allocation
1641 * yet ... then adjust the alloc size to be
1642 * bigger, and return 1 but with the empty skb.
1643 * This results in an empty message being RX'ed
1644 * in userspace, but that is ignored.
1645 *
1646 * We can then retry with the larger buffer.
1647 */
1648 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1649 !skb->len &&
1650 cb->min_dump_alloc < 4096) {
1651 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001652 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001653 return 1;
1654 }
1655 idx--;
1656 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001657 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001658 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 break;
Johannes Berg55682962007-09-20 13:09:35 -04001660 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001661 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001662
Johannes Berg86e8cf92013-06-19 10:57:22 +02001663 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001664
1665 return skb->len;
1666}
1667
Johannes Berg86e8cf92013-06-19 10:57:22 +02001668static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1669{
1670 kfree((void *)cb->args[0]);
1671 return 0;
1672}
1673
Johannes Berg55682962007-09-20 13:09:35 -04001674static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1675{
1676 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001677 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001678 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001679
Johannes Berg645e77d2013-03-01 14:03:49 +01001680 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001681 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001682 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001683
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001686 nlmsg_free(msg);
1687 return -ENOBUFS;
1688 }
Johannes Berg55682962007-09-20 13:09:35 -04001689
Johannes Berg134e6372009-07-10 09:51:34 +00001690 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001691}
1692
Jouni Malinen31888482008-10-30 16:59:24 +02001693static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1694 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1695 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1696 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1697 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1698 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1699};
1700
1701static int parse_txq_params(struct nlattr *tb[],
1702 struct ieee80211_txq_params *txq_params)
1703{
Johannes Berga3304b02012-03-28 11:04:24 +02001704 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001705 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1706 !tb[NL80211_TXQ_ATTR_AIFS])
1707 return -EINVAL;
1708
Johannes Berga3304b02012-03-28 11:04:24 +02001709 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001710 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1711 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1712 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1713 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1714
Johannes Berga3304b02012-03-28 11:04:24 +02001715 if (txq_params->ac >= NL80211_NUM_ACS)
1716 return -EINVAL;
1717
Jouni Malinen31888482008-10-30 16:59:24 +02001718 return 0;
1719}
1720
Johannes Bergf444de02010-05-05 15:25:02 +02001721static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1722{
1723 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001724 * You can only set the channel explicitly for WDS interfaces,
1725 * all others have their channel managed via their respective
1726 * "establish a connection" command (connect, join, ...)
1727 *
1728 * For AP/GO and mesh mode, the channel can be set with the
1729 * channel userspace API, but is only stored and passed to the
1730 * low-level driver when the AP starts or the mesh is joined.
1731 * This is for backward compatibility, userspace can also give
1732 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001733 *
1734 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001735 * whatever else is going on, so they have their own special
1736 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001737 */
1738 return !wdev ||
1739 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001740 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001741 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1742 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001743}
1744
Johannes Berg683b6d32012-11-08 21:25:48 +01001745static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1746 struct genl_info *info,
1747 struct cfg80211_chan_def *chandef)
1748{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301749 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001750
1751 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1752 return -EINVAL;
1753
1754 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1755
1756 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001757 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1758 chandef->center_freq1 = control_freq;
1759 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001760
1761 /* Primary channel not allowed */
1762 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1763 return -EINVAL;
1764
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001765 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1766 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001767
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001768 chantype = nla_get_u32(
1769 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1770
1771 switch (chantype) {
1772 case NL80211_CHAN_NO_HT:
1773 case NL80211_CHAN_HT20:
1774 case NL80211_CHAN_HT40PLUS:
1775 case NL80211_CHAN_HT40MINUS:
1776 cfg80211_chandef_create(chandef, chandef->chan,
1777 chantype);
1778 break;
1779 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001780 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001781 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001782 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1783 chandef->width =
1784 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1785 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1786 chandef->center_freq1 =
1787 nla_get_u32(
1788 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1789 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1790 chandef->center_freq2 =
1791 nla_get_u32(
1792 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1793 }
1794
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001795 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001796 return -EINVAL;
1797
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001798 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1799 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001800 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001801
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001802 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1803 chandef->width == NL80211_CHAN_WIDTH_10) &&
1804 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1805 return -EINVAL;
1806
Johannes Berg683b6d32012-11-08 21:25:48 +01001807 return 0;
1808}
1809
Johannes Bergf444de02010-05-05 15:25:02 +02001810static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1811 struct wireless_dev *wdev,
1812 struct genl_info *info)
1813{
Johannes Berg683b6d32012-11-08 21:25:48 +01001814 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001815 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001816 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1817
1818 if (wdev)
1819 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001820
Johannes Bergf444de02010-05-05 15:25:02 +02001821 if (!nl80211_can_set_dev_channel(wdev))
1822 return -EOPNOTSUPP;
1823
Johannes Berg683b6d32012-11-08 21:25:48 +01001824 result = nl80211_parse_chandef(rdev, info, &chandef);
1825 if (result)
1826 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001827
Johannes Berge8c9bd52012-06-06 08:18:22 +02001828 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001829 case NL80211_IFTYPE_AP:
1830 case NL80211_IFTYPE_P2P_GO:
1831 if (wdev->beacon_interval) {
1832 result = -EBUSY;
1833 break;
1834 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001835 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001836 result = -EINVAL;
1837 break;
1838 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001839 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001840 result = 0;
1841 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001842 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001843 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001844 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001845 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001846 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001847 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001848 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001849 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001850 }
Johannes Bergf444de02010-05-05 15:25:02 +02001851
1852 return result;
1853}
1854
1855static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1856{
Johannes Berg4c476992010-10-04 21:36:35 +02001857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1858 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001859
Johannes Berg4c476992010-10-04 21:36:35 +02001860 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001861}
1862
Bill Jordane8347eb2010-10-01 13:54:28 -04001863static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1864{
Johannes Berg43b19952010-10-07 13:10:30 +02001865 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1866 struct net_device *dev = info->user_ptr[1];
1867 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001868 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001869
1870 if (!info->attrs[NL80211_ATTR_MAC])
1871 return -EINVAL;
1872
Johannes Berg43b19952010-10-07 13:10:30 +02001873 if (netif_running(dev))
1874 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001875
Johannes Berg43b19952010-10-07 13:10:30 +02001876 if (!rdev->ops->set_wds_peer)
1877 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001878
Johannes Berg43b19952010-10-07 13:10:30 +02001879 if (wdev->iftype != NL80211_IFTYPE_WDS)
1880 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001881
1882 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001883 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001884}
1885
1886
Johannes Berg55682962007-09-20 13:09:35 -04001887static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1888{
1889 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001890 struct net_device *netdev = NULL;
1891 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001892 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001893 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001894 u32 changed;
1895 u8 retry_short = 0, retry_long = 0;
1896 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001897 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001898
Johannes Berg5fe231e2013-05-08 21:45:15 +02001899 ASSERT_RTNL();
1900
Johannes Bergf444de02010-05-05 15:25:02 +02001901 /*
1902 * Try to find the wiphy and netdev. Normally this
1903 * function shouldn't need the netdev, but this is
1904 * done for backward compatibility -- previously
1905 * setting the channel was done per wiphy, but now
1906 * it is per netdev. Previous userland like hostapd
1907 * also passed a netdev to set_wiphy, so that it is
1908 * possible to let that go to the right netdev!
1909 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001910
Johannes Bergf444de02010-05-05 15:25:02 +02001911 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1912 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1913
1914 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001915 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001916 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001917 else
Johannes Bergf444de02010-05-05 15:25:02 +02001918 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001919 }
1920
Johannes Bergf444de02010-05-05 15:25:02 +02001921 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001922 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1923 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001924 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001925 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001926 wdev = NULL;
1927 netdev = NULL;
1928 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001929 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001930 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001931
1932 /*
1933 * end workaround code, by now the rdev is available
1934 * and locked, and wdev may or may not be NULL.
1935 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001936
1937 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001938 result = cfg80211_dev_rename(
1939 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001940
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001941 if (result)
1942 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001943
Jouni Malinen31888482008-10-30 16:59:24 +02001944 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1945 struct ieee80211_txq_params txq_params;
1946 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1947
1948 if (!rdev->ops->set_txq_params) {
1949 result = -EOPNOTSUPP;
1950 goto bad_res;
1951 }
1952
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001953 if (!netdev) {
1954 result = -EINVAL;
1955 goto bad_res;
1956 }
1957
Johannes Berg133a3ff2011-11-03 14:50:13 +01001958 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1959 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1960 result = -EINVAL;
1961 goto bad_res;
1962 }
1963
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001964 if (!netif_running(netdev)) {
1965 result = -ENETDOWN;
1966 goto bad_res;
1967 }
1968
Jouni Malinen31888482008-10-30 16:59:24 +02001969 nla_for_each_nested(nl_txq_params,
1970 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1971 rem_txq_params) {
1972 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1973 nla_data(nl_txq_params),
1974 nla_len(nl_txq_params),
1975 txq_params_policy);
1976 result = parse_txq_params(tb, &txq_params);
1977 if (result)
1978 goto bad_res;
1979
Hila Gonene35e4d22012-06-27 17:19:42 +03001980 result = rdev_set_txq_params(rdev, netdev,
1981 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001982 if (result)
1983 goto bad_res;
1984 }
1985 }
1986
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001987 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001988 result = __nl80211_set_channel(rdev,
1989 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1990 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001991 if (result)
1992 goto bad_res;
1993 }
1994
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001995 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001996 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001997 enum nl80211_tx_power_setting type;
1998 int idx, mbm = 0;
1999
Johannes Bergc8442112012-10-24 10:17:18 +02002000 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2001 txp_wdev = NULL;
2002
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002003 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002004 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002005 goto bad_res;
2006 }
2007
2008 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2009 type = nla_get_u32(info->attrs[idx]);
2010
2011 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2012 (type != NL80211_TX_POWER_AUTOMATIC)) {
2013 result = -EINVAL;
2014 goto bad_res;
2015 }
2016
2017 if (type != NL80211_TX_POWER_AUTOMATIC) {
2018 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2019 mbm = nla_get_u32(info->attrs[idx]);
2020 }
2021
Johannes Bergc8442112012-10-24 10:17:18 +02002022 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002023 if (result)
2024 goto bad_res;
2025 }
2026
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002027 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2028 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2029 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002030 if ((!rdev->wiphy.available_antennas_tx &&
2031 !rdev->wiphy.available_antennas_rx) ||
2032 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002033 result = -EOPNOTSUPP;
2034 goto bad_res;
2035 }
2036
2037 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2038 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2039
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002040 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002041 * available antenna masks, except for the "all" mask */
2042 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2043 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002044 result = -EINVAL;
2045 goto bad_res;
2046 }
2047
Bruno Randolf7f531e02010-12-16 11:30:22 +09002048 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2049 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002050
Hila Gonene35e4d22012-06-27 17:19:42 +03002051 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002052 if (result)
2053 goto bad_res;
2054 }
2055
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056 changed = 0;
2057
2058 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2059 retry_short = nla_get_u8(
2060 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2061 if (retry_short == 0) {
2062 result = -EINVAL;
2063 goto bad_res;
2064 }
2065 changed |= WIPHY_PARAM_RETRY_SHORT;
2066 }
2067
2068 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2069 retry_long = nla_get_u8(
2070 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2071 if (retry_long == 0) {
2072 result = -EINVAL;
2073 goto bad_res;
2074 }
2075 changed |= WIPHY_PARAM_RETRY_LONG;
2076 }
2077
2078 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2079 frag_threshold = nla_get_u32(
2080 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2081 if (frag_threshold < 256) {
2082 result = -EINVAL;
2083 goto bad_res;
2084 }
2085 if (frag_threshold != (u32) -1) {
2086 /*
2087 * Fragments (apart from the last one) are required to
2088 * have even length. Make the fragmentation code
2089 * simpler by stripping LSB should someone try to use
2090 * odd threshold value.
2091 */
2092 frag_threshold &= ~0x1;
2093 }
2094 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2095 }
2096
2097 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2098 rts_threshold = nla_get_u32(
2099 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2100 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2101 }
2102
Lukáš Turek81077e82009-12-21 22:50:47 +01002103 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2104 coverage_class = nla_get_u8(
2105 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2106 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2107 }
2108
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002109 if (changed) {
2110 u8 old_retry_short, old_retry_long;
2111 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002112 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002113
2114 if (!rdev->ops->set_wiphy_params) {
2115 result = -EOPNOTSUPP;
2116 goto bad_res;
2117 }
2118
2119 old_retry_short = rdev->wiphy.retry_short;
2120 old_retry_long = rdev->wiphy.retry_long;
2121 old_frag_threshold = rdev->wiphy.frag_threshold;
2122 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002123 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002124
2125 if (changed & WIPHY_PARAM_RETRY_SHORT)
2126 rdev->wiphy.retry_short = retry_short;
2127 if (changed & WIPHY_PARAM_RETRY_LONG)
2128 rdev->wiphy.retry_long = retry_long;
2129 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2130 rdev->wiphy.frag_threshold = frag_threshold;
2131 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2132 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002133 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2134 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002135
Hila Gonene35e4d22012-06-27 17:19:42 +03002136 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002137 if (result) {
2138 rdev->wiphy.retry_short = old_retry_short;
2139 rdev->wiphy.retry_long = old_retry_long;
2140 rdev->wiphy.frag_threshold = old_frag_threshold;
2141 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002142 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002143 }
2144 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002145
Johannes Berg306d6112008-12-08 12:39:04 +01002146 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002147 if (netdev)
2148 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002149 return result;
2150}
2151
Johannes Berg71bbc992012-06-15 15:30:18 +02002152static inline u64 wdev_id(struct wireless_dev *wdev)
2153{
2154 return (u64)wdev->identifier |
2155 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2156}
Johannes Berg55682962007-09-20 13:09:35 -04002157
Johannes Berg683b6d32012-11-08 21:25:48 +01002158static int nl80211_send_chandef(struct sk_buff *msg,
2159 struct cfg80211_chan_def *chandef)
2160{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002161 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002162
Johannes Berg683b6d32012-11-08 21:25:48 +01002163 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2164 chandef->chan->center_freq))
2165 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002166 switch (chandef->width) {
2167 case NL80211_CHAN_WIDTH_20_NOHT:
2168 case NL80211_CHAN_WIDTH_20:
2169 case NL80211_CHAN_WIDTH_40:
2170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2171 cfg80211_get_chandef_type(chandef)))
2172 return -ENOBUFS;
2173 break;
2174 default:
2175 break;
2176 }
2177 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2178 return -ENOBUFS;
2179 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2180 return -ENOBUFS;
2181 if (chandef->center_freq2 &&
2182 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002183 return -ENOBUFS;
2184 return 0;
2185}
2186
Eric W. Biederman15e47302012-09-07 20:12:54 +00002187static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002188 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002189 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002190{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002191 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002192 void *hdr;
2193
Eric W. Biederman15e47302012-09-07 20:12:54 +00002194 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002195 if (!hdr)
2196 return -1;
2197
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002198 if (dev &&
2199 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002200 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002201 goto nla_put_failure;
2202
2203 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2204 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002205 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002207 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2208 rdev->devlist_generation ^
2209 (cfg80211_rdev_list_generation << 2)))
2210 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002211
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002212 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002213 int ret;
2214 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002215
Johannes Berg683b6d32012-11-08 21:25:48 +01002216 ret = rdev_get_channel(rdev, wdev, &chandef);
2217 if (ret == 0) {
2218 if (nl80211_send_chandef(msg, &chandef))
2219 goto nla_put_failure;
2220 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002221 }
2222
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002223 if (wdev->ssid_len) {
2224 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2225 goto nla_put_failure;
2226 }
2227
Johannes Berg55682962007-09-20 13:09:35 -04002228 return genlmsg_end(msg, hdr);
2229
2230 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002231 genlmsg_cancel(msg, hdr);
2232 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002233}
2234
2235static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2236{
2237 int wp_idx = 0;
2238 int if_idx = 0;
2239 int wp_start = cb->args[0];
2240 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002241 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002242 struct wireless_dev *wdev;
2243
Johannes Berg5fe231e2013-05-08 21:45:15 +02002244 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002245 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2246 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002247 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002248 if (wp_idx < wp_start) {
2249 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002250 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002251 }
Johannes Berg55682962007-09-20 13:09:35 -04002252 if_idx = 0;
2253
Johannes Berg89a54e42012-06-15 14:33:17 +02002254 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002255 if (if_idx < if_start) {
2256 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002257 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002258 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002259 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002260 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002261 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 goto out;
2263 }
2264 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002265 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002266
2267 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002268 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002270 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002271
2272 cb->args[0] = wp_idx;
2273 cb->args[1] = if_idx;
2274
2275 return skb->len;
2276}
2277
2278static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2279{
2280 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002281 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002282 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002283
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002285 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002286 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002287
Eric W. Biederman15e47302012-09-07 20:12:54 +00002288 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002289 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002290 nlmsg_free(msg);
2291 return -ENOBUFS;
2292 }
Johannes Berg55682962007-09-20 13:09:35 -04002293
Johannes Berg134e6372009-07-10 09:51:34 +00002294 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002295}
2296
Michael Wu66f7ac52008-01-31 19:48:22 +01002297static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2298 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2299 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2300 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2301 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2302 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002303 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002304};
2305
2306static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2307{
2308 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2309 int flag;
2310
2311 *mntrflags = 0;
2312
2313 if (!nla)
2314 return -EINVAL;
2315
2316 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2317 nla, mntr_flags_policy))
2318 return -EINVAL;
2319
2320 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2321 if (flags[flag])
2322 *mntrflags |= (1<<flag);
2323
2324 return 0;
2325}
2326
Johannes Berg9bc383d2009-11-19 11:55:19 +01002327static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002328 struct net_device *netdev, u8 use_4addr,
2329 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002330{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002331 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002332 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002333 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002334 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002335 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002336
2337 switch (iftype) {
2338 case NL80211_IFTYPE_AP_VLAN:
2339 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2340 return 0;
2341 break;
2342 case NL80211_IFTYPE_STATION:
2343 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2344 return 0;
2345 break;
2346 default:
2347 break;
2348 }
2349
2350 return -EOPNOTSUPP;
2351}
2352
Johannes Berg55682962007-09-20 13:09:35 -04002353static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2354{
Johannes Berg4c476992010-10-04 21:36:35 +02002355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002356 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002357 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002358 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002359 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002360 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002361 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002362
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002363 memset(&params, 0, sizeof(params));
2364
Johannes Berg04a773a2009-04-19 21:24:32 +02002365 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002366
Johannes Berg723b0382008-09-16 20:22:09 +02002367 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002368 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002369 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002370 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002371 if (ntype > NL80211_IFTYPE_MAX)
2372 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002373 }
2374
Johannes Berg92ffe052008-09-16 20:39:36 +02002375 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002376 struct wireless_dev *wdev = dev->ieee80211_ptr;
2377
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (ntype != NL80211_IFTYPE_MESH_POINT)
2379 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002380 if (netif_running(dev))
2381 return -EBUSY;
2382
2383 wdev_lock(wdev);
2384 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2385 IEEE80211_MAX_MESH_ID_LEN);
2386 wdev->mesh_id_up_len =
2387 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2388 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2389 wdev->mesh_id_up_len);
2390 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002391 }
2392
Felix Fietkau8b787642009-11-10 18:53:10 +01002393 if (info->attrs[NL80211_ATTR_4ADDR]) {
2394 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2395 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002396 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002397 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002398 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002399 } else {
2400 params.use_4addr = -1;
2401 }
2402
Johannes Berg92ffe052008-09-16 20:39:36 +02002403 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002404 if (ntype != NL80211_IFTYPE_MONITOR)
2405 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002406 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2407 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002408 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002409 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002410
2411 flags = &_flags;
2412 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002413 }
Johannes Berg3b858752009-03-12 09:55:09 +01002414
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002415 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2416 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2417 return -EOPNOTSUPP;
2418
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002419 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002420 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002421 else
2422 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002423
Johannes Berg9bc383d2009-11-19 11:55:19 +01002424 if (!err && params.use_4addr != -1)
2425 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2426
Johannes Berg55682962007-09-20 13:09:35 -04002427 return err;
2428}
2429
2430static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2431{
Johannes Berg4c476992010-10-04 21:36:35 +02002432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002433 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002434 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002435 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002436 int err;
2437 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002438 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002439
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002440 memset(&params, 0, sizeof(params));
2441
Johannes Berg55682962007-09-20 13:09:35 -04002442 if (!info->attrs[NL80211_ATTR_IFNAME])
2443 return -EINVAL;
2444
2445 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2446 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2447 if (type > NL80211_IFTYPE_MAX)
2448 return -EINVAL;
2449 }
2450
Johannes Berg79c97e92009-07-07 03:56:12 +02002451 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002452 !(rdev->wiphy.interface_modes & (1 << type)))
2453 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002454
Arend van Spriel1c18f142013-01-08 10:17:27 +01002455 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2456 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2457 ETH_ALEN);
2458 if (!is_valid_ether_addr(params.macaddr))
2459 return -EADDRNOTAVAIL;
2460 }
2461
Johannes Berg9bc383d2009-11-19 11:55:19 +01002462 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002463 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002464 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002465 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002466 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002467 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002468
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2470 if (!msg)
2471 return -ENOMEM;
2472
Michael Wu66f7ac52008-01-31 19:48:22 +01002473 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2474 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2475 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002476
2477 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2478 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2479 return -EOPNOTSUPP;
2480
Hila Gonene35e4d22012-06-27 17:19:42 +03002481 wdev = rdev_add_virtual_intf(rdev,
2482 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2483 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002484 if (IS_ERR(wdev)) {
2485 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002486 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002487 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002488
Johannes Berg98104fde2012-06-16 00:19:54 +02002489 switch (type) {
2490 case NL80211_IFTYPE_MESH_POINT:
2491 if (!info->attrs[NL80211_ATTR_MESH_ID])
2492 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002493 wdev_lock(wdev);
2494 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2495 IEEE80211_MAX_MESH_ID_LEN);
2496 wdev->mesh_id_up_len =
2497 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2498 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2499 wdev->mesh_id_up_len);
2500 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002501 break;
2502 case NL80211_IFTYPE_P2P_DEVICE:
2503 /*
2504 * P2P Device doesn't have a netdev, so doesn't go
2505 * through the netdev notifier and must be added here
2506 */
2507 mutex_init(&wdev->mtx);
2508 INIT_LIST_HEAD(&wdev->event_list);
2509 spin_lock_init(&wdev->event_lock);
2510 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2511 spin_lock_init(&wdev->mgmt_registrations_lock);
2512
Johannes Berg98104fde2012-06-16 00:19:54 +02002513 wdev->identifier = ++rdev->wdev_id;
2514 list_add_rcu(&wdev->list, &rdev->wdev_list);
2515 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002516 break;
2517 default:
2518 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002519 }
2520
Eric W. Biederman15e47302012-09-07 20:12:54 +00002521 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002522 rdev, wdev) < 0) {
2523 nlmsg_free(msg);
2524 return -ENOBUFS;
2525 }
2526
2527 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002528}
2529
2530static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2531{
Johannes Berg4c476992010-10-04 21:36:35 +02002532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002533 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002534
Johannes Berg4c476992010-10-04 21:36:35 +02002535 if (!rdev->ops->del_virtual_intf)
2536 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002537
Johannes Berg84efbb82012-06-16 00:00:26 +02002538 /*
2539 * If we remove a wireless device without a netdev then clear
2540 * user_ptr[1] so that nl80211_post_doit won't dereference it
2541 * to check if it needs to do dev_put(). Otherwise it crashes
2542 * since the wdev has been freed, unlike with a netdev where
2543 * we need the dev_put() for the netdev to really be freed.
2544 */
2545 if (!wdev->netdev)
2546 info->user_ptr[1] = NULL;
2547
Hila Gonene35e4d22012-06-27 17:19:42 +03002548 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002549}
2550
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002551static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2552{
2553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2554 struct net_device *dev = info->user_ptr[1];
2555 u16 noack_map;
2556
2557 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2558 return -EINVAL;
2559
2560 if (!rdev->ops->set_noack_map)
2561 return -EOPNOTSUPP;
2562
2563 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2564
Hila Gonene35e4d22012-06-27 17:19:42 +03002565 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002566}
2567
Johannes Berg41ade002007-12-19 02:03:29 +01002568struct get_key_cookie {
2569 struct sk_buff *msg;
2570 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002571 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002572};
2573
2574static void get_key_callback(void *c, struct key_params *params)
2575{
Johannes Bergb9454e82009-07-08 13:29:08 +02002576 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002577 struct get_key_cookie *cookie = c;
2578
David S. Miller9360ffd2012-03-29 04:41:26 -04002579 if ((params->key &&
2580 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2581 params->key_len, params->key)) ||
2582 (params->seq &&
2583 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2584 params->seq_len, params->seq)) ||
2585 (params->cipher &&
2586 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2587 params->cipher)))
2588 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002589
Johannes Bergb9454e82009-07-08 13:29:08 +02002590 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2591 if (!key)
2592 goto nla_put_failure;
2593
David S. Miller9360ffd2012-03-29 04:41:26 -04002594 if ((params->key &&
2595 nla_put(cookie->msg, NL80211_KEY_DATA,
2596 params->key_len, params->key)) ||
2597 (params->seq &&
2598 nla_put(cookie->msg, NL80211_KEY_SEQ,
2599 params->seq_len, params->seq)) ||
2600 (params->cipher &&
2601 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2602 params->cipher)))
2603 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002604
David S. Miller9360ffd2012-03-29 04:41:26 -04002605 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2606 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002607
2608 nla_nest_end(cookie->msg, key);
2609
Johannes Berg41ade002007-12-19 02:03:29 +01002610 return;
2611 nla_put_failure:
2612 cookie->error = 1;
2613}
2614
2615static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2616{
Johannes Berg4c476992010-10-04 21:36:35 +02002617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002618 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002619 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002620 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002621 const u8 *mac_addr = NULL;
2622 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002623 struct get_key_cookie cookie = {
2624 .error = 0,
2625 };
2626 void *hdr;
2627 struct sk_buff *msg;
2628
2629 if (info->attrs[NL80211_ATTR_KEY_IDX])
2630 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2631
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002632 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002633 return -EINVAL;
2634
2635 if (info->attrs[NL80211_ATTR_MAC])
2636 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2637
Johannes Berge31b8212010-10-05 19:39:30 +02002638 pairwise = !!mac_addr;
2639 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2640 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2641 if (kt >= NUM_NL80211_KEYTYPES)
2642 return -EINVAL;
2643 if (kt != NL80211_KEYTYPE_GROUP &&
2644 kt != NL80211_KEYTYPE_PAIRWISE)
2645 return -EINVAL;
2646 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2647 }
2648
Johannes Berg4c476992010-10-04 21:36:35 +02002649 if (!rdev->ops->get_key)
2650 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002651
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002652 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002653 if (!msg)
2654 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002655
Eric W. Biederman15e47302012-09-07 20:12:54 +00002656 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002657 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (IS_ERR(hdr))
2659 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002660
2661 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002662 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002663
David S. Miller9360ffd2012-03-29 04:41:26 -04002664 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2665 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2666 goto nla_put_failure;
2667 if (mac_addr &&
2668 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2669 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002670
Johannes Berge31b8212010-10-05 19:39:30 +02002671 if (pairwise && mac_addr &&
2672 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2673 return -ENOENT;
2674
Hila Gonene35e4d22012-06-27 17:19:42 +03002675 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2676 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002677
2678 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002679 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002680
2681 if (cookie.error)
2682 goto nla_put_failure;
2683
2684 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002685 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002686
2687 nla_put_failure:
2688 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002689 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002690 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002691 return err;
2692}
2693
2694static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2695{
Johannes Berg4c476992010-10-04 21:36:35 +02002696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002697 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002698 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002699 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002700
Johannes Bergb9454e82009-07-08 13:29:08 +02002701 err = nl80211_parse_key(info, &key);
2702 if (err)
2703 return err;
2704
2705 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002706 return -EINVAL;
2707
Johannes Bergb9454e82009-07-08 13:29:08 +02002708 /* only support setting default key */
2709 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002710 return -EINVAL;
2711
Johannes Bergfffd0932009-07-08 14:22:54 +02002712 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002713
2714 if (key.def) {
2715 if (!rdev->ops->set_default_key) {
2716 err = -EOPNOTSUPP;
2717 goto out;
2718 }
2719
2720 err = nl80211_key_allowed(dev->ieee80211_ptr);
2721 if (err)
2722 goto out;
2723
Hila Gonene35e4d22012-06-27 17:19:42 +03002724 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002725 key.def_uni, key.def_multi);
2726
2727 if (err)
2728 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002729
Johannes Berg3d23e342009-09-29 23:27:28 +02002730#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002731 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002732#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002733 } else {
2734 if (key.def_uni || !key.def_multi) {
2735 err = -EINVAL;
2736 goto out;
2737 }
2738
2739 if (!rdev->ops->set_default_mgmt_key) {
2740 err = -EOPNOTSUPP;
2741 goto out;
2742 }
2743
2744 err = nl80211_key_allowed(dev->ieee80211_ptr);
2745 if (err)
2746 goto out;
2747
Hila Gonene35e4d22012-06-27 17:19:42 +03002748 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002749 if (err)
2750 goto out;
2751
2752#ifdef CONFIG_CFG80211_WEXT
2753 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2754#endif
2755 }
2756
2757 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002758 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002759
Johannes Berg41ade002007-12-19 02:03:29 +01002760 return err;
2761}
2762
2763static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2764{
Johannes Berg4c476992010-10-04 21:36:35 +02002765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002767 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002768 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002769 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Johannes Bergb9454e82009-07-08 13:29:08 +02002771 err = nl80211_parse_key(info, &key);
2772 if (err)
2773 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002774
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002776 return -EINVAL;
2777
Johannes Berg41ade002007-12-19 02:03:29 +01002778 if (info->attrs[NL80211_ATTR_MAC])
2779 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2780
Johannes Berge31b8212010-10-05 19:39:30 +02002781 if (key.type == -1) {
2782 if (mac_addr)
2783 key.type = NL80211_KEYTYPE_PAIRWISE;
2784 else
2785 key.type = NL80211_KEYTYPE_GROUP;
2786 }
2787
2788 /* for now */
2789 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2790 key.type != NL80211_KEYTYPE_GROUP)
2791 return -EINVAL;
2792
Johannes Berg4c476992010-10-04 21:36:35 +02002793 if (!rdev->ops->add_key)
2794 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002795
Johannes Berge31b8212010-10-05 19:39:30 +02002796 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2797 key.type == NL80211_KEYTYPE_PAIRWISE,
2798 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002799 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002800
2801 wdev_lock(dev->ieee80211_ptr);
2802 err = nl80211_key_allowed(dev->ieee80211_ptr);
2803 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002804 err = rdev_add_key(rdev, dev, key.idx,
2805 key.type == NL80211_KEYTYPE_PAIRWISE,
2806 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002807 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002808
Johannes Berg41ade002007-12-19 02:03:29 +01002809 return err;
2810}
2811
2812static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2813{
Johannes Berg4c476992010-10-04 21:36:35 +02002814 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002815 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002816 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002817 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002819
Johannes Bergb9454e82009-07-08 13:29:08 +02002820 err = nl80211_parse_key(info, &key);
2821 if (err)
2822 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002823
2824 if (info->attrs[NL80211_ATTR_MAC])
2825 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2826
Johannes Berge31b8212010-10-05 19:39:30 +02002827 if (key.type == -1) {
2828 if (mac_addr)
2829 key.type = NL80211_KEYTYPE_PAIRWISE;
2830 else
2831 key.type = NL80211_KEYTYPE_GROUP;
2832 }
2833
2834 /* for now */
2835 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2836 key.type != NL80211_KEYTYPE_GROUP)
2837 return -EINVAL;
2838
Johannes Berg4c476992010-10-04 21:36:35 +02002839 if (!rdev->ops->del_key)
2840 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002841
Johannes Bergfffd0932009-07-08 14:22:54 +02002842 wdev_lock(dev->ieee80211_ptr);
2843 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002844
2845 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2846 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2847 err = -ENOENT;
2848
Johannes Bergfffd0932009-07-08 14:22:54 +02002849 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002850 err = rdev_del_key(rdev, dev, key.idx,
2851 key.type == NL80211_KEYTYPE_PAIRWISE,
2852 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002853
Johannes Berg3d23e342009-09-29 23:27:28 +02002854#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002855 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002856 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002857 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002858 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002859 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2860 }
2861#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002862 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002863
Johannes Berg41ade002007-12-19 02:03:29 +01002864 return err;
2865}
2866
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302867/* This function returns an error or the number of nested attributes */
2868static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2869{
2870 struct nlattr *attr;
2871 int n_entries = 0, tmp;
2872
2873 nla_for_each_nested(attr, nl_attr, tmp) {
2874 if (nla_len(attr) != ETH_ALEN)
2875 return -EINVAL;
2876
2877 n_entries++;
2878 }
2879
2880 return n_entries;
2881}
2882
2883/*
2884 * This function parses ACL information and allocates memory for ACL data.
2885 * On successful return, the calling function is responsible to free the
2886 * ACL buffer returned by this function.
2887 */
2888static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2889 struct genl_info *info)
2890{
2891 enum nl80211_acl_policy acl_policy;
2892 struct nlattr *attr;
2893 struct cfg80211_acl_data *acl;
2894 int i = 0, n_entries, tmp;
2895
2896 if (!wiphy->max_acl_mac_addrs)
2897 return ERR_PTR(-EOPNOTSUPP);
2898
2899 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2900 return ERR_PTR(-EINVAL);
2901
2902 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2903 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2904 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2905 return ERR_PTR(-EINVAL);
2906
2907 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2908 return ERR_PTR(-EINVAL);
2909
2910 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2911 if (n_entries < 0)
2912 return ERR_PTR(n_entries);
2913
2914 if (n_entries > wiphy->max_acl_mac_addrs)
2915 return ERR_PTR(-ENOTSUPP);
2916
2917 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2918 GFP_KERNEL);
2919 if (!acl)
2920 return ERR_PTR(-ENOMEM);
2921
2922 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2923 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2924 i++;
2925 }
2926
2927 acl->n_acl_entries = n_entries;
2928 acl->acl_policy = acl_policy;
2929
2930 return acl;
2931}
2932
2933static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2934{
2935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2936 struct net_device *dev = info->user_ptr[1];
2937 struct cfg80211_acl_data *acl;
2938 int err;
2939
2940 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2941 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2942 return -EOPNOTSUPP;
2943
2944 if (!dev->ieee80211_ptr->beacon_interval)
2945 return -EINVAL;
2946
2947 acl = parse_acl_data(&rdev->wiphy, info);
2948 if (IS_ERR(acl))
2949 return PTR_ERR(acl);
2950
2951 err = rdev_set_mac_acl(rdev, dev, acl);
2952
2953 kfree(acl);
2954
2955 return err;
2956}
2957
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002958static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002959 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002960{
Johannes Berg88600202012-02-13 15:17:18 +01002961 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002962
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002963 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2964 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2965 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2966 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002967 return -EINVAL;
2968
Johannes Berg88600202012-02-13 15:17:18 +01002969 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002970
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002971 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2972 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2973 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002974 if (!bcn->head_len)
2975 return -EINVAL;
2976 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002977 }
2978
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002979 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2980 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2981 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002982 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002983 }
2984
Johannes Berg4c476992010-10-04 21:36:35 +02002985 if (!haveinfo)
2986 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002987
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002988 if (attrs[NL80211_ATTR_IE]) {
2989 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2990 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002991 }
2992
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002993 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002994 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002995 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002996 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002997 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002998 }
2999
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003000 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003001 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003003 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003004 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003005 }
3006
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003007 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3008 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3009 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003010 }
3011
Johannes Berg88600202012-02-13 15:17:18 +01003012 return 0;
3013}
3014
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003015static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3016 struct cfg80211_ap_settings *params)
3017{
3018 struct wireless_dev *wdev;
3019 bool ret = false;
3020
Johannes Berg89a54e42012-06-15 14:33:17 +02003021 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003022 if (wdev->iftype != NL80211_IFTYPE_AP &&
3023 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3024 continue;
3025
Johannes Berg683b6d32012-11-08 21:25:48 +01003026 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003027 continue;
3028
Johannes Berg683b6d32012-11-08 21:25:48 +01003029 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003030 ret = true;
3031 break;
3032 }
3033
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003034 return ret;
3035}
3036
Jouni Malinene39e5b52012-09-30 19:29:39 +03003037static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3038 enum nl80211_auth_type auth_type,
3039 enum nl80211_commands cmd)
3040{
3041 if (auth_type > NL80211_AUTHTYPE_MAX)
3042 return false;
3043
3044 switch (cmd) {
3045 case NL80211_CMD_AUTHENTICATE:
3046 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3047 auth_type == NL80211_AUTHTYPE_SAE)
3048 return false;
3049 return true;
3050 case NL80211_CMD_CONNECT:
3051 case NL80211_CMD_START_AP:
3052 /* SAE not supported yet */
3053 if (auth_type == NL80211_AUTHTYPE_SAE)
3054 return false;
3055 return true;
3056 default:
3057 return false;
3058 }
3059}
3060
Johannes Berg88600202012-02-13 15:17:18 +01003061static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3062{
3063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3064 struct net_device *dev = info->user_ptr[1];
3065 struct wireless_dev *wdev = dev->ieee80211_ptr;
3066 struct cfg80211_ap_settings params;
3067 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003068 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003069
3070 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3071 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3072 return -EOPNOTSUPP;
3073
3074 if (!rdev->ops->start_ap)
3075 return -EOPNOTSUPP;
3076
3077 if (wdev->beacon_interval)
3078 return -EALREADY;
3079
3080 memset(&params, 0, sizeof(params));
3081
3082 /* these are required for START_AP */
3083 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3084 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3085 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3086 return -EINVAL;
3087
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003088 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003089 if (err)
3090 return err;
3091
3092 params.beacon_interval =
3093 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3094 params.dtim_period =
3095 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3096
3097 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3098 if (err)
3099 return err;
3100
3101 /*
3102 * In theory, some of these attributes should be required here
3103 * but since they were not used when the command was originally
3104 * added, keep them optional for old user space programs to let
3105 * them continue to work with drivers that do not need the
3106 * additional information -- drivers must check!
3107 */
3108 if (info->attrs[NL80211_ATTR_SSID]) {
3109 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3110 params.ssid_len =
3111 nla_len(info->attrs[NL80211_ATTR_SSID]);
3112 if (params.ssid_len == 0 ||
3113 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3114 return -EINVAL;
3115 }
3116
3117 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3118 params.hidden_ssid = nla_get_u32(
3119 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3120 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3121 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3122 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3123 return -EINVAL;
3124 }
3125
3126 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3127
3128 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3129 params.auth_type = nla_get_u32(
3130 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003131 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3132 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003133 return -EINVAL;
3134 } else
3135 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3136
3137 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3138 NL80211_MAX_NR_CIPHER_SUITES);
3139 if (err)
3140 return err;
3141
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303142 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3143 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3144 return -EOPNOTSUPP;
3145 params.inactivity_timeout = nla_get_u16(
3146 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3147 }
3148
Johannes Berg53cabad2012-11-14 15:17:28 +01003149 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3151 return -EINVAL;
3152 params.p2p_ctwindow =
3153 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3154 if (params.p2p_ctwindow > 127)
3155 return -EINVAL;
3156 if (params.p2p_ctwindow != 0 &&
3157 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3158 return -EINVAL;
3159 }
3160
3161 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3162 u8 tmp;
3163
3164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3165 return -EINVAL;
3166 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3167 if (tmp > 1)
3168 return -EINVAL;
3169 params.p2p_opp_ps = tmp;
3170 if (params.p2p_opp_ps != 0 &&
3171 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3172 return -EINVAL;
3173 }
3174
Johannes Bergaa430da2012-05-16 23:50:18 +02003175 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003176 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3177 if (err)
3178 return err;
3179 } else if (wdev->preset_chandef.chan) {
3180 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003181 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003182 return -EINVAL;
3183
Johannes Berg683b6d32012-11-08 21:25:48 +01003184 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003185 return -EINVAL;
3186
Simon Wunderlich04f39042013-02-08 18:16:19 +01003187 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3188 if (err < 0)
3189 return err;
3190 if (err) {
3191 radar_detect_width = BIT(params.chandef.width);
3192 params.radar_required = true;
3193 }
3194
Simon Wunderlich04f39042013-02-08 18:16:19 +01003195 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3196 params.chandef.chan,
3197 CHAN_MODE_SHARED,
3198 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003199 if (err)
3200 return err;
3201
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303202 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3203 params.acl = parse_acl_data(&rdev->wiphy, info);
3204 if (IS_ERR(params.acl))
3205 return PTR_ERR(params.acl);
3206 }
3207
Hila Gonene35e4d22012-06-27 17:19:42 +03003208 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003209 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003210 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003211 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003212 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003213 wdev->ssid_len = params.ssid_len;
3214 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003215 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303216
3217 kfree(params.acl);
3218
Johannes Berg56d18932011-05-09 18:41:15 +02003219 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003220}
3221
Johannes Berg88600202012-02-13 15:17:18 +01003222static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3223{
3224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3225 struct net_device *dev = info->user_ptr[1];
3226 struct wireless_dev *wdev = dev->ieee80211_ptr;
3227 struct cfg80211_beacon_data params;
3228 int err;
3229
3230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3231 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3232 return -EOPNOTSUPP;
3233
3234 if (!rdev->ops->change_beacon)
3235 return -EOPNOTSUPP;
3236
3237 if (!wdev->beacon_interval)
3238 return -EINVAL;
3239
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003240 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003241 if (err)
3242 return err;
3243
Hila Gonene35e4d22012-06-27 17:19:42 +03003244 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003245}
3246
3247static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003248{
Johannes Berg4c476992010-10-04 21:36:35 +02003249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3250 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003251
Michal Kazior60771782012-06-29 12:46:56 +02003252 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003253}
3254
Johannes Berg5727ef12007-12-19 02:03:34 +01003255static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3256 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3257 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3258 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003259 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003260 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003261 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003262};
3263
Johannes Bergeccb8e82009-05-11 21:57:56 +03003264static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003265 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003266 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003267{
3268 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003269 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003270 int flag;
3271
Johannes Bergeccb8e82009-05-11 21:57:56 +03003272 /*
3273 * Try parsing the new attribute first so userspace
3274 * can specify both for older kernels.
3275 */
3276 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3277 if (nla) {
3278 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003279
Johannes Bergeccb8e82009-05-11 21:57:56 +03003280 sta_flags = nla_data(nla);
3281 params->sta_flags_mask = sta_flags->mask;
3282 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003283 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003284 if ((params->sta_flags_mask |
3285 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3286 return -EINVAL;
3287 return 0;
3288 }
3289
3290 /* if present, parse the old attribute */
3291
3292 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003293 if (!nla)
3294 return 0;
3295
3296 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3297 nla, sta_flags_policy))
3298 return -EINVAL;
3299
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003300 /*
3301 * Only allow certain flags for interface types so that
3302 * other attributes are silently ignored. Remember that
3303 * this is backward compatibility code with old userspace
3304 * and shouldn't be hit in other cases anyway.
3305 */
3306 switch (iftype) {
3307 case NL80211_IFTYPE_AP:
3308 case NL80211_IFTYPE_AP_VLAN:
3309 case NL80211_IFTYPE_P2P_GO:
3310 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3311 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3312 BIT(NL80211_STA_FLAG_WME) |
3313 BIT(NL80211_STA_FLAG_MFP);
3314 break;
3315 case NL80211_IFTYPE_P2P_CLIENT:
3316 case NL80211_IFTYPE_STATION:
3317 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3318 BIT(NL80211_STA_FLAG_TDLS_PEER);
3319 break;
3320 case NL80211_IFTYPE_MESH_POINT:
3321 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3322 BIT(NL80211_STA_FLAG_MFP) |
3323 BIT(NL80211_STA_FLAG_AUTHORIZED);
3324 default:
3325 return -EINVAL;
3326 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003327
Johannes Berg3383b5a2012-05-10 20:14:43 +02003328 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3329 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003330 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003331
Johannes Berg3383b5a2012-05-10 20:14:43 +02003332 /* no longer support new API additions in old API */
3333 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3334 return -EINVAL;
3335 }
3336 }
3337
Johannes Berg5727ef12007-12-19 02:03:34 +01003338 return 0;
3339}
3340
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003341static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3342 int attr)
3343{
3344 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003345 u32 bitrate;
3346 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003347
3348 rate = nla_nest_start(msg, attr);
3349 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003350 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003351
3352 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3353 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003354 /* report 16-bit bitrate only if we can */
3355 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003356 if (bitrate > 0 &&
3357 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3358 return false;
3359 if (bitrate_compat > 0 &&
3360 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3361 return false;
3362
3363 if (info->flags & RATE_INFO_FLAGS_MCS) {
3364 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3365 return false;
3366 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3367 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3368 return false;
3369 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3370 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3371 return false;
3372 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3373 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3374 return false;
3375 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3376 return false;
3377 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3378 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3379 return false;
3380 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3381 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3382 return false;
3383 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3384 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3385 return false;
3386 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3387 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3388 return false;
3389 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3390 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3391 return false;
3392 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003393
3394 nla_nest_end(msg, rate);
3395 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003396}
3397
Felix Fietkau119363c2013-04-22 16:29:30 +02003398static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3399 int id)
3400{
3401 void *attr;
3402 int i = 0;
3403
3404 if (!mask)
3405 return true;
3406
3407 attr = nla_nest_start(msg, id);
3408 if (!attr)
3409 return false;
3410
3411 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3412 if (!(mask & BIT(i)))
3413 continue;
3414
3415 if (nla_put_u8(msg, i, signal[i]))
3416 return false;
3417 }
3418
3419 nla_nest_end(msg, attr);
3420
3421 return true;
3422}
3423
Eric W. Biederman15e47302012-09-07 20:12:54 +00003424static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003425 int flags,
3426 struct cfg80211_registered_device *rdev,
3427 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003428 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003429{
3430 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003431 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003432
Eric W. Biederman15e47302012-09-07 20:12:54 +00003433 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003434 if (!hdr)
3435 return -1;
3436
David S. Miller9360ffd2012-03-29 04:41:26 -04003437 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3438 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3439 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3440 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003441
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003442 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3443 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003444 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003445 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3446 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3447 sinfo->connected_time))
3448 goto nla_put_failure;
3449 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3451 sinfo->inactive_time))
3452 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003453 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3454 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003455 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003456 (u32)sinfo->rx_bytes))
3457 goto nla_put_failure;
3458 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003459 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003460 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3461 (u32)sinfo->tx_bytes))
3462 goto nla_put_failure;
3463 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3464 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003465 sinfo->rx_bytes))
3466 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003467 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3468 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003469 sinfo->tx_bytes))
3470 goto nla_put_failure;
3471 if ((sinfo->filled & STATION_INFO_LLID) &&
3472 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3473 goto nla_put_failure;
3474 if ((sinfo->filled & STATION_INFO_PLID) &&
3475 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3478 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3479 sinfo->plink_state))
3480 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003481 switch (rdev->wiphy.signal_type) {
3482 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003483 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3484 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3485 sinfo->signal))
3486 goto nla_put_failure;
3487 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3488 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3489 sinfo->signal_avg))
3490 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003491 break;
3492 default:
3493 break;
3494 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003495 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3496 if (!nl80211_put_signal(msg, sinfo->chains,
3497 sinfo->chain_signal,
3498 NL80211_STA_INFO_CHAIN_SIGNAL))
3499 goto nla_put_failure;
3500 }
3501 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3502 if (!nl80211_put_signal(msg, sinfo->chains,
3503 sinfo->chain_signal_avg,
3504 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3505 goto nla_put_failure;
3506 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003507 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003508 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3509 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003510 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003511 }
3512 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3513 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3514 NL80211_STA_INFO_RX_BITRATE))
3515 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003516 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003517 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3518 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3519 sinfo->rx_packets))
3520 goto nla_put_failure;
3521 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3522 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3523 sinfo->tx_packets))
3524 goto nla_put_failure;
3525 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3526 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3527 sinfo->tx_retries))
3528 goto nla_put_failure;
3529 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3530 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3531 sinfo->tx_failed))
3532 goto nla_put_failure;
3533 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3534 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3535 sinfo->beacon_loss_count))
3536 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003537 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3538 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3539 sinfo->local_pm))
3540 goto nla_put_failure;
3541 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3542 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3543 sinfo->peer_pm))
3544 goto nla_put_failure;
3545 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3546 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3547 sinfo->nonpeer_pm))
3548 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003549 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3550 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3551 if (!bss_param)
3552 goto nla_put_failure;
3553
David S. Miller9360ffd2012-03-29 04:41:26 -04003554 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3555 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3556 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3557 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3558 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3559 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3560 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3561 sinfo->bss_param.dtim_period) ||
3562 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3563 sinfo->bss_param.beacon_interval))
3564 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003565
3566 nla_nest_end(msg, bss_param);
3567 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003568 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3569 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3570 sizeof(struct nl80211_sta_flag_update),
3571 &sinfo->sta_flags))
3572 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003573 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3574 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3575 sinfo->t_offset))
3576 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003577 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003578
David S. Miller9360ffd2012-03-29 04:41:26 -04003579 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3580 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3581 sinfo->assoc_req_ies))
3582 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003583
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584 return genlmsg_end(msg, hdr);
3585
3586 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003587 genlmsg_cancel(msg, hdr);
3588 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589}
3590
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003592 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003594 struct station_info sinfo;
3595 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003596 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003597 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003598 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003599 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003600
Johannes Berg97990a02013-04-19 01:02:55 +02003601 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003602 if (err)
3603 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003604
Johannes Berg97990a02013-04-19 01:02:55 +02003605 if (!wdev->netdev) {
3606 err = -EINVAL;
3607 goto out_err;
3608 }
3609
Johannes Bergbba95fe2008-07-29 13:22:51 +02003610 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003611 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003612 goto out_err;
3613 }
3614
Johannes Bergbba95fe2008-07-29 13:22:51 +02003615 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003616 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003617 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003618 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003619 if (err == -ENOENT)
3620 break;
3621 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003622 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003623
3624 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003625 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003626 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003627 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003628 &sinfo) < 0)
3629 goto out;
3630
3631 sta_idx++;
3632 }
3633
3634
3635 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003636 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003637 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003638 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003639 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003640
3641 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003642}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003643
Johannes Berg5727ef12007-12-19 02:03:34 +01003644static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3645{
Johannes Berg4c476992010-10-04 21:36:35 +02003646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3647 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003648 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003649 struct sk_buff *msg;
3650 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003651 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003652
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003653 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003654
3655 if (!info->attrs[NL80211_ATTR_MAC])
3656 return -EINVAL;
3657
3658 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3659
Johannes Berg4c476992010-10-04 21:36:35 +02003660 if (!rdev->ops->get_station)
3661 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003662
Hila Gonene35e4d22012-06-27 17:19:42 +03003663 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003664 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003665 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003666
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003668 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003669 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003670
Eric W. Biederman15e47302012-09-07 20:12:54 +00003671 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003672 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003673 nlmsg_free(msg);
3674 return -ENOBUFS;
3675 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003676
Johannes Berg4c476992010-10-04 21:36:35 +02003677 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003678}
3679
Johannes Berg77ee7c82013-02-15 00:48:33 +01003680int cfg80211_check_station_change(struct wiphy *wiphy,
3681 struct station_parameters *params,
3682 enum cfg80211_station_type statype)
3683{
3684 if (params->listen_interval != -1)
3685 return -EINVAL;
3686 if (params->aid)
3687 return -EINVAL;
3688
3689 /* When you run into this, adjust the code below for the new flag */
3690 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3691
3692 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003693 case CFG80211_STA_MESH_PEER_KERNEL:
3694 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003695 /*
3696 * No ignoring the TDLS flag here -- the userspace mesh
3697 * code doesn't have the bug of including TDLS in the
3698 * mask everywhere.
3699 */
3700 if (params->sta_flags_mask &
3701 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3702 BIT(NL80211_STA_FLAG_MFP) |
3703 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3704 return -EINVAL;
3705 break;
3706 case CFG80211_STA_TDLS_PEER_SETUP:
3707 case CFG80211_STA_TDLS_PEER_ACTIVE:
3708 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3709 return -EINVAL;
3710 /* ignore since it can't change */
3711 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3712 break;
3713 default:
3714 /* disallow mesh-specific things */
3715 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3716 return -EINVAL;
3717 if (params->local_pm)
3718 return -EINVAL;
3719 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3720 return -EINVAL;
3721 }
3722
3723 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3724 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3725 /* TDLS can't be set, ... */
3726 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3727 return -EINVAL;
3728 /*
3729 * ... but don't bother the driver with it. This works around
3730 * a hostapd/wpa_supplicant issue -- it always includes the
3731 * TLDS_PEER flag in the mask even for AP mode.
3732 */
3733 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3734 }
3735
3736 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3737 /* reject other things that can't change */
3738 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3739 return -EINVAL;
3740 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3741 return -EINVAL;
3742 if (params->supported_rates)
3743 return -EINVAL;
3744 if (params->ext_capab || params->ht_capa || params->vht_capa)
3745 return -EINVAL;
3746 }
3747
3748 if (statype != CFG80211_STA_AP_CLIENT) {
3749 if (params->vlan)
3750 return -EINVAL;
3751 }
3752
3753 switch (statype) {
3754 case CFG80211_STA_AP_MLME_CLIENT:
3755 /* Use this only for authorizing/unauthorizing a station */
3756 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3757 return -EOPNOTSUPP;
3758 break;
3759 case CFG80211_STA_AP_CLIENT:
3760 /* accept only the listed bits */
3761 if (params->sta_flags_mask &
3762 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3763 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3764 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3765 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3766 BIT(NL80211_STA_FLAG_WME) |
3767 BIT(NL80211_STA_FLAG_MFP)))
3768 return -EINVAL;
3769
3770 /* but authenticated/associated only if driver handles it */
3771 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3772 params->sta_flags_mask &
3773 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3774 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3775 return -EINVAL;
3776 break;
3777 case CFG80211_STA_IBSS:
3778 case CFG80211_STA_AP_STA:
3779 /* reject any changes other than AUTHORIZED */
3780 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3781 return -EINVAL;
3782 break;
3783 case CFG80211_STA_TDLS_PEER_SETUP:
3784 /* reject any changes other than AUTHORIZED or WME */
3785 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3786 BIT(NL80211_STA_FLAG_WME)))
3787 return -EINVAL;
3788 /* force (at least) rates when authorizing */
3789 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3790 !params->supported_rates)
3791 return -EINVAL;
3792 break;
3793 case CFG80211_STA_TDLS_PEER_ACTIVE:
3794 /* reject any changes */
3795 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003796 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003797 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3798 return -EINVAL;
3799 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003800 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003801 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3802 return -EINVAL;
3803 break;
3804 }
3805
3806 return 0;
3807}
3808EXPORT_SYMBOL(cfg80211_check_station_change);
3809
Johannes Berg5727ef12007-12-19 02:03:34 +01003810/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003811 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003812 */
Johannes Berg80b99892011-11-18 16:23:01 +01003813static struct net_device *get_vlan(struct genl_info *info,
3814 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003815{
Johannes Berg463d0182009-07-14 00:33:35 +02003816 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003817 struct net_device *v;
3818 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003819
Johannes Berg80b99892011-11-18 16:23:01 +01003820 if (!vlanattr)
3821 return NULL;
3822
3823 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3824 if (!v)
3825 return ERR_PTR(-ENODEV);
3826
3827 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3828 ret = -EINVAL;
3829 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003830 }
Johannes Berg80b99892011-11-18 16:23:01 +01003831
Johannes Berg77ee7c82013-02-15 00:48:33 +01003832 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3833 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3834 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3835 ret = -EINVAL;
3836 goto error;
3837 }
3838
Johannes Berg80b99892011-11-18 16:23:01 +01003839 if (!netif_running(v)) {
3840 ret = -ENETDOWN;
3841 goto error;
3842 }
3843
3844 return v;
3845 error:
3846 dev_put(v);
3847 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003848}
3849
Jouni Malinendf881292013-02-14 21:10:54 +02003850static struct nla_policy
3851nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3852 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3853 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3854};
3855
Johannes Bergff276692013-02-15 00:09:01 +01003856static int nl80211_parse_sta_wme(struct genl_info *info,
3857 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003858{
Jouni Malinendf881292013-02-14 21:10:54 +02003859 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3860 struct nlattr *nla;
3861 int err;
3862
Jouni Malinendf881292013-02-14 21:10:54 +02003863 /* parse WME attributes if present */
3864 if (!info->attrs[NL80211_ATTR_STA_WME])
3865 return 0;
3866
3867 nla = info->attrs[NL80211_ATTR_STA_WME];
3868 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3869 nl80211_sta_wme_policy);
3870 if (err)
3871 return err;
3872
3873 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3874 params->uapsd_queues = nla_get_u8(
3875 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3876 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3877 return -EINVAL;
3878
3879 if (tb[NL80211_STA_WME_MAX_SP])
3880 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3881
3882 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3883 return -EINVAL;
3884
3885 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3886
3887 return 0;
3888}
3889
Johannes Bergff276692013-02-15 00:09:01 +01003890static int nl80211_set_station_tdls(struct genl_info *info,
3891 struct station_parameters *params)
3892{
3893 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003894 if (info->attrs[NL80211_ATTR_PEER_AID])
3895 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003896 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3897 params->ht_capa =
3898 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3899 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3900 params->vht_capa =
3901 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3902
3903 return nl80211_parse_sta_wme(info, params);
3904}
3905
Johannes Berg5727ef12007-12-19 02:03:34 +01003906static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3907{
Johannes Berg4c476992010-10-04 21:36:35 +02003908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003909 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003910 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003911 u8 *mac_addr;
3912 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003913
3914 memset(&params, 0, sizeof(params));
3915
3916 params.listen_interval = -1;
3917
Johannes Berg77ee7c82013-02-15 00:48:33 +01003918 if (!rdev->ops->change_station)
3919 return -EOPNOTSUPP;
3920
Johannes Berg5727ef12007-12-19 02:03:34 +01003921 if (info->attrs[NL80211_ATTR_STA_AID])
3922 return -EINVAL;
3923
3924 if (!info->attrs[NL80211_ATTR_MAC])
3925 return -EINVAL;
3926
3927 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3928
3929 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3930 params.supported_rates =
3931 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3932 params.supported_rates_len =
3933 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3934 }
3935
Jouni Malinen9d62a982013-02-14 21:10:13 +02003936 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3937 params.capability =
3938 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3939 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3940 }
3941
3942 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3943 params.ext_capab =
3944 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3945 params.ext_capab_len =
3946 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3947 }
3948
Jouni Malinendf881292013-02-14 21:10:54 +02003949 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003950 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003951
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003952 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003953 return -EINVAL;
3954
Johannes Bergf8bacc22013-02-14 23:27:01 +01003955 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003956 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003957 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3958 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3959 return -EINVAL;
3960 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003961
Johannes Bergf8bacc22013-02-14 23:27:01 +01003962 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003963 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003964 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3965 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3966 return -EINVAL;
3967 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3968 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003969
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003970 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3971 enum nl80211_mesh_power_mode pm = nla_get_u32(
3972 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3973
3974 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3975 pm > NL80211_MESH_POWER_MAX)
3976 return -EINVAL;
3977
3978 params.local_pm = pm;
3979 }
3980
Johannes Berg77ee7c82013-02-15 00:48:33 +01003981 /* Include parameters for TDLS peer (will check later) */
3982 err = nl80211_set_station_tdls(info, &params);
3983 if (err)
3984 return err;
3985
3986 params.vlan = get_vlan(info, rdev);
3987 if (IS_ERR(params.vlan))
3988 return PTR_ERR(params.vlan);
3989
Johannes Berga97f4422009-06-18 17:23:43 +02003990 switch (dev->ieee80211_ptr->iftype) {
3991 case NL80211_IFTYPE_AP:
3992 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003993 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003994 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003995 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003996 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003997 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003998 break;
3999 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004000 err = -EOPNOTSUPP;
4001 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004002 }
4003
Johannes Berg77ee7c82013-02-15 00:48:33 +01004004 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004005 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004006
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004008 if (params.vlan)
4009 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004010
Johannes Berg5727ef12007-12-19 02:03:34 +01004011 return err;
4012}
4013
4014static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4015{
Johannes Berg4c476992010-10-04 21:36:35 +02004016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004017 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004018 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004019 struct station_parameters params;
4020 u8 *mac_addr = NULL;
4021
4022 memset(&params, 0, sizeof(params));
4023
Johannes Berg984c3112013-02-14 23:43:25 +01004024 if (!rdev->ops->add_station)
4025 return -EOPNOTSUPP;
4026
Johannes Berg5727ef12007-12-19 02:03:34 +01004027 if (!info->attrs[NL80211_ATTR_MAC])
4028 return -EINVAL;
4029
Johannes Berg5727ef12007-12-19 02:03:34 +01004030 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4031 return -EINVAL;
4032
4033 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4034 return -EINVAL;
4035
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004036 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4037 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004038 return -EINVAL;
4039
Johannes Berg5727ef12007-12-19 02:03:34 +01004040 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4041 params.supported_rates =
4042 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4043 params.supported_rates_len =
4044 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4045 params.listen_interval =
4046 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004047
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004048 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004049 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004050 else
4051 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004052 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4053 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004054
Jouni Malinen9d62a982013-02-14 21:10:13 +02004055 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4056 params.capability =
4057 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4058 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4059 }
4060
4061 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4062 params.ext_capab =
4063 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4064 params.ext_capab_len =
4065 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4066 }
4067
Jouni Malinen36aedc92008-08-25 11:58:58 +03004068 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4069 params.ht_capa =
4070 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004071
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004072 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4073 params.vht_capa =
4074 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4075
Johannes Bergf8bacc22013-02-14 23:27:01 +01004076 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004077 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004078 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4079 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4080 return -EINVAL;
4081 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004082
Johannes Bergff276692013-02-15 00:09:01 +01004083 err = nl80211_parse_sta_wme(info, &params);
4084 if (err)
4085 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004086
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004087 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004088 return -EINVAL;
4089
Johannes Berg77ee7c82013-02-15 00:48:33 +01004090 /* When you run into this, adjust the code below for the new flag */
4091 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4092
Johannes Bergbdd90d52011-12-14 12:20:27 +01004093 switch (dev->ieee80211_ptr->iftype) {
4094 case NL80211_IFTYPE_AP:
4095 case NL80211_IFTYPE_AP_VLAN:
4096 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004097 /* ignore WME attributes if iface/sta is not capable */
4098 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4099 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4100 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004101
Johannes Bergbdd90d52011-12-14 12:20:27 +01004102 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004103 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4104 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004105 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004106 /* but don't bother the driver with it */
4107 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004108
Johannes Bergd582cff2012-10-26 17:53:44 +02004109 /* allow authenticated/associated only if driver handles it */
4110 if (!(rdev->wiphy.features &
4111 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4112 params.sta_flags_mask &
4113 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4114 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4115 return -EINVAL;
4116
Johannes Bergbdd90d52011-12-14 12:20:27 +01004117 /* must be last in here for error handling */
4118 params.vlan = get_vlan(info, rdev);
4119 if (IS_ERR(params.vlan))
4120 return PTR_ERR(params.vlan);
4121 break;
4122 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004123 /* ignore uAPSD data */
4124 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4125
Johannes Bergd582cff2012-10-26 17:53:44 +02004126 /* associated is disallowed */
4127 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4128 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004129 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004130 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4131 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004132 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004133 break;
4134 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004135 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004136 /* ignore uAPSD data */
4137 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4138
Johannes Berg77ee7c82013-02-15 00:48:33 +01004139 /* these are disallowed */
4140 if (params.sta_flags_mask &
4141 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4142 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004143 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004144 /* Only TDLS peers can be added */
4145 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4146 return -EINVAL;
4147 /* Can only add if TDLS ... */
4148 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4149 return -EOPNOTSUPP;
4150 /* ... with external setup is supported */
4151 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4152 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004153 /*
4154 * Older wpa_supplicant versions always mark the TDLS peer
4155 * as authorized, but it shouldn't yet be.
4156 */
4157 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004158 break;
4159 default:
4160 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004161 }
4162
Johannes Bergbdd90d52011-12-14 12:20:27 +01004163 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004164
Hila Gonene35e4d22012-06-27 17:19:42 +03004165 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004166
Johannes Berg5727ef12007-12-19 02:03:34 +01004167 if (params.vlan)
4168 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004169 return err;
4170}
4171
4172static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4173{
Johannes Berg4c476992010-10-04 21:36:35 +02004174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4175 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004176 u8 *mac_addr = NULL;
4177
4178 if (info->attrs[NL80211_ATTR_MAC])
4179 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4180
Johannes Berge80cf852009-05-11 14:43:13 +02004181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4185 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004186
Johannes Berg4c476992010-10-04 21:36:35 +02004187 if (!rdev->ops->del_station)
4188 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004189
Hila Gonene35e4d22012-06-27 17:19:42 +03004190 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004191}
4192
Eric W. Biederman15e47302012-09-07 20:12:54 +00004193static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004194 int flags, struct net_device *dev,
4195 u8 *dst, u8 *next_hop,
4196 struct mpath_info *pinfo)
4197{
4198 void *hdr;
4199 struct nlattr *pinfoattr;
4200
Eric W. Biederman15e47302012-09-07 20:12:54 +00004201 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004202 if (!hdr)
4203 return -1;
4204
David S. Miller9360ffd2012-03-29 04:41:26 -04004205 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4207 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4208 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4209 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004210
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004211 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4212 if (!pinfoattr)
4213 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004214 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4215 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4216 pinfo->frame_qlen))
4217 goto nla_put_failure;
4218 if (((pinfo->filled & MPATH_INFO_SN) &&
4219 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4220 ((pinfo->filled & MPATH_INFO_METRIC) &&
4221 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4222 pinfo->metric)) ||
4223 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4224 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4225 pinfo->exptime)) ||
4226 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4227 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4228 pinfo->flags)) ||
4229 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4230 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4231 pinfo->discovery_timeout)) ||
4232 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4233 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4234 pinfo->discovery_retries)))
4235 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004236
4237 nla_nest_end(msg, pinfoattr);
4238
4239 return genlmsg_end(msg, hdr);
4240
4241 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004242 genlmsg_cancel(msg, hdr);
4243 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004244}
4245
4246static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004247 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004249 struct mpath_info pinfo;
4250 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004251 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252 u8 dst[ETH_ALEN];
4253 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004254 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004255 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004256
Johannes Berg97990a02013-04-19 01:02:55 +02004257 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004258 if (err)
4259 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004260
4261 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004262 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004263 goto out_err;
4264 }
4265
Johannes Berg97990a02013-04-19 01:02:55 +02004266 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004267 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004268 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004269 }
4270
Johannes Bergbba95fe2008-07-29 13:22:51 +02004271 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004272 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4273 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004274 if (err == -ENOENT)
4275 break;
4276 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004277 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004278
Eric W. Biederman15e47302012-09-07 20:12:54 +00004279 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004280 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004281 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004282 &pinfo) < 0)
4283 goto out;
4284
4285 path_idx++;
4286 }
4287
4288
4289 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004290 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004291 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004292 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004293 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004294 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004295}
4296
4297static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4298{
Johannes Berg4c476992010-10-04 21:36:35 +02004299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004301 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302 struct mpath_info pinfo;
4303 struct sk_buff *msg;
4304 u8 *dst = NULL;
4305 u8 next_hop[ETH_ALEN];
4306
4307 memset(&pinfo, 0, sizeof(pinfo));
4308
4309 if (!info->attrs[NL80211_ATTR_MAC])
4310 return -EINVAL;
4311
4312 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4313
Johannes Berg4c476992010-10-04 21:36:35 +02004314 if (!rdev->ops->get_mpath)
4315 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004316
Johannes Berg4c476992010-10-04 21:36:35 +02004317 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4318 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004319
Hila Gonene35e4d22012-06-27 17:19:42 +03004320 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004322 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004323
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004326 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004327
Eric W. Biederman15e47302012-09-07 20:12:54 +00004328 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004329 dev, dst, next_hop, &pinfo) < 0) {
4330 nlmsg_free(msg);
4331 return -ENOBUFS;
4332 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004333
Johannes Berg4c476992010-10-04 21:36:35 +02004334 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004335}
4336
4337static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4338{
Johannes Berg4c476992010-10-04 21:36:35 +02004339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4340 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004341 u8 *dst = NULL;
4342 u8 *next_hop = NULL;
4343
4344 if (!info->attrs[NL80211_ATTR_MAC])
4345 return -EINVAL;
4346
4347 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4348 return -EINVAL;
4349
4350 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4351 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4352
Johannes Berg4c476992010-10-04 21:36:35 +02004353 if (!rdev->ops->change_mpath)
4354 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004355
Johannes Berg4c476992010-10-04 21:36:35 +02004356 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4357 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358
Hila Gonene35e4d22012-06-27 17:19:42 +03004359 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004360}
Johannes Berg4c476992010-10-04 21:36:35 +02004361
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004362static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4363{
Johannes Berg4c476992010-10-04 21:36:35 +02004364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4365 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004366 u8 *dst = NULL;
4367 u8 *next_hop = NULL;
4368
4369 if (!info->attrs[NL80211_ATTR_MAC])
4370 return -EINVAL;
4371
4372 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4373 return -EINVAL;
4374
4375 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4376 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4377
Johannes Berg4c476992010-10-04 21:36:35 +02004378 if (!rdev->ops->add_mpath)
4379 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004380
Johannes Berg4c476992010-10-04 21:36:35 +02004381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4382 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383
Hila Gonene35e4d22012-06-27 17:19:42 +03004384 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004385}
4386
4387static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4388{
Johannes Berg4c476992010-10-04 21:36:35 +02004389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4390 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391 u8 *dst = NULL;
4392
4393 if (info->attrs[NL80211_ATTR_MAC])
4394 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4395
Johannes Berg4c476992010-10-04 21:36:35 +02004396 if (!rdev->ops->del_mpath)
4397 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004398
Hila Gonene35e4d22012-06-27 17:19:42 +03004399 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400}
4401
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004402static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4403{
Johannes Berg4c476992010-10-04 21:36:35 +02004404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4405 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004406 struct bss_parameters params;
4407
4408 memset(&params, 0, sizeof(params));
4409 /* default to not changing parameters */
4410 params.use_cts_prot = -1;
4411 params.use_short_preamble = -1;
4412 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004413 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004414 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004415 params.p2p_ctwindow = -1;
4416 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004417
4418 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4419 params.use_cts_prot =
4420 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4421 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4422 params.use_short_preamble =
4423 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4424 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4425 params.use_short_slot_time =
4426 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004427 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4428 params.basic_rates =
4429 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4430 params.basic_rates_len =
4431 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4432 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004433 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4434 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004435 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4436 params.ht_opmode =
4437 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004438
Johannes Berg53cabad2012-11-14 15:17:28 +01004439 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4440 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4441 return -EINVAL;
4442 params.p2p_ctwindow =
4443 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4444 if (params.p2p_ctwindow < 0)
4445 return -EINVAL;
4446 if (params.p2p_ctwindow != 0 &&
4447 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4448 return -EINVAL;
4449 }
4450
4451 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4452 u8 tmp;
4453
4454 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4455 return -EINVAL;
4456 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4457 if (tmp > 1)
4458 return -EINVAL;
4459 params.p2p_opp_ps = tmp;
4460 if (params.p2p_opp_ps &&
4461 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4462 return -EINVAL;
4463 }
4464
Johannes Berg4c476992010-10-04 21:36:35 +02004465 if (!rdev->ops->change_bss)
4466 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004467
Johannes Berg074ac8d2010-09-16 14:58:22 +02004468 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004469 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4470 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004471
Hila Gonene35e4d22012-06-27 17:19:42 +03004472 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004473}
4474
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004475static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004476 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4477 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4478 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4479 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4480 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4481 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4482};
4483
4484static int parse_reg_rule(struct nlattr *tb[],
4485 struct ieee80211_reg_rule *reg_rule)
4486{
4487 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4488 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4489
4490 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4491 return -EINVAL;
4492 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4493 return -EINVAL;
4494 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4495 return -EINVAL;
4496 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4497 return -EINVAL;
4498 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4499 return -EINVAL;
4500
4501 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4502
4503 freq_range->start_freq_khz =
4504 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4505 freq_range->end_freq_khz =
4506 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4507 freq_range->max_bandwidth_khz =
4508 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4509
4510 power_rule->max_eirp =
4511 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4512
4513 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4514 power_rule->max_antenna_gain =
4515 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4516
4517 return 0;
4518}
4519
4520static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4521{
4522 int r;
4523 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004524 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004525
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004526 /*
4527 * You should only get this when cfg80211 hasn't yet initialized
4528 * completely when built-in to the kernel right between the time
4529 * window between nl80211_init() and regulatory_init(), if that is
4530 * even possible.
4531 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004532 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004533 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004534
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004535 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4536 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004537
4538 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4539
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004540 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4541 user_reg_hint_type =
4542 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4543 else
4544 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4545
4546 switch (user_reg_hint_type) {
4547 case NL80211_USER_REG_HINT_USER:
4548 case NL80211_USER_REG_HINT_CELL_BASE:
4549 break;
4550 default:
4551 return -EINVAL;
4552 }
4553
4554 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004555
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004556 return r;
4557}
4558
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004559static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004560 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004561{
Johannes Berg4c476992010-10-04 21:36:35 +02004562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004563 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004564 struct wireless_dev *wdev = dev->ieee80211_ptr;
4565 struct mesh_config cur_params;
4566 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004567 void *hdr;
4568 struct nlattr *pinfoattr;
4569 struct sk_buff *msg;
4570
Johannes Berg29cbe682010-12-03 09:20:44 +01004571 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4572 return -EOPNOTSUPP;
4573
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004574 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004575 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004576
Johannes Berg29cbe682010-12-03 09:20:44 +01004577 wdev_lock(wdev);
4578 /* If not connected, get default parameters */
4579 if (!wdev->mesh_id_len)
4580 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4581 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004582 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004583 wdev_unlock(wdev);
4584
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004586 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587
4588 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004590 if (!msg)
4591 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004592 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004593 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004595 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004596 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004597 if (!pinfoattr)
4598 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004599 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4600 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4601 cur_params.dot11MeshRetryTimeout) ||
4602 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4603 cur_params.dot11MeshConfirmTimeout) ||
4604 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4605 cur_params.dot11MeshHoldingTimeout) ||
4606 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4607 cur_params.dot11MeshMaxPeerLinks) ||
4608 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4609 cur_params.dot11MeshMaxRetries) ||
4610 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4611 cur_params.dot11MeshTTL) ||
4612 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4613 cur_params.element_ttl) ||
4614 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4615 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004616 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4617 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004618 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4619 cur_params.dot11MeshHWMPmaxPREQretries) ||
4620 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4621 cur_params.path_refresh_time) ||
4622 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4623 cur_params.min_discovery_timeout) ||
4624 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4625 cur_params.dot11MeshHWMPactivePathTimeout) ||
4626 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4627 cur_params.dot11MeshHWMPpreqMinInterval) ||
4628 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4629 cur_params.dot11MeshHWMPperrMinInterval) ||
4630 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4631 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4632 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4633 cur_params.dot11MeshHWMPRootMode) ||
4634 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4635 cur_params.dot11MeshHWMPRannInterval) ||
4636 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4637 cur_params.dot11MeshGateAnnouncementProtocol) ||
4638 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4639 cur_params.dot11MeshForwarding) ||
4640 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004641 cur_params.rssi_threshold) ||
4642 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004643 cur_params.ht_opmode) ||
4644 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4645 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4646 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004647 cur_params.dot11MeshHWMProotInterval) ||
4648 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004649 cur_params.dot11MeshHWMPconfirmationInterval) ||
4650 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4651 cur_params.power_mode) ||
4652 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004653 cur_params.dot11MeshAwakeWindowDuration) ||
4654 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4655 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004656 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004657 nla_nest_end(msg, pinfoattr);
4658 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004659 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004660
Johannes Berg3b858752009-03-12 09:55:09 +01004661 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004663 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004664 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004665 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004666}
4667
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004668static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004669 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4670 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4671 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4672 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4673 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4674 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004675 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004676 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004677 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004678 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4679 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4680 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4681 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4682 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004683 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004684 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004685 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004686 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004687 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004688 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004689 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4690 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004691 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4692 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004693 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004694 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4695 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004696 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697};
4698
Javier Cardonac80d5452010-12-16 17:37:49 -08004699static const struct nla_policy
4700 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004701 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004702 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4703 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004704 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004705 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004706 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004707 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004709 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004710};
4711
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004712static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004713 struct mesh_config *cfg,
4714 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004715{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004716 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004717 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718
Marco Porschea54fba2013-01-07 16:04:48 +01004719#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4720do { \
4721 if (tb[attr]) { \
4722 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4723 return -EINVAL; \
4724 cfg->param = fn(tb[attr]); \
4725 mask |= (1 << (attr - 1)); \
4726 } \
4727} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004728
4729
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004730 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004731 return -EINVAL;
4732 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004733 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004734 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004735 return -EINVAL;
4736
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004737 /* This makes sure that there aren't more than 32 mesh config
4738 * parameters (otherwise our bitfield scheme would not work.) */
4739 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4740
4741 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004742 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004743 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4744 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004745 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004746 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4747 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004749 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4750 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004752 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4753 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004755 mask, NL80211_MESHCONF_MAX_RETRIES,
4756 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004757 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004758 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004760 mask, NL80211_MESHCONF_ELEMENT_TTL,
4761 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004762 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004763 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4764 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004765 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4766 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004767 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4768 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004769 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004770 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4771 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004772 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004773 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4774 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004775 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004776 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4777 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004778 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4779 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004780 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4781 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004782 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004783 1, 65535, mask,
4784 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004785 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004787 1, 65535, mask,
4788 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004789 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004791 dot11MeshHWMPnetDiameterTraversalTime,
4792 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004793 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4794 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4796 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4797 nla_get_u8);
4798 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4799 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004800 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004801 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004802 dot11MeshGateAnnouncementProtocol, 0, 1,
4803 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004804 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004805 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004806 mask, NL80211_MESHCONF_FORWARDING,
4807 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004808 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004809 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4810 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004811 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004812 mask, NL80211_MESHCONF_HT_OPMODE,
4813 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004814 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004815 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004816 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4817 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004819 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4820 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004822 dot11MeshHWMPconfirmationInterval,
4823 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004824 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4825 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4827 NL80211_MESH_POWER_ACTIVE,
4828 NL80211_MESH_POWER_MAX,
4829 mask, NL80211_MESHCONF_POWER_MODE,
4830 nla_get_u32);
4831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4832 0, 65535, mask,
4833 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4835 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4836 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004837 if (mask_out)
4838 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004839
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840 return 0;
4841
4842#undef FILL_IN_MESH_PARAM_IF_SET
4843}
4844
Javier Cardonac80d5452010-12-16 17:37:49 -08004845static int nl80211_parse_mesh_setup(struct genl_info *info,
4846 struct mesh_setup *setup)
4847{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004849 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4850
4851 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4852 return -EINVAL;
4853 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4854 info->attrs[NL80211_ATTR_MESH_SETUP],
4855 nl80211_mesh_setup_params_policy))
4856 return -EINVAL;
4857
Javier Cardonad299a1f2012-03-31 11:31:33 -07004858 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4859 setup->sync_method =
4860 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4861 IEEE80211_SYNC_METHOD_VENDOR :
4862 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4863
Javier Cardonac80d5452010-12-16 17:37:49 -08004864 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4865 setup->path_sel_proto =
4866 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4867 IEEE80211_PATH_PROTOCOL_VENDOR :
4868 IEEE80211_PATH_PROTOCOL_HWMP;
4869
4870 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4871 setup->path_metric =
4872 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4873 IEEE80211_PATH_METRIC_VENDOR :
4874 IEEE80211_PATH_METRIC_AIRTIME;
4875
Javier Cardona581a8b02011-04-07 15:08:27 -07004876
4877 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004878 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004879 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004880 if (!is_valid_ie_attr(ieattr))
4881 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004882 setup->ie = nla_data(ieattr);
4883 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004884 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004885 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4886 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4887 return -EINVAL;
4888 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004889 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4890 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004891 if (setup->is_secure)
4892 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004893
Colleen Twitty6e16d902013-05-08 11:45:59 -07004894 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4895 if (!setup->user_mpm)
4896 return -EINVAL;
4897 setup->auth_id =
4898 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4899 }
4900
Javier Cardonac80d5452010-12-16 17:37:49 -08004901 return 0;
4902}
4903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004904static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004905 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004906{
4907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4908 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004909 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004910 struct mesh_config cfg;
4911 u32 mask;
4912 int err;
4913
Johannes Berg29cbe682010-12-03 09:20:44 +01004914 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4915 return -EOPNOTSUPP;
4916
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004917 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004918 return -EOPNOTSUPP;
4919
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004920 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004921 if (err)
4922 return err;
4923
Johannes Berg29cbe682010-12-03 09:20:44 +01004924 wdev_lock(wdev);
4925 if (!wdev->mesh_id_len)
4926 err = -ENOLINK;
4927
4928 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004929 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004930
4931 wdev_unlock(wdev);
4932
4933 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004934}
4935
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004936static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4937{
Johannes Berg458f4f92012-12-06 15:47:38 +01004938 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939 struct sk_buff *msg;
4940 void *hdr = NULL;
4941 struct nlattr *nl_reg_rules;
4942 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004943
4944 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004945 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004946
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004947 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004948 if (!msg)
4949 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004950
Eric W. Biederman15e47302012-09-07 20:12:54 +00004951 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004952 NL80211_CMD_GET_REG);
4953 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004954 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004955
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004956 if (reg_last_request_cell_base() &&
4957 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4958 NL80211_USER_REG_HINT_CELL_BASE))
4959 goto nla_put_failure;
4960
Johannes Berg458f4f92012-12-06 15:47:38 +01004961 rcu_read_lock();
4962 regdom = rcu_dereference(cfg80211_regdomain);
4963
4964 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4965 (regdom->dfs_region &&
4966 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4967 goto nla_put_failure_rcu;
4968
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004969 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4970 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004971 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004972
Johannes Berg458f4f92012-12-06 15:47:38 +01004973 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004974 struct nlattr *nl_reg_rule;
4975 const struct ieee80211_reg_rule *reg_rule;
4976 const struct ieee80211_freq_range *freq_range;
4977 const struct ieee80211_power_rule *power_rule;
4978
Johannes Berg458f4f92012-12-06 15:47:38 +01004979 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004980 freq_range = &reg_rule->freq_range;
4981 power_rule = &reg_rule->power_rule;
4982
4983 nl_reg_rule = nla_nest_start(msg, i);
4984 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004985 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004986
David S. Miller9360ffd2012-03-29 04:41:26 -04004987 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4988 reg_rule->flags) ||
4989 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4990 freq_range->start_freq_khz) ||
4991 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4992 freq_range->end_freq_khz) ||
4993 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4994 freq_range->max_bandwidth_khz) ||
4995 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4996 power_rule->max_antenna_gain) ||
4997 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4998 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004999 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005000
5001 nla_nest_end(msg, nl_reg_rule);
5002 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005003 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005004
5005 nla_nest_end(msg, nl_reg_rules);
5006
5007 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005008 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005009
Johannes Berg458f4f92012-12-06 15:47:38 +01005010nla_put_failure_rcu:
5011 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005012nla_put_failure:
5013 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005014put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005015 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005016 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005017}
5018
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005019static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5020{
5021 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5022 struct nlattr *nl_reg_rule;
5023 char *alpha2 = NULL;
5024 int rem_reg_rules = 0, r = 0;
5025 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005026 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005027 struct ieee80211_regdomain *rd = NULL;
5028
5029 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5030 return -EINVAL;
5031
5032 if (!info->attrs[NL80211_ATTR_REG_RULES])
5033 return -EINVAL;
5034
5035 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5036
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005037 if (info->attrs[NL80211_ATTR_DFS_REGION])
5038 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5039
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005040 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005041 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005042 num_rules++;
5043 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005044 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005045 }
5046
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005047 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005048 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005049
5050 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005051 if (!rd)
5052 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005053
5054 rd->n_reg_rules = num_rules;
5055 rd->alpha2[0] = alpha2[0];
5056 rd->alpha2[1] = alpha2[1];
5057
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005058 /*
5059 * Disable DFS master mode if the DFS region was
5060 * not supported or known on this kernel.
5061 */
5062 if (reg_supported_dfs_region(dfs_region))
5063 rd->dfs_region = dfs_region;
5064
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005065 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005066 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005067 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005068 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5069 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005070 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5071 if (r)
5072 goto bad_reg;
5073
5074 rule_idx++;
5075
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005076 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5077 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005078 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005079 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005080 }
5081
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005082 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005083 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005084 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005085
Johannes Bergd2372b32008-10-24 20:32:20 +02005086 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005087 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005088 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005089}
5090
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005091static int validate_scan_freqs(struct nlattr *freqs)
5092{
5093 struct nlattr *attr1, *attr2;
5094 int n_channels = 0, tmp1, tmp2;
5095
5096 nla_for_each_nested(attr1, freqs, tmp1) {
5097 n_channels++;
5098 /*
5099 * Some hardware has a limited channel list for
5100 * scanning, and it is pretty much nonsensical
5101 * to scan for a channel twice, so disallow that
5102 * and don't require drivers to check that the
5103 * channel list they get isn't longer than what
5104 * they can scan, as long as they can scan all
5105 * the channels they registered at once.
5106 */
5107 nla_for_each_nested(attr2, freqs, tmp2)
5108 if (attr1 != attr2 &&
5109 nla_get_u32(attr1) == nla_get_u32(attr2))
5110 return 0;
5111 }
5112
5113 return n_channels;
5114}
5115
Johannes Berg2a519312009-02-10 21:25:55 +01005116static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5117{
Johannes Berg4c476992010-10-04 21:36:35 +02005118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005119 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005120 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005121 struct nlattr *attr;
5122 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005123 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005124 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005125
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005126 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5127 return -EINVAL;
5128
Johannes Berg79c97e92009-07-07 03:56:12 +02005129 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005130
Johannes Berg4c476992010-10-04 21:36:35 +02005131 if (!rdev->ops->scan)
5132 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005133
Johannes Bergf9f47522013-03-19 15:04:07 +01005134 if (rdev->scan_req) {
5135 err = -EBUSY;
5136 goto unlock;
5137 }
Johannes Berg2a519312009-02-10 21:25:55 +01005138
5139 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005140 n_channels = validate_scan_freqs(
5141 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005142 if (!n_channels) {
5143 err = -EINVAL;
5144 goto unlock;
5145 }
Johannes Berg2a519312009-02-10 21:25:55 +01005146 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005147 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005148 n_channels = 0;
5149
Johannes Berg2a519312009-02-10 21:25:55 +01005150 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5151 if (wiphy->bands[band])
5152 n_channels += wiphy->bands[band]->n_channels;
5153 }
5154
5155 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5156 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5157 n_ssids++;
5158
Johannes Bergf9f47522013-03-19 15:04:07 +01005159 if (n_ssids > wiphy->max_scan_ssids) {
5160 err = -EINVAL;
5161 goto unlock;
5162 }
Johannes Berg2a519312009-02-10 21:25:55 +01005163
Jouni Malinen70692ad2009-02-16 19:39:13 +02005164 if (info->attrs[NL80211_ATTR_IE])
5165 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5166 else
5167 ie_len = 0;
5168
Johannes Bergf9f47522013-03-19 15:04:07 +01005169 if (ie_len > wiphy->max_scan_ie_len) {
5170 err = -EINVAL;
5171 goto unlock;
5172 }
Johannes Berg18a83652009-03-31 12:12:05 +02005173
Johannes Berg2a519312009-02-10 21:25:55 +01005174 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005175 + sizeof(*request->ssids) * n_ssids
5176 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005177 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005178 if (!request) {
5179 err = -ENOMEM;
5180 goto unlock;
5181 }
Johannes Berg2a519312009-02-10 21:25:55 +01005182
Johannes Berg2a519312009-02-10 21:25:55 +01005183 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005184 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005185 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005186 if (ie_len) {
5187 if (request->ssids)
5188 request->ie = (void *)(request->ssids + n_ssids);
5189 else
5190 request->ie = (void *)(request->channels + n_channels);
5191 }
Johannes Berg2a519312009-02-10 21:25:55 +01005192
Johannes Berg584991d2009-11-02 13:32:03 +01005193 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005194 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5195 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005196 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005197 struct ieee80211_channel *chan;
5198
5199 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5200
5201 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005202 err = -EINVAL;
5203 goto out_free;
5204 }
Johannes Berg584991d2009-11-02 13:32:03 +01005205
5206 /* ignore disabled channels */
5207 if (chan->flags & IEEE80211_CHAN_DISABLED)
5208 continue;
5209
5210 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005211 i++;
5212 }
5213 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005214 enum ieee80211_band band;
5215
Johannes Berg2a519312009-02-10 21:25:55 +01005216 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005217 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5218 int j;
5219 if (!wiphy->bands[band])
5220 continue;
5221 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005222 struct ieee80211_channel *chan;
5223
5224 chan = &wiphy->bands[band]->channels[j];
5225
5226 if (chan->flags & IEEE80211_CHAN_DISABLED)
5227 continue;
5228
5229 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005230 i++;
5231 }
5232 }
5233 }
5234
Johannes Berg584991d2009-11-02 13:32:03 +01005235 if (!i) {
5236 err = -EINVAL;
5237 goto out_free;
5238 }
5239
5240 request->n_channels = i;
5241
Johannes Berg2a519312009-02-10 21:25:55 +01005242 i = 0;
5243 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5244 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005245 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005246 err = -EINVAL;
5247 goto out_free;
5248 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005249 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005250 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005251 i++;
5252 }
5253 }
5254
Jouni Malinen70692ad2009-02-16 19:39:13 +02005255 if (info->attrs[NL80211_ATTR_IE]) {
5256 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005257 memcpy((void *)request->ie,
5258 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005259 request->ie_len);
5260 }
5261
Johannes Berg34850ab2011-07-18 18:08:35 +02005262 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005263 if (wiphy->bands[i])
5264 request->rates[i] =
5265 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005266
5267 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5268 nla_for_each_nested(attr,
5269 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5270 tmp) {
5271 enum ieee80211_band band = nla_type(attr);
5272
Dan Carpenter84404622011-07-29 11:52:18 +03005273 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005274 err = -EINVAL;
5275 goto out_free;
5276 }
5277 err = ieee80211_get_ratemask(wiphy->bands[band],
5278 nla_data(attr),
5279 nla_len(attr),
5280 &request->rates[band]);
5281 if (err)
5282 goto out_free;
5283 }
5284 }
5285
Sam Leffler46856bb2012-10-11 21:03:32 -07005286 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005287 request->flags = nla_get_u32(
5288 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005289 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5290 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5291 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5292 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005293 err = -EOPNOTSUPP;
5294 goto out_free;
5295 }
5296 }
Sam Lefflered4737712012-10-11 21:03:31 -07005297
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305298 request->no_cck =
5299 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5300
Johannes Bergfd014282012-06-18 19:17:03 +02005301 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005302 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005303 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005304
Johannes Berg79c97e92009-07-07 03:56:12 +02005305 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005306 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005307
Johannes Berg463d0182009-07-14 00:33:35 +02005308 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005309 nl80211_send_scan_start(rdev, wdev);
5310 if (wdev->netdev)
5311 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005312 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005313 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005314 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005315 kfree(request);
5316 }
Johannes Berg3b858752009-03-12 09:55:09 +01005317
Johannes Bergf9f47522013-03-19 15:04:07 +01005318 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005319 return err;
5320}
5321
Luciano Coelho807f8a82011-05-11 17:09:35 +03005322static int nl80211_start_sched_scan(struct sk_buff *skb,
5323 struct genl_info *info)
5324{
5325 struct cfg80211_sched_scan_request *request;
5326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5327 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005328 struct nlattr *attr;
5329 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005330 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005331 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005332 enum ieee80211_band band;
5333 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005334 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005335
5336 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5337 !rdev->ops->sched_scan_start)
5338 return -EOPNOTSUPP;
5339
5340 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5341 return -EINVAL;
5342
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005343 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5344 return -EINVAL;
5345
5346 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5347 if (interval == 0)
5348 return -EINVAL;
5349
Luciano Coelho807f8a82011-05-11 17:09:35 +03005350 wiphy = &rdev->wiphy;
5351
5352 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5353 n_channels = validate_scan_freqs(
5354 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5355 if (!n_channels)
5356 return -EINVAL;
5357 } else {
5358 n_channels = 0;
5359
5360 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5361 if (wiphy->bands[band])
5362 n_channels += wiphy->bands[band]->n_channels;
5363 }
5364
5365 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5366 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5367 tmp)
5368 n_ssids++;
5369
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005370 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005371 return -EINVAL;
5372
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005373 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5374 nla_for_each_nested(attr,
5375 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5376 tmp)
5377 n_match_sets++;
5378
5379 if (n_match_sets > wiphy->max_match_sets)
5380 return -EINVAL;
5381
Luciano Coelho807f8a82011-05-11 17:09:35 +03005382 if (info->attrs[NL80211_ATTR_IE])
5383 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5384 else
5385 ie_len = 0;
5386
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005387 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005388 return -EINVAL;
5389
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005390 if (rdev->sched_scan_req) {
5391 err = -EINPROGRESS;
5392 goto out;
5393 }
5394
Luciano Coelho807f8a82011-05-11 17:09:35 +03005395 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005396 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005397 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005398 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005399 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005400 if (!request) {
5401 err = -ENOMEM;
5402 goto out;
5403 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005404
5405 if (n_ssids)
5406 request->ssids = (void *)&request->channels[n_channels];
5407 request->n_ssids = n_ssids;
5408 if (ie_len) {
5409 if (request->ssids)
5410 request->ie = (void *)(request->ssids + n_ssids);
5411 else
5412 request->ie = (void *)(request->channels + n_channels);
5413 }
5414
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005415 if (n_match_sets) {
5416 if (request->ie)
5417 request->match_sets = (void *)(request->ie + ie_len);
5418 else if (request->ssids)
5419 request->match_sets =
5420 (void *)(request->ssids + n_ssids);
5421 else
5422 request->match_sets =
5423 (void *)(request->channels + n_channels);
5424 }
5425 request->n_match_sets = n_match_sets;
5426
Luciano Coelho807f8a82011-05-11 17:09:35 +03005427 i = 0;
5428 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5429 /* user specified, bail out if channel not found */
5430 nla_for_each_nested(attr,
5431 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5432 tmp) {
5433 struct ieee80211_channel *chan;
5434
5435 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5436
5437 if (!chan) {
5438 err = -EINVAL;
5439 goto out_free;
5440 }
5441
5442 /* ignore disabled channels */
5443 if (chan->flags & IEEE80211_CHAN_DISABLED)
5444 continue;
5445
5446 request->channels[i] = chan;
5447 i++;
5448 }
5449 } else {
5450 /* all channels */
5451 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5452 int j;
5453 if (!wiphy->bands[band])
5454 continue;
5455 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5456 struct ieee80211_channel *chan;
5457
5458 chan = &wiphy->bands[band]->channels[j];
5459
5460 if (chan->flags & IEEE80211_CHAN_DISABLED)
5461 continue;
5462
5463 request->channels[i] = chan;
5464 i++;
5465 }
5466 }
5467 }
5468
5469 if (!i) {
5470 err = -EINVAL;
5471 goto out_free;
5472 }
5473
5474 request->n_channels = i;
5475
5476 i = 0;
5477 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5478 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5479 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005480 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005481 err = -EINVAL;
5482 goto out_free;
5483 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005484 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005485 memcpy(request->ssids[i].ssid, nla_data(attr),
5486 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005487 i++;
5488 }
5489 }
5490
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005491 i = 0;
5492 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5493 nla_for_each_nested(attr,
5494 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5495 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005496 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005497
5498 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5499 nla_data(attr), nla_len(attr),
5500 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005501 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005502 if (ssid) {
5503 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5504 err = -EINVAL;
5505 goto out_free;
5506 }
5507 memcpy(request->match_sets[i].ssid.ssid,
5508 nla_data(ssid), nla_len(ssid));
5509 request->match_sets[i].ssid.ssid_len =
5510 nla_len(ssid);
5511 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005512 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5513 if (rssi)
5514 request->rssi_thold = nla_get_u32(rssi);
5515 else
5516 request->rssi_thold =
5517 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005518 i++;
5519 }
5520 }
5521
Luciano Coelho807f8a82011-05-11 17:09:35 +03005522 if (info->attrs[NL80211_ATTR_IE]) {
5523 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5524 memcpy((void *)request->ie,
5525 nla_data(info->attrs[NL80211_ATTR_IE]),
5526 request->ie_len);
5527 }
5528
Sam Leffler46856bb2012-10-11 21:03:32 -07005529 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005530 request->flags = nla_get_u32(
5531 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005532 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5533 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5534 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5535 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005536 err = -EOPNOTSUPP;
5537 goto out_free;
5538 }
5539 }
Sam Lefflered4737712012-10-11 21:03:31 -07005540
Luciano Coelho807f8a82011-05-11 17:09:35 +03005541 request->dev = dev;
5542 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005543 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005544 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005545
Hila Gonene35e4d22012-06-27 17:19:42 +03005546 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005547 if (!err) {
5548 rdev->sched_scan_req = request;
5549 nl80211_send_sched_scan(rdev, dev,
5550 NL80211_CMD_START_SCHED_SCAN);
5551 goto out;
5552 }
5553
5554out_free:
5555 kfree(request);
5556out:
5557 return err;
5558}
5559
5560static int nl80211_stop_sched_scan(struct sk_buff *skb,
5561 struct genl_info *info)
5562{
5563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5564
5565 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5566 !rdev->ops->sched_scan_stop)
5567 return -EOPNOTSUPP;
5568
Johannes Berg5fe231e2013-05-08 21:45:15 +02005569 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005570}
5571
Simon Wunderlich04f39042013-02-08 18:16:19 +01005572static int nl80211_start_radar_detection(struct sk_buff *skb,
5573 struct genl_info *info)
5574{
5575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5576 struct net_device *dev = info->user_ptr[1];
5577 struct wireless_dev *wdev = dev->ieee80211_ptr;
5578 struct cfg80211_chan_def chandef;
5579 int err;
5580
5581 err = nl80211_parse_chandef(rdev, info, &chandef);
5582 if (err)
5583 return err;
5584
5585 if (wdev->cac_started)
5586 return -EBUSY;
5587
5588 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5589 if (err < 0)
5590 return err;
5591
5592 if (err == 0)
5593 return -EINVAL;
5594
5595 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5596 return -EINVAL;
5597
5598 if (!rdev->ops->start_radar_detection)
5599 return -EOPNOTSUPP;
5600
Simon Wunderlich04f39042013-02-08 18:16:19 +01005601 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5602 chandef.chan, CHAN_MODE_SHARED,
5603 BIT(chandef.width));
5604 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005605 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005606
5607 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5608 if (!err) {
5609 wdev->channel = chandef.chan;
5610 wdev->cac_started = true;
5611 wdev->cac_start_time = jiffies;
5612 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005613 return err;
5614}
5615
Johannes Berg9720bb32011-06-21 09:45:33 +02005616static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5617 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005618 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005619 struct wireless_dev *wdev,
5620 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005621{
Johannes Berg48ab9052009-07-10 18:42:31 +02005622 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005623 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005624 void *hdr;
5625 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005626 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005627
5628 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005629
Eric W. Biederman15e47302012-09-07 20:12:54 +00005630 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005631 NL80211_CMD_NEW_SCAN_RESULTS);
5632 if (!hdr)
5633 return -1;
5634
Johannes Berg9720bb32011-06-21 09:45:33 +02005635 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5636
Johannes Berg97990a02013-04-19 01:02:55 +02005637 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5638 goto nla_put_failure;
5639 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005640 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5641 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005642 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5643 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005644
5645 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5646 if (!bss)
5647 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005648 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005649 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005650 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005651
5652 rcu_read_lock();
5653 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005654 if (ies) {
5655 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5656 goto fail_unlock_rcu;
5657 tsf = true;
5658 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5659 ies->len, ies->data))
5660 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005661 }
5662 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005663 if (ies) {
5664 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5665 goto fail_unlock_rcu;
5666 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5667 ies->len, ies->data))
5668 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005669 }
5670 rcu_read_unlock();
5671
David S. Miller9360ffd2012-03-29 04:41:26 -04005672 if (res->beacon_interval &&
5673 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5674 goto nla_put_failure;
5675 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5676 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5677 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5678 jiffies_to_msecs(jiffies - intbss->ts)))
5679 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005680
Johannes Berg77965c972009-02-18 18:45:06 +01005681 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005682 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005683 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5684 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005685 break;
5686 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005687 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5688 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005689 break;
5690 default:
5691 break;
5692 }
5693
Johannes Berg48ab9052009-07-10 18:42:31 +02005694 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005695 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005696 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005697 if (intbss == wdev->current_bss &&
5698 nla_put_u32(msg, NL80211_BSS_STATUS,
5699 NL80211_BSS_STATUS_ASSOCIATED))
5700 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005701 break;
5702 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005703 if (intbss == wdev->current_bss &&
5704 nla_put_u32(msg, NL80211_BSS_STATUS,
5705 NL80211_BSS_STATUS_IBSS_JOINED))
5706 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005707 break;
5708 default:
5709 break;
5710 }
5711
Johannes Berg2a519312009-02-10 21:25:55 +01005712 nla_nest_end(msg, bss);
5713
5714 return genlmsg_end(msg, hdr);
5715
Johannes Berg8cef2c92013-02-05 16:54:31 +01005716 fail_unlock_rcu:
5717 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005718 nla_put_failure:
5719 genlmsg_cancel(msg, hdr);
5720 return -EMSGSIZE;
5721}
5722
Johannes Berg97990a02013-04-19 01:02:55 +02005723static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005724{
Johannes Berg48ab9052009-07-10 18:42:31 +02005725 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005726 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005727 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005728 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005729 int err;
5730
Johannes Berg97990a02013-04-19 01:02:55 +02005731 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005732 if (err)
5733 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005734
Johannes Berg48ab9052009-07-10 18:42:31 +02005735 wdev_lock(wdev);
5736 spin_lock_bh(&rdev->bss_lock);
5737 cfg80211_bss_expire(rdev);
5738
Johannes Berg9720bb32011-06-21 09:45:33 +02005739 cb->seq = rdev->bss_generation;
5740
Johannes Berg48ab9052009-07-10 18:42:31 +02005741 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005742 if (++idx <= start)
5743 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005744 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005745 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005746 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005747 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005748 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005749 }
5750 }
5751
Johannes Berg48ab9052009-07-10 18:42:31 +02005752 spin_unlock_bh(&rdev->bss_lock);
5753 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005754
Johannes Berg97990a02013-04-19 01:02:55 +02005755 cb->args[2] = idx;
5756 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005757
Johannes Berg67748892010-10-04 21:14:06 +02005758 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005759}
5760
Eric W. Biederman15e47302012-09-07 20:12:54 +00005761static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005762 int flags, struct net_device *dev,
5763 struct survey_info *survey)
5764{
5765 void *hdr;
5766 struct nlattr *infoattr;
5767
Eric W. Biederman15e47302012-09-07 20:12:54 +00005768 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005769 NL80211_CMD_NEW_SURVEY_RESULTS);
5770 if (!hdr)
5771 return -ENOMEM;
5772
David S. Miller9360ffd2012-03-29 04:41:26 -04005773 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5774 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005775
5776 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5777 if (!infoattr)
5778 goto nla_put_failure;
5779
David S. Miller9360ffd2012-03-29 04:41:26 -04005780 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5781 survey->channel->center_freq))
5782 goto nla_put_failure;
5783
5784 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5785 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5786 goto nla_put_failure;
5787 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5788 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5789 goto nla_put_failure;
5790 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5791 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5792 survey->channel_time))
5793 goto nla_put_failure;
5794 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5795 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5796 survey->channel_time_busy))
5797 goto nla_put_failure;
5798 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5799 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5800 survey->channel_time_ext_busy))
5801 goto nla_put_failure;
5802 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5803 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5804 survey->channel_time_rx))
5805 goto nla_put_failure;
5806 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5807 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5808 survey->channel_time_tx))
5809 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005810
5811 nla_nest_end(msg, infoattr);
5812
5813 return genlmsg_end(msg, hdr);
5814
5815 nla_put_failure:
5816 genlmsg_cancel(msg, hdr);
5817 return -EMSGSIZE;
5818}
5819
5820static int nl80211_dump_survey(struct sk_buff *skb,
5821 struct netlink_callback *cb)
5822{
5823 struct survey_info survey;
5824 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005825 struct wireless_dev *wdev;
5826 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005827 int res;
5828
Johannes Berg97990a02013-04-19 01:02:55 +02005829 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005830 if (res)
5831 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005832
Johannes Berg97990a02013-04-19 01:02:55 +02005833 if (!wdev->netdev) {
5834 res = -EINVAL;
5835 goto out_err;
5836 }
5837
Holger Schurig61fa7132009-11-11 12:25:40 +01005838 if (!dev->ops->dump_survey) {
5839 res = -EOPNOTSUPP;
5840 goto out_err;
5841 }
5842
5843 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005844 struct ieee80211_channel *chan;
5845
Johannes Berg97990a02013-04-19 01:02:55 +02005846 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005847 if (res == -ENOENT)
5848 break;
5849 if (res)
5850 goto out_err;
5851
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005852 /* Survey without a channel doesn't make sense */
5853 if (!survey.channel) {
5854 res = -EINVAL;
5855 goto out;
5856 }
5857
5858 chan = ieee80211_get_channel(&dev->wiphy,
5859 survey.channel->center_freq);
5860 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5861 survey_idx++;
5862 continue;
5863 }
5864
Holger Schurig61fa7132009-11-11 12:25:40 +01005865 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005866 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005867 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005868 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005869 goto out;
5870 survey_idx++;
5871 }
5872
5873 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005874 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005875 res = skb->len;
5876 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005877 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005878 return res;
5879}
5880
Samuel Ortizb23aa672009-07-01 21:26:54 +02005881static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5882{
5883 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5884 NL80211_WPA_VERSION_2));
5885}
5886
Jouni Malinen636a5d32009-03-19 13:39:22 +02005887static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5888{
Johannes Berg4c476992010-10-04 21:36:35 +02005889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5890 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005891 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005892 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5893 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005894 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005895 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005896 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005897
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005898 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5899 return -EINVAL;
5900
5901 if (!info->attrs[NL80211_ATTR_MAC])
5902 return -EINVAL;
5903
Jouni Malinen17780922009-03-27 20:52:47 +02005904 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5905 return -EINVAL;
5906
Johannes Berg19957bb2009-07-02 17:20:43 +02005907 if (!info->attrs[NL80211_ATTR_SSID])
5908 return -EINVAL;
5909
5910 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5911 return -EINVAL;
5912
Johannes Bergfffd0932009-07-08 14:22:54 +02005913 err = nl80211_parse_key(info, &key);
5914 if (err)
5915 return err;
5916
5917 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005918 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5919 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005920 if (!key.p.key || !key.p.key_len)
5921 return -EINVAL;
5922 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5923 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5924 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5925 key.p.key_len != WLAN_KEY_LEN_WEP104))
5926 return -EINVAL;
5927 if (key.idx > 4)
5928 return -EINVAL;
5929 } else {
5930 key.p.key_len = 0;
5931 key.p.key = NULL;
5932 }
5933
Johannes Bergafea0b72010-08-10 09:46:42 +02005934 if (key.idx >= 0) {
5935 int i;
5936 bool ok = false;
5937 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5938 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5939 ok = true;
5940 break;
5941 }
5942 }
Johannes Berg4c476992010-10-04 21:36:35 +02005943 if (!ok)
5944 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005945 }
5946
Johannes Berg4c476992010-10-04 21:36:35 +02005947 if (!rdev->ops->auth)
5948 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005949
Johannes Berg074ac8d2010-09-16 14:58:22 +02005950 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005951 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5952 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005953
Johannes Berg19957bb2009-07-02 17:20:43 +02005954 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005955 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005956 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005957 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5958 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005959
Johannes Berg19957bb2009-07-02 17:20:43 +02005960 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5961 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5962
5963 if (info->attrs[NL80211_ATTR_IE]) {
5964 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5965 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5966 }
5967
5968 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005969 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005970 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005971
Jouni Malinene39e5b52012-09-30 19:29:39 +03005972 if (auth_type == NL80211_AUTHTYPE_SAE &&
5973 !info->attrs[NL80211_ATTR_SAE_DATA])
5974 return -EINVAL;
5975
5976 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5977 if (auth_type != NL80211_AUTHTYPE_SAE)
5978 return -EINVAL;
5979 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5980 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5981 /* need to include at least Auth Transaction and Status Code */
5982 if (sae_data_len < 4)
5983 return -EINVAL;
5984 }
5985
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005986 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5987
Johannes Berg95de8172012-01-20 13:55:25 +01005988 /*
5989 * Since we no longer track auth state, ignore
5990 * requests to only change local state.
5991 */
5992 if (local_state_change)
5993 return 0;
5994
Johannes Berg91bf9b22013-05-15 17:44:01 +02005995 wdev_lock(dev->ieee80211_ptr);
5996 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5997 ssid, ssid_len, ie, ie_len,
5998 key.p.key, key.p.key_len, key.idx,
5999 sae_data, sae_data_len);
6000 wdev_unlock(dev->ieee80211_ptr);
6001 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006002}
6003
Johannes Bergc0692b82010-08-27 14:26:53 +03006004static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6005 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006006 struct cfg80211_crypto_settings *settings,
6007 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006008{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006009 memset(settings, 0, sizeof(*settings));
6010
Samuel Ortizb23aa672009-07-01 21:26:54 +02006011 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6012
Johannes Bergc0692b82010-08-27 14:26:53 +03006013 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6014 u16 proto;
6015 proto = nla_get_u16(
6016 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6017 settings->control_port_ethertype = cpu_to_be16(proto);
6018 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6019 proto != ETH_P_PAE)
6020 return -EINVAL;
6021 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6022 settings->control_port_no_encrypt = true;
6023 } else
6024 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6025
Samuel Ortizb23aa672009-07-01 21:26:54 +02006026 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6027 void *data;
6028 int len, i;
6029
6030 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6031 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6032 settings->n_ciphers_pairwise = len / sizeof(u32);
6033
6034 if (len % sizeof(u32))
6035 return -EINVAL;
6036
Johannes Berg3dc27d22009-07-02 21:36:37 +02006037 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006038 return -EINVAL;
6039
6040 memcpy(settings->ciphers_pairwise, data, len);
6041
6042 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006043 if (!cfg80211_supported_cipher_suite(
6044 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006045 settings->ciphers_pairwise[i]))
6046 return -EINVAL;
6047 }
6048
6049 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6050 settings->cipher_group =
6051 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006052 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6053 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006054 return -EINVAL;
6055 }
6056
6057 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6058 settings->wpa_versions =
6059 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6060 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6061 return -EINVAL;
6062 }
6063
6064 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6065 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006066 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006067
6068 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6069 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6070 settings->n_akm_suites = len / sizeof(u32);
6071
6072 if (len % sizeof(u32))
6073 return -EINVAL;
6074
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006075 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6076 return -EINVAL;
6077
Samuel Ortizb23aa672009-07-01 21:26:54 +02006078 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006079 }
6080
6081 return 0;
6082}
6083
Jouni Malinen636a5d32009-03-19 13:39:22 +02006084static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6085{
Johannes Berg4c476992010-10-04 21:36:35 +02006086 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6087 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006088 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006089 struct cfg80211_assoc_request req = {};
6090 const u8 *bssid, *ssid;
6091 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006092
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006093 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6094 return -EINVAL;
6095
6096 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006097 !info->attrs[NL80211_ATTR_SSID] ||
6098 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006099 return -EINVAL;
6100
Johannes Berg4c476992010-10-04 21:36:35 +02006101 if (!rdev->ops->assoc)
6102 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006103
Johannes Berg074ac8d2010-09-16 14:58:22 +02006104 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006105 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6106 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006107
Johannes Berg19957bb2009-07-02 17:20:43 +02006108 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006109
Johannes Berg19957bb2009-07-02 17:20:43 +02006110 chan = ieee80211_get_channel(&rdev->wiphy,
6111 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006112 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6113 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006114
Johannes Berg19957bb2009-07-02 17:20:43 +02006115 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6116 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006117
6118 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006119 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6120 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006121 }
6122
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006123 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006124 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006125 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006126 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006127 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006128 else if (mfp != NL80211_MFP_NO)
6129 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006130 }
6131
Johannes Berg3e5d7642009-07-07 14:37:26 +02006132 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006133 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006134
Ben Greear7e7c8922011-11-18 11:31:59 -08006135 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006136 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006137
6138 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006139 memcpy(&req.ht_capa_mask,
6140 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6141 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006142
6143 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006144 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006145 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006146 memcpy(&req.ht_capa,
6147 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6148 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006149 }
6150
Johannes Bergee2aca32013-02-21 17:36:01 +01006151 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006152 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006153
6154 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006155 memcpy(&req.vht_capa_mask,
6156 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6157 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006158
6159 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006160 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006161 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006162 memcpy(&req.vht_capa,
6163 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6164 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006165 }
6166
Johannes Bergf62fab72013-02-21 20:09:09 +01006167 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006168 if (!err) {
6169 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006170 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6171 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006172 wdev_unlock(dev->ieee80211_ptr);
6173 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006174
Jouni Malinen636a5d32009-03-19 13:39:22 +02006175 return err;
6176}
6177
6178static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6179{
Johannes Berg4c476992010-10-04 21:36:35 +02006180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6181 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006182 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006183 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006184 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006185 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006186
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006187 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6188 return -EINVAL;
6189
6190 if (!info->attrs[NL80211_ATTR_MAC])
6191 return -EINVAL;
6192
6193 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6194 return -EINVAL;
6195
Johannes Berg4c476992010-10-04 21:36:35 +02006196 if (!rdev->ops->deauth)
6197 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006198
Johannes Berg074ac8d2010-09-16 14:58:22 +02006199 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006200 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6201 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006202
Johannes Berg19957bb2009-07-02 17:20:43 +02006203 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006204
Johannes Berg19957bb2009-07-02 17:20:43 +02006205 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6206 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006207 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006208 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006209 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006210
6211 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006212 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6213 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006214 }
6215
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006216 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6217
Johannes Berg91bf9b22013-05-15 17:44:01 +02006218 wdev_lock(dev->ieee80211_ptr);
6219 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6220 local_state_change);
6221 wdev_unlock(dev->ieee80211_ptr);
6222 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006223}
6224
6225static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6226{
Johannes Berg4c476992010-10-04 21:36:35 +02006227 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6228 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006229 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006230 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006231 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006232 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006233
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006234 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6235 return -EINVAL;
6236
6237 if (!info->attrs[NL80211_ATTR_MAC])
6238 return -EINVAL;
6239
6240 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6241 return -EINVAL;
6242
Johannes Berg4c476992010-10-04 21:36:35 +02006243 if (!rdev->ops->disassoc)
6244 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006245
Johannes Berg074ac8d2010-09-16 14:58:22 +02006246 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006247 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6248 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006249
Johannes Berg19957bb2009-07-02 17:20:43 +02006250 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006251
Johannes Berg19957bb2009-07-02 17:20:43 +02006252 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6253 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006254 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006255 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006256 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006257
6258 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006259 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6260 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006261 }
6262
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006263 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6264
Johannes Berg91bf9b22013-05-15 17:44:01 +02006265 wdev_lock(dev->ieee80211_ptr);
6266 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6267 local_state_change);
6268 wdev_unlock(dev->ieee80211_ptr);
6269 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006270}
6271
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006272static bool
6273nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6274 int mcast_rate[IEEE80211_NUM_BANDS],
6275 int rateval)
6276{
6277 struct wiphy *wiphy = &rdev->wiphy;
6278 bool found = false;
6279 int band, i;
6280
6281 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6282 struct ieee80211_supported_band *sband;
6283
6284 sband = wiphy->bands[band];
6285 if (!sband)
6286 continue;
6287
6288 for (i = 0; i < sband->n_bitrates; i++) {
6289 if (sband->bitrates[i].bitrate == rateval) {
6290 mcast_rate[band] = i + 1;
6291 found = true;
6292 break;
6293 }
6294 }
6295 }
6296
6297 return found;
6298}
6299
Johannes Berg04a773a2009-04-19 21:24:32 +02006300static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6301{
Johannes Berg4c476992010-10-04 21:36:35 +02006302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6303 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006304 struct cfg80211_ibss_params ibss;
6305 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006306 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006307 int err;
6308
Johannes Berg8e30bc52009-04-22 17:45:38 +02006309 memset(&ibss, 0, sizeof(ibss));
6310
Johannes Berg04a773a2009-04-19 21:24:32 +02006311 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6312 return -EINVAL;
6313
Johannes Berg683b6d32012-11-08 21:25:48 +01006314 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006315 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6316 return -EINVAL;
6317
Johannes Berg8e30bc52009-04-22 17:45:38 +02006318 ibss.beacon_interval = 100;
6319
6320 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6321 ibss.beacon_interval =
6322 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6323 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6324 return -EINVAL;
6325 }
6326
Johannes Berg4c476992010-10-04 21:36:35 +02006327 if (!rdev->ops->join_ibss)
6328 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006329
Johannes Berg4c476992010-10-04 21:36:35 +02006330 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6331 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006332
Johannes Berg79c97e92009-07-07 03:56:12 +02006333 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006334
Johannes Berg39193492011-09-16 13:45:25 +02006335 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006336 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006337
6338 if (!is_valid_ether_addr(ibss.bssid))
6339 return -EINVAL;
6340 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006341 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6342 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6343
6344 if (info->attrs[NL80211_ATTR_IE]) {
6345 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6346 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6347 }
6348
Johannes Berg683b6d32012-11-08 21:25:48 +01006349 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6350 if (err)
6351 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006352
Johannes Berg683b6d32012-11-08 21:25:48 +01006353 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006354 return -EINVAL;
6355
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006356 switch (ibss.chandef.width) {
6357 case NL80211_CHAN_WIDTH_20_NOHT:
6358 break;
6359 case NL80211_CHAN_WIDTH_20:
6360 case NL80211_CHAN_WIDTH_40:
6361 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6362 break;
6363 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006364 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006365 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006366
Johannes Berg04a773a2009-04-19 21:24:32 +02006367 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006368 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006369
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006370 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6371 u8 *rates =
6372 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6373 int n_rates =
6374 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6375 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006376 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006377
Johannes Berg34850ab2011-07-18 18:08:35 +02006378 err = ieee80211_get_ratemask(sband, rates, n_rates,
6379 &ibss.basic_rates);
6380 if (err)
6381 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006382 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006383
Simon Wunderlich803768f2013-06-28 10:39:58 +02006384 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6385 memcpy(&ibss.ht_capa_mask,
6386 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6387 sizeof(ibss.ht_capa_mask));
6388
6389 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6390 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6391 return -EINVAL;
6392 memcpy(&ibss.ht_capa,
6393 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6394 sizeof(ibss.ht_capa));
6395 }
6396
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006397 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6398 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6399 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6400 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006401
Johannes Berg4c476992010-10-04 21:36:35 +02006402 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306403 bool no_ht = false;
6404
Johannes Berg4c476992010-10-04 21:36:35 +02006405 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306406 info->attrs[NL80211_ATTR_KEYS],
6407 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006408 if (IS_ERR(connkeys))
6409 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306410
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006411 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6412 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306413 kfree(connkeys);
6414 return -EINVAL;
6415 }
Johannes Berg4c476992010-10-04 21:36:35 +02006416 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006417
Antonio Quartulli267335d2012-01-31 20:25:47 +01006418 ibss.control_port =
6419 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6420
Johannes Berg4c476992010-10-04 21:36:35 +02006421 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006422 if (err)
6423 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006424 return err;
6425}
6426
6427static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6428{
Johannes Berg4c476992010-10-04 21:36:35 +02006429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6430 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006431
Johannes Berg4c476992010-10-04 21:36:35 +02006432 if (!rdev->ops->leave_ibss)
6433 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006434
Johannes Berg4c476992010-10-04 21:36:35 +02006435 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6436 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006437
Johannes Berg4c476992010-10-04 21:36:35 +02006438 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006439}
6440
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006441static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6442{
6443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6444 struct net_device *dev = info->user_ptr[1];
6445 int mcast_rate[IEEE80211_NUM_BANDS];
6446 u32 nla_rate;
6447 int err;
6448
6449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6450 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6451 return -EOPNOTSUPP;
6452
6453 if (!rdev->ops->set_mcast_rate)
6454 return -EOPNOTSUPP;
6455
6456 memset(mcast_rate, 0, sizeof(mcast_rate));
6457
6458 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6459 return -EINVAL;
6460
6461 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6462 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6463 return -EINVAL;
6464
6465 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6466
6467 return err;
6468}
6469
6470
Johannes Bergaff89a92009-07-01 21:26:51 +02006471#ifdef CONFIG_NL80211_TESTMODE
6472static struct genl_multicast_group nl80211_testmode_mcgrp = {
6473 .name = "testmode",
6474};
6475
6476static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6477{
Johannes Berg4c476992010-10-04 21:36:35 +02006478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006479 int err;
6480
6481 if (!info->attrs[NL80211_ATTR_TESTDATA])
6482 return -EINVAL;
6483
Johannes Bergaff89a92009-07-01 21:26:51 +02006484 err = -EOPNOTSUPP;
6485 if (rdev->ops->testmode_cmd) {
6486 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006487 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006488 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6489 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6490 rdev->testmode_info = NULL;
6491 }
6492
Johannes Bergaff89a92009-07-01 21:26:51 +02006493 return err;
6494}
6495
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006496static int nl80211_testmode_dump(struct sk_buff *skb,
6497 struct netlink_callback *cb)
6498{
Johannes Berg00918d32011-12-13 17:22:05 +01006499 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006500 int err;
6501 long phy_idx;
6502 void *data = NULL;
6503 int data_len = 0;
6504
Johannes Berg5fe231e2013-05-08 21:45:15 +02006505 rtnl_lock();
6506
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006507 if (cb->args[0]) {
6508 /*
6509 * 0 is a valid index, but not valid for args[0],
6510 * so we need to offset by 1.
6511 */
6512 phy_idx = cb->args[0] - 1;
6513 } else {
6514 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6515 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6516 nl80211_policy);
6517 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006518 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006519
Johannes Berg2bd7e352012-06-15 14:23:16 +02006520 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6521 nl80211_fam.attrbuf);
6522 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006523 err = PTR_ERR(rdev);
6524 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006525 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006526 phy_idx = rdev->wiphy_idx;
6527 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006528
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006529 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6530 cb->args[1] =
6531 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6532 }
6533
6534 if (cb->args[1]) {
6535 data = nla_data((void *)cb->args[1]);
6536 data_len = nla_len((void *)cb->args[1]);
6537 }
6538
Johannes Berg00918d32011-12-13 17:22:05 +01006539 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6540 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006541 err = -ENOENT;
6542 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006543 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006544
Johannes Berg00918d32011-12-13 17:22:05 +01006545 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006546 err = -EOPNOTSUPP;
6547 goto out_err;
6548 }
6549
6550 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006551 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006552 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6553 NL80211_CMD_TESTMODE);
6554 struct nlattr *tmdata;
6555
David S. Miller9360ffd2012-03-29 04:41:26 -04006556 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006557 genlmsg_cancel(skb, hdr);
6558 break;
6559 }
6560
6561 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6562 if (!tmdata) {
6563 genlmsg_cancel(skb, hdr);
6564 break;
6565 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006566 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006567 nla_nest_end(skb, tmdata);
6568
6569 if (err == -ENOBUFS || err == -ENOENT) {
6570 genlmsg_cancel(skb, hdr);
6571 break;
6572 } else if (err) {
6573 genlmsg_cancel(skb, hdr);
6574 goto out_err;
6575 }
6576
6577 genlmsg_end(skb, hdr);
6578 }
6579
6580 err = skb->len;
6581 /* see above */
6582 cb->args[0] = phy_idx + 1;
6583 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006584 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006585 return err;
6586}
6587
Johannes Bergaff89a92009-07-01 21:26:51 +02006588static struct sk_buff *
6589__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006590 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006591{
6592 struct sk_buff *skb;
6593 void *hdr;
6594 struct nlattr *data;
6595
6596 skb = nlmsg_new(approxlen + 100, gfp);
6597 if (!skb)
6598 return NULL;
6599
Eric W. Biederman15e47302012-09-07 20:12:54 +00006600 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006601 if (!hdr) {
6602 kfree_skb(skb);
6603 return NULL;
6604 }
6605
David S. Miller9360ffd2012-03-29 04:41:26 -04006606 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6607 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006608 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6609
6610 ((void **)skb->cb)[0] = rdev;
6611 ((void **)skb->cb)[1] = hdr;
6612 ((void **)skb->cb)[2] = data;
6613
6614 return skb;
6615
6616 nla_put_failure:
6617 kfree_skb(skb);
6618 return NULL;
6619}
6620
6621struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6622 int approxlen)
6623{
6624 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6625
6626 if (WARN_ON(!rdev->testmode_info))
6627 return NULL;
6628
6629 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006630 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006631 rdev->testmode_info->snd_seq,
6632 GFP_KERNEL);
6633}
6634EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6635
6636int cfg80211_testmode_reply(struct sk_buff *skb)
6637{
6638 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6639 void *hdr = ((void **)skb->cb)[1];
6640 struct nlattr *data = ((void **)skb->cb)[2];
6641
6642 if (WARN_ON(!rdev->testmode_info)) {
6643 kfree_skb(skb);
6644 return -EINVAL;
6645 }
6646
6647 nla_nest_end(skb, data);
6648 genlmsg_end(skb, hdr);
6649 return genlmsg_reply(skb, rdev->testmode_info);
6650}
6651EXPORT_SYMBOL(cfg80211_testmode_reply);
6652
6653struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6654 int approxlen, gfp_t gfp)
6655{
6656 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6657
6658 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6659}
6660EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6661
6662void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6663{
6664 void *hdr = ((void **)skb->cb)[1];
6665 struct nlattr *data = ((void **)skb->cb)[2];
6666
6667 nla_nest_end(skb, data);
6668 genlmsg_end(skb, hdr);
6669 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6670}
6671EXPORT_SYMBOL(cfg80211_testmode_event);
6672#endif
6673
Samuel Ortizb23aa672009-07-01 21:26:54 +02006674static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6675{
Johannes Berg4c476992010-10-04 21:36:35 +02006676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6677 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006678 struct cfg80211_connect_params connect;
6679 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006680 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006681 int err;
6682
6683 memset(&connect, 0, sizeof(connect));
6684
6685 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6686 return -EINVAL;
6687
6688 if (!info->attrs[NL80211_ATTR_SSID] ||
6689 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6690 return -EINVAL;
6691
6692 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6693 connect.auth_type =
6694 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006695 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6696 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006697 return -EINVAL;
6698 } else
6699 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6700
6701 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6702
Johannes Bergc0692b82010-08-27 14:26:53 +03006703 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006704 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006705 if (err)
6706 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006707
Johannes Berg074ac8d2010-09-16 14:58:22 +02006708 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006709 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6710 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006711
Johannes Berg79c97e92009-07-07 03:56:12 +02006712 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006713
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306714 connect.bg_scan_period = -1;
6715 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6716 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6717 connect.bg_scan_period =
6718 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6719 }
6720
Samuel Ortizb23aa672009-07-01 21:26:54 +02006721 if (info->attrs[NL80211_ATTR_MAC])
6722 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6723 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6724 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6725
6726 if (info->attrs[NL80211_ATTR_IE]) {
6727 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6728 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6729 }
6730
Jouni Malinencee00a92013-01-15 17:15:57 +02006731 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6732 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6733 if (connect.mfp != NL80211_MFP_REQUIRED &&
6734 connect.mfp != NL80211_MFP_NO)
6735 return -EINVAL;
6736 } else {
6737 connect.mfp = NL80211_MFP_NO;
6738 }
6739
Samuel Ortizb23aa672009-07-01 21:26:54 +02006740 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6741 connect.channel =
6742 ieee80211_get_channel(wiphy,
6743 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6744 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006745 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6746 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006747 }
6748
Johannes Bergfffd0932009-07-08 14:22:54 +02006749 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6750 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306751 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006752 if (IS_ERR(connkeys))
6753 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006754 }
6755
Ben Greear7e7c8922011-11-18 11:31:59 -08006756 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6757 connect.flags |= ASSOC_REQ_DISABLE_HT;
6758
6759 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6760 memcpy(&connect.ht_capa_mask,
6761 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6762 sizeof(connect.ht_capa_mask));
6763
6764 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006765 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6766 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006767 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006768 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006769 memcpy(&connect.ht_capa,
6770 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6771 sizeof(connect.ht_capa));
6772 }
6773
Johannes Bergee2aca32013-02-21 17:36:01 +01006774 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6775 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6776
6777 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6778 memcpy(&connect.vht_capa_mask,
6779 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6780 sizeof(connect.vht_capa_mask));
6781
6782 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6783 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6784 kfree(connkeys);
6785 return -EINVAL;
6786 }
6787 memcpy(&connect.vht_capa,
6788 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6789 sizeof(connect.vht_capa));
6790 }
6791
Johannes Berg83739b02013-05-15 17:44:01 +02006792 wdev_lock(dev->ieee80211_ptr);
6793 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6794 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006795 if (err)
6796 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006797 return err;
6798}
6799
6800static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6801{
Johannes Berg4c476992010-10-04 21:36:35 +02006802 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6803 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006804 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006805 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006806
6807 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6808 reason = WLAN_REASON_DEAUTH_LEAVING;
6809 else
6810 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6811
6812 if (reason == 0)
6813 return -EINVAL;
6814
Johannes Berg074ac8d2010-09-16 14:58:22 +02006815 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006816 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6817 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006818
Johannes Berg83739b02013-05-15 17:44:01 +02006819 wdev_lock(dev->ieee80211_ptr);
6820 ret = cfg80211_disconnect(rdev, dev, reason, true);
6821 wdev_unlock(dev->ieee80211_ptr);
6822 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006823}
6824
Johannes Berg463d0182009-07-14 00:33:35 +02006825static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6826{
Johannes Berg4c476992010-10-04 21:36:35 +02006827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006828 struct net *net;
6829 int err;
6830 u32 pid;
6831
6832 if (!info->attrs[NL80211_ATTR_PID])
6833 return -EINVAL;
6834
6835 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6836
Johannes Berg463d0182009-07-14 00:33:35 +02006837 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006838 if (IS_ERR(net))
6839 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006840
6841 err = 0;
6842
6843 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006844 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6845 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006846
Johannes Berg463d0182009-07-14 00:33:35 +02006847 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006848 return err;
6849}
6850
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006851static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6852{
Johannes Berg4c476992010-10-04 21:36:35 +02006853 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006854 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6855 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006856 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006857 struct cfg80211_pmksa pmksa;
6858
6859 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6860
6861 if (!info->attrs[NL80211_ATTR_MAC])
6862 return -EINVAL;
6863
6864 if (!info->attrs[NL80211_ATTR_PMKID])
6865 return -EINVAL;
6866
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006867 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6868 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6869
Johannes Berg074ac8d2010-09-16 14:58:22 +02006870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006871 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6872 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006873
6874 switch (info->genlhdr->cmd) {
6875 case NL80211_CMD_SET_PMKSA:
6876 rdev_ops = rdev->ops->set_pmksa;
6877 break;
6878 case NL80211_CMD_DEL_PMKSA:
6879 rdev_ops = rdev->ops->del_pmksa;
6880 break;
6881 default:
6882 WARN_ON(1);
6883 break;
6884 }
6885
Johannes Berg4c476992010-10-04 21:36:35 +02006886 if (!rdev_ops)
6887 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006888
Johannes Berg4c476992010-10-04 21:36:35 +02006889 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006890}
6891
6892static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6893{
Johannes Berg4c476992010-10-04 21:36:35 +02006894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6895 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006896
Johannes Berg074ac8d2010-09-16 14:58:22 +02006897 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006898 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6899 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006900
Johannes Berg4c476992010-10-04 21:36:35 +02006901 if (!rdev->ops->flush_pmksa)
6902 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006903
Hila Gonene35e4d22012-06-27 17:19:42 +03006904 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006905}
6906
Arik Nemtsov109086c2011-09-28 14:12:50 +03006907static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6908{
6909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6910 struct net_device *dev = info->user_ptr[1];
6911 u8 action_code, dialog_token;
6912 u16 status_code;
6913 u8 *peer;
6914
6915 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6916 !rdev->ops->tdls_mgmt)
6917 return -EOPNOTSUPP;
6918
6919 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6920 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6921 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6922 !info->attrs[NL80211_ATTR_IE] ||
6923 !info->attrs[NL80211_ATTR_MAC])
6924 return -EINVAL;
6925
6926 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6927 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6928 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6929 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6930
Hila Gonene35e4d22012-06-27 17:19:42 +03006931 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6932 dialog_token, status_code,
6933 nla_data(info->attrs[NL80211_ATTR_IE]),
6934 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006935}
6936
6937static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6938{
6939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6940 struct net_device *dev = info->user_ptr[1];
6941 enum nl80211_tdls_operation operation;
6942 u8 *peer;
6943
6944 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6945 !rdev->ops->tdls_oper)
6946 return -EOPNOTSUPP;
6947
6948 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6949 !info->attrs[NL80211_ATTR_MAC])
6950 return -EINVAL;
6951
6952 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6953 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6954
Hila Gonene35e4d22012-06-27 17:19:42 +03006955 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006956}
6957
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006958static int nl80211_remain_on_channel(struct sk_buff *skb,
6959 struct genl_info *info)
6960{
Johannes Berg4c476992010-10-04 21:36:35 +02006961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006962 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006963 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006964 struct sk_buff *msg;
6965 void *hdr;
6966 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006967 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006968 int err;
6969
6970 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6971 !info->attrs[NL80211_ATTR_DURATION])
6972 return -EINVAL;
6973
6974 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6975
Johannes Berg7c4ef712011-11-18 15:33:48 +01006976 if (!rdev->ops->remain_on_channel ||
6977 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006978 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006979
Johannes Bergebf348f2012-06-01 12:50:54 +02006980 /*
6981 * We should be on that channel for at least a minimum amount of
6982 * time (10ms) but no longer than the driver supports.
6983 */
6984 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6985 duration > rdev->wiphy.max_remain_on_channel_duration)
6986 return -EINVAL;
6987
Johannes Berg683b6d32012-11-08 21:25:48 +01006988 err = nl80211_parse_chandef(rdev, info, &chandef);
6989 if (err)
6990 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006991
6992 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006993 if (!msg)
6994 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006995
Eric W. Biederman15e47302012-09-07 20:12:54 +00006996 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006997 NL80211_CMD_REMAIN_ON_CHANNEL);
6998
6999 if (IS_ERR(hdr)) {
7000 err = PTR_ERR(hdr);
7001 goto free_msg;
7002 }
7003
Johannes Berg683b6d32012-11-08 21:25:48 +01007004 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7005 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007006
7007 if (err)
7008 goto free_msg;
7009
David S. Miller9360ffd2012-03-29 04:41:26 -04007010 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7011 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007012
7013 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007014
7015 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007016
7017 nla_put_failure:
7018 err = -ENOBUFS;
7019 free_msg:
7020 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007021 return err;
7022}
7023
7024static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7025 struct genl_info *info)
7026{
Johannes Berg4c476992010-10-04 21:36:35 +02007027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007028 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007029 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007030
7031 if (!info->attrs[NL80211_ATTR_COOKIE])
7032 return -EINVAL;
7033
Johannes Berg4c476992010-10-04 21:36:35 +02007034 if (!rdev->ops->cancel_remain_on_channel)
7035 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007036
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007037 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7038
Hila Gonene35e4d22012-06-27 17:19:42 +03007039 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007040}
7041
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007042static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7043 u8 *rates, u8 rates_len)
7044{
7045 u8 i;
7046 u32 mask = 0;
7047
7048 for (i = 0; i < rates_len; i++) {
7049 int rate = (rates[i] & 0x7f) * 5;
7050 int ridx;
7051 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7052 struct ieee80211_rate *srate =
7053 &sband->bitrates[ridx];
7054 if (rate == srate->bitrate) {
7055 mask |= 1 << ridx;
7056 break;
7057 }
7058 }
7059 if (ridx == sband->n_bitrates)
7060 return 0; /* rate not found */
7061 }
7062
7063 return mask;
7064}
7065
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007066static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7067 u8 *rates, u8 rates_len,
7068 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7069{
7070 u8 i;
7071
7072 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7073
7074 for (i = 0; i < rates_len; i++) {
7075 int ridx, rbit;
7076
7077 ridx = rates[i] / 8;
7078 rbit = BIT(rates[i] % 8);
7079
7080 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007081 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007082 return false;
7083
7084 /* check availability */
7085 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7086 mcs[ridx] |= rbit;
7087 else
7088 return false;
7089 }
7090
7091 return true;
7092}
7093
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007094static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007095 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7096 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007097 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7098 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007099};
7100
7101static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7102 struct genl_info *info)
7103{
7104 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007106 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007107 int rem, i;
7108 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007109 struct nlattr *tx_rates;
7110 struct ieee80211_supported_band *sband;
7111
7112 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7113 return -EINVAL;
7114
Johannes Berg4c476992010-10-04 21:36:35 +02007115 if (!rdev->ops->set_bitrate_mask)
7116 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007117
7118 memset(&mask, 0, sizeof(mask));
7119 /* Default to all rates enabled */
7120 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7121 sband = rdev->wiphy.bands[i];
7122 mask.control[i].legacy =
7123 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007124 if (sband)
7125 memcpy(mask.control[i].mcs,
7126 sband->ht_cap.mcs.rx_mask,
7127 sizeof(mask.control[i].mcs));
7128 else
7129 memset(mask.control[i].mcs, 0,
7130 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007131 }
7132
7133 /*
7134 * The nested attribute uses enum nl80211_band as the index. This maps
7135 * directly to the enum ieee80211_band values used in cfg80211.
7136 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007137 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007138 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7139 {
7140 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007141 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7142 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007143 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007144 if (sband == NULL)
7145 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007146 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7147 nla_len(tx_rates), nl80211_txattr_policy);
7148 if (tb[NL80211_TXRATE_LEGACY]) {
7149 mask.control[band].legacy = rateset_to_mask(
7150 sband,
7151 nla_data(tb[NL80211_TXRATE_LEGACY]),
7152 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307153 if ((mask.control[band].legacy == 0) &&
7154 nla_len(tb[NL80211_TXRATE_LEGACY]))
7155 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007156 }
7157 if (tb[NL80211_TXRATE_MCS]) {
7158 if (!ht_rateset_to_mask(
7159 sband,
7160 nla_data(tb[NL80211_TXRATE_MCS]),
7161 nla_len(tb[NL80211_TXRATE_MCS]),
7162 mask.control[band].mcs))
7163 return -EINVAL;
7164 }
7165
7166 if (mask.control[band].legacy == 0) {
7167 /* don't allow empty legacy rates if HT
7168 * is not even supported. */
7169 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7170 return -EINVAL;
7171
7172 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7173 if (mask.control[band].mcs[i])
7174 break;
7175
7176 /* legacy and mcs rates may not be both empty */
7177 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007178 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007179 }
7180 }
7181
Hila Gonene35e4d22012-06-27 17:19:42 +03007182 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007183}
7184
Johannes Berg2e161f782010-08-12 15:38:38 +02007185static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007186{
Johannes Berg4c476992010-10-04 21:36:35 +02007187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007188 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02007189 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007190
7191 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7192 return -EINVAL;
7193
Johannes Berg2e161f782010-08-12 15:38:38 +02007194 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7195 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007196
Johannes Berg71bbc992012-06-15 15:30:18 +02007197 switch (wdev->iftype) {
7198 case NL80211_IFTYPE_STATION:
7199 case NL80211_IFTYPE_ADHOC:
7200 case NL80211_IFTYPE_P2P_CLIENT:
7201 case NL80211_IFTYPE_AP:
7202 case NL80211_IFTYPE_AP_VLAN:
7203 case NL80211_IFTYPE_MESH_POINT:
7204 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007205 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007206 break;
7207 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007208 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007209 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007210
7211 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007212 if (!rdev->ops->mgmt_tx)
7213 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007214
Eric W. Biederman15e47302012-09-07 20:12:54 +00007215 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007216 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7217 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007218}
7219
Johannes Berg2e161f782010-08-12 15:38:38 +02007220static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007221{
Johannes Berg4c476992010-10-04 21:36:35 +02007222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007223 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007224 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007225 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007226 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007227 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007228 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007229 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007230 bool offchan, no_cck, dont_wait_for_ack;
7231
7232 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007233
Johannes Berg683b6d32012-11-08 21:25:48 +01007234 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007235 return -EINVAL;
7236
Johannes Berg4c476992010-10-04 21:36:35 +02007237 if (!rdev->ops->mgmt_tx)
7238 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007239
Johannes Berg71bbc992012-06-15 15:30:18 +02007240 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007241 case NL80211_IFTYPE_P2P_DEVICE:
7242 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7243 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007244 case NL80211_IFTYPE_STATION:
7245 case NL80211_IFTYPE_ADHOC:
7246 case NL80211_IFTYPE_P2P_CLIENT:
7247 case NL80211_IFTYPE_AP:
7248 case NL80211_IFTYPE_AP_VLAN:
7249 case NL80211_IFTYPE_MESH_POINT:
7250 case NL80211_IFTYPE_P2P_GO:
7251 break;
7252 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007253 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007254 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007255
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007256 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007257 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007258 return -EINVAL;
7259 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007260
7261 /*
7262 * We should wait on the channel for at least a minimum amount
7263 * of time (10ms) but no longer than the driver supports.
7264 */
7265 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7266 wait > rdev->wiphy.max_remain_on_channel_duration)
7267 return -EINVAL;
7268
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007269 }
7270
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007271 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7272
Johannes Berg7c4ef712011-11-18 15:33:48 +01007273 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7274 return -EINVAL;
7275
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307276 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7277
Antonio Quartulliea141b752013-06-11 14:20:03 +02007278 /* get the channel if any has been specified, otherwise pass NULL to
7279 * the driver. The latter will use the current one
7280 */
7281 chandef.chan = NULL;
7282 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7283 err = nl80211_parse_chandef(rdev, info, &chandef);
7284 if (err)
7285 return err;
7286 }
7287
7288 if (!chandef.chan && offchan)
7289 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007290
Johannes Berge247bd902011-11-04 11:18:21 +01007291 if (!dont_wait_for_ack) {
7292 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7293 if (!msg)
7294 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007295
Eric W. Biederman15e47302012-09-07 20:12:54 +00007296 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007297 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007298
Johannes Berge247bd902011-11-04 11:18:21 +01007299 if (IS_ERR(hdr)) {
7300 err = PTR_ERR(hdr);
7301 goto free_msg;
7302 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007303 }
Johannes Berge247bd902011-11-04 11:18:21 +01007304
Johannes Berg683b6d32012-11-08 21:25:48 +01007305 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f782010-08-12 15:38:38 +02007306 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7307 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007308 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007309 if (err)
7310 goto free_msg;
7311
Johannes Berge247bd902011-11-04 11:18:21 +01007312 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007313 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7314 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007315
Johannes Berge247bd902011-11-04 11:18:21 +01007316 genlmsg_end(msg, hdr);
7317 return genlmsg_reply(msg, info);
7318 }
7319
7320 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007321
7322 nla_put_failure:
7323 err = -ENOBUFS;
7324 free_msg:
7325 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007326 return err;
7327}
7328
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007329static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7330{
7331 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007332 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007333 u64 cookie;
7334
7335 if (!info->attrs[NL80211_ATTR_COOKIE])
7336 return -EINVAL;
7337
7338 if (!rdev->ops->mgmt_tx_cancel_wait)
7339 return -EOPNOTSUPP;
7340
Johannes Berg71bbc992012-06-15 15:30:18 +02007341 switch (wdev->iftype) {
7342 case NL80211_IFTYPE_STATION:
7343 case NL80211_IFTYPE_ADHOC:
7344 case NL80211_IFTYPE_P2P_CLIENT:
7345 case NL80211_IFTYPE_AP:
7346 case NL80211_IFTYPE_AP_VLAN:
7347 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007348 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007349 break;
7350 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007351 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007352 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007353
7354 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7355
Hila Gonene35e4d22012-06-27 17:19:42 +03007356 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007357}
7358
Kalle Valoffb9eb32010-02-17 17:58:10 +02007359static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7360{
Johannes Berg4c476992010-10-04 21:36:35 +02007361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007362 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007363 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007364 u8 ps_state;
7365 bool state;
7366 int err;
7367
Johannes Berg4c476992010-10-04 21:36:35 +02007368 if (!info->attrs[NL80211_ATTR_PS_STATE])
7369 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007370
7371 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7372
Johannes Berg4c476992010-10-04 21:36:35 +02007373 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7374 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007375
7376 wdev = dev->ieee80211_ptr;
7377
Johannes Berg4c476992010-10-04 21:36:35 +02007378 if (!rdev->ops->set_power_mgmt)
7379 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007380
7381 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7382
7383 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007384 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007385
Hila Gonene35e4d22012-06-27 17:19:42 +03007386 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007387 if (!err)
7388 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007389 return err;
7390}
7391
7392static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7393{
Johannes Berg4c476992010-10-04 21:36:35 +02007394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007395 enum nl80211_ps_state ps_state;
7396 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007397 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007398 struct sk_buff *msg;
7399 void *hdr;
7400 int err;
7401
Kalle Valoffb9eb32010-02-17 17:58:10 +02007402 wdev = dev->ieee80211_ptr;
7403
Johannes Berg4c476992010-10-04 21:36:35 +02007404 if (!rdev->ops->set_power_mgmt)
7405 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007406
7407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007408 if (!msg)
7409 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007410
Eric W. Biederman15e47302012-09-07 20:12:54 +00007411 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007412 NL80211_CMD_GET_POWER_SAVE);
7413 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007414 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007415 goto free_msg;
7416 }
7417
7418 if (wdev->ps)
7419 ps_state = NL80211_PS_ENABLED;
7420 else
7421 ps_state = NL80211_PS_DISABLED;
7422
David S. Miller9360ffd2012-03-29 04:41:26 -04007423 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7424 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007425
7426 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007427 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007428
Johannes Berg4c476992010-10-04 21:36:35 +02007429 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007430 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007431 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007432 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007433 return err;
7434}
7435
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007436static struct nla_policy
7437nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7438 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7439 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7440 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007441 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7442 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7443 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007444};
7445
Thomas Pedersen84f10702012-07-12 16:17:33 -07007446static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007447 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007448{
7449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7450 struct wireless_dev *wdev;
7451 struct net_device *dev = info->user_ptr[1];
7452
Johannes Bergd9d8b012012-11-26 12:51:52 +01007453 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007454 return -EINVAL;
7455
7456 wdev = dev->ieee80211_ptr;
7457
7458 if (!rdev->ops->set_cqm_txe_config)
7459 return -EOPNOTSUPP;
7460
7461 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7462 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7463 return -EOPNOTSUPP;
7464
Hila Gonene35e4d22012-06-27 17:19:42 +03007465 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007466}
7467
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007468static int nl80211_set_cqm_rssi(struct genl_info *info,
7469 s32 threshold, u32 hysteresis)
7470{
Johannes Berg4c476992010-10-04 21:36:35 +02007471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007472 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007473 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007474
7475 if (threshold > 0)
7476 return -EINVAL;
7477
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007478 wdev = dev->ieee80211_ptr;
7479
Johannes Berg4c476992010-10-04 21:36:35 +02007480 if (!rdev->ops->set_cqm_rssi_config)
7481 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007482
Johannes Berg074ac8d2010-09-16 14:58:22 +02007483 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007484 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7485 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007486
Hila Gonene35e4d22012-06-27 17:19:42 +03007487 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007488}
7489
7490static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7491{
7492 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7493 struct nlattr *cqm;
7494 int err;
7495
7496 cqm = info->attrs[NL80211_ATTR_CQM];
7497 if (!cqm) {
7498 err = -EINVAL;
7499 goto out;
7500 }
7501
7502 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7503 nl80211_attr_cqm_policy);
7504 if (err)
7505 goto out;
7506
7507 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7508 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7509 s32 threshold;
7510 u32 hysteresis;
7511 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7512 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7513 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007514 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7515 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7516 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7517 u32 rate, pkts, intvl;
7518 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7519 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7520 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7521 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007522 } else
7523 err = -EINVAL;
7524
7525out:
7526 return err;
7527}
7528
Johannes Berg29cbe682010-12-03 09:20:44 +01007529static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7530{
7531 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7532 struct net_device *dev = info->user_ptr[1];
7533 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007534 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007535 int err;
7536
7537 /* start with default */
7538 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007539 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007540
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007541 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007542 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007543 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007544 if (err)
7545 return err;
7546 }
7547
7548 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7549 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7550 return -EINVAL;
7551
Javier Cardonac80d5452010-12-16 17:37:49 -08007552 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7553 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7554
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007555 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7556 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7557 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7558 return -EINVAL;
7559
Marco Porsch9bdbf042013-01-07 16:04:51 +01007560 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7561 setup.beacon_interval =
7562 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7563 if (setup.beacon_interval < 10 ||
7564 setup.beacon_interval > 10000)
7565 return -EINVAL;
7566 }
7567
7568 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7569 setup.dtim_period =
7570 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7571 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7572 return -EINVAL;
7573 }
7574
Javier Cardonac80d5452010-12-16 17:37:49 -08007575 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7576 /* parse additional setup parameters if given */
7577 err = nl80211_parse_mesh_setup(info, &setup);
7578 if (err)
7579 return err;
7580 }
7581
Thomas Pedersend37bb182013-03-04 13:06:13 -08007582 if (setup.user_mpm)
7583 cfg.auto_open_plinks = false;
7584
Johannes Bergcc1d2802012-05-16 23:50:20 +02007585 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007586 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7587 if (err)
7588 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007589 } else {
7590 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007591 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007592 }
7593
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007594 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7595 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7596 int n_rates =
7597 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7598 struct ieee80211_supported_band *sband;
7599
7600 if (!setup.chandef.chan)
7601 return -EINVAL;
7602
7603 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7604
7605 err = ieee80211_get_ratemask(sband, rates, n_rates,
7606 &setup.basic_rates);
7607 if (err)
7608 return err;
7609 }
7610
Javier Cardonac80d5452010-12-16 17:37:49 -08007611 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007612}
7613
7614static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7615{
7616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7617 struct net_device *dev = info->user_ptr[1];
7618
7619 return cfg80211_leave_mesh(rdev, dev);
7620}
7621
Johannes Bergdfb89c52012-06-27 09:23:48 +02007622#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007623static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7624 struct cfg80211_registered_device *rdev)
7625{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007626 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007627 struct nlattr *nl_pats, *nl_pat;
7628 int i, pat_len;
7629
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007630 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007631 return 0;
7632
7633 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7634 if (!nl_pats)
7635 return -ENOBUFS;
7636
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007637 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007638 nl_pat = nla_nest_start(msg, i + 1);
7639 if (!nl_pat)
7640 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007641 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007642 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007643 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007644 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7645 wowlan->patterns[i].pattern) ||
7646 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007647 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007648 return -ENOBUFS;
7649 nla_nest_end(msg, nl_pat);
7650 }
7651 nla_nest_end(msg, nl_pats);
7652
7653 return 0;
7654}
7655
Johannes Berg2a0e0472013-01-23 22:57:40 +01007656static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7657 struct cfg80211_wowlan_tcp *tcp)
7658{
7659 struct nlattr *nl_tcp;
7660
7661 if (!tcp)
7662 return 0;
7663
7664 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7665 if (!nl_tcp)
7666 return -ENOBUFS;
7667
7668 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7669 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7670 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7671 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7672 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7673 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7674 tcp->payload_len, tcp->payload) ||
7675 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7676 tcp->data_interval) ||
7677 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7678 tcp->wake_len, tcp->wake_data) ||
7679 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7680 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7681 return -ENOBUFS;
7682
7683 if (tcp->payload_seq.len &&
7684 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7685 sizeof(tcp->payload_seq), &tcp->payload_seq))
7686 return -ENOBUFS;
7687
7688 if (tcp->payload_tok.len &&
7689 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7690 sizeof(tcp->payload_tok) + tcp->tokens_size,
7691 &tcp->payload_tok))
7692 return -ENOBUFS;
7693
Johannes Berge248ad32013-05-16 10:24:28 +02007694 nla_nest_end(msg, nl_tcp);
7695
Johannes Berg2a0e0472013-01-23 22:57:40 +01007696 return 0;
7697}
7698
Johannes Bergff1b6e62011-05-04 15:37:28 +02007699static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7700{
7701 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7702 struct sk_buff *msg;
7703 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007704 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007705
Johannes Berg964dc9e2013-06-03 17:25:34 +02007706 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007707 return -EOPNOTSUPP;
7708
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007709 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007710 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007711 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7712 rdev->wiphy.wowlan_config->tcp->payload_len +
7713 rdev->wiphy.wowlan_config->tcp->wake_len +
7714 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007715 }
7716
7717 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007718 if (!msg)
7719 return -ENOMEM;
7720
Eric W. Biederman15e47302012-09-07 20:12:54 +00007721 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007722 NL80211_CMD_GET_WOWLAN);
7723 if (!hdr)
7724 goto nla_put_failure;
7725
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007726 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007727 struct nlattr *nl_wowlan;
7728
7729 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7730 if (!nl_wowlan)
7731 goto nla_put_failure;
7732
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007733 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007734 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007735 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007736 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007737 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007738 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007739 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007740 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007741 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007742 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007743 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007744 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007745 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007746 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7747 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007748
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007749 if (nl80211_send_wowlan_patterns(msg, rdev))
7750 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007751
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007752 if (nl80211_send_wowlan_tcp(msg,
7753 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007754 goto nla_put_failure;
7755
Johannes Bergff1b6e62011-05-04 15:37:28 +02007756 nla_nest_end(msg, nl_wowlan);
7757 }
7758
7759 genlmsg_end(msg, hdr);
7760 return genlmsg_reply(msg, info);
7761
7762nla_put_failure:
7763 nlmsg_free(msg);
7764 return -ENOBUFS;
7765}
7766
Johannes Berg2a0e0472013-01-23 22:57:40 +01007767static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7768 struct nlattr *attr,
7769 struct cfg80211_wowlan *trig)
7770{
7771 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7772 struct cfg80211_wowlan_tcp *cfg;
7773 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7774 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7775 u32 size;
7776 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7777 int err, port;
7778
Johannes Berg964dc9e2013-06-03 17:25:34 +02007779 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007780 return -EINVAL;
7781
7782 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7783 nla_data(attr), nla_len(attr),
7784 nl80211_wowlan_tcp_policy);
7785 if (err)
7786 return err;
7787
7788 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7789 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7790 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7791 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7792 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7793 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7794 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7795 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7796 return -EINVAL;
7797
7798 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007799 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007800 return -EINVAL;
7801
7802 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007803 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007804 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007805 return -EINVAL;
7806
7807 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007808 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007809 return -EINVAL;
7810
7811 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7812 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7813 return -EINVAL;
7814
7815 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7816 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7817
7818 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7819 tokens_size = tokln - sizeof(*tok);
7820
7821 if (!tok->len || tokens_size % tok->len)
7822 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007823 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007824 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007825 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007826 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007827 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007828 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007829 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007830 return -EINVAL;
7831 if (tok->offset + tok->len > data_size)
7832 return -EINVAL;
7833 }
7834
7835 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7836 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007837 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007838 return -EINVAL;
7839 if (seq->len == 0 || seq->len > 4)
7840 return -EINVAL;
7841 if (seq->len + seq->offset > data_size)
7842 return -EINVAL;
7843 }
7844
7845 size = sizeof(*cfg);
7846 size += data_size;
7847 size += wake_size + wake_mask_size;
7848 size += tokens_size;
7849
7850 cfg = kzalloc(size, GFP_KERNEL);
7851 if (!cfg)
7852 return -ENOMEM;
7853 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7854 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7855 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7856 ETH_ALEN);
7857 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7858 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7859 else
7860 port = 0;
7861#ifdef CONFIG_INET
7862 /* allocate a socket and port for it and use it */
7863 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7864 IPPROTO_TCP, &cfg->sock, 1);
7865 if (err) {
7866 kfree(cfg);
7867 return err;
7868 }
7869 if (inet_csk_get_port(cfg->sock->sk, port)) {
7870 sock_release(cfg->sock);
7871 kfree(cfg);
7872 return -EADDRINUSE;
7873 }
7874 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7875#else
7876 if (!port) {
7877 kfree(cfg);
7878 return -EINVAL;
7879 }
7880 cfg->src_port = port;
7881#endif
7882
7883 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7884 cfg->payload_len = data_size;
7885 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7886 memcpy((void *)cfg->payload,
7887 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7888 data_size);
7889 if (seq)
7890 cfg->payload_seq = *seq;
7891 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7892 cfg->wake_len = wake_size;
7893 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7894 memcpy((void *)cfg->wake_data,
7895 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7896 wake_size);
7897 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7898 data_size + wake_size;
7899 memcpy((void *)cfg->wake_mask,
7900 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7901 wake_mask_size);
7902 if (tok) {
7903 cfg->tokens_size = tokens_size;
7904 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7905 }
7906
7907 trig->tcp = cfg;
7908
7909 return 0;
7910}
7911
Johannes Bergff1b6e62011-05-04 15:37:28 +02007912static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7913{
7914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7915 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007916 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007917 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007918 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007919 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007920 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007921
Johannes Berg964dc9e2013-06-03 17:25:34 +02007922 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007923 return -EOPNOTSUPP;
7924
Johannes Bergae33bd82012-07-12 16:25:02 +02007925 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7926 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007927 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007928 goto set_wakeup;
7929 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007930
7931 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7932 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7933 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7934 nl80211_wowlan_policy);
7935 if (err)
7936 return err;
7937
7938 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7939 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7940 return -EINVAL;
7941 new_triggers.any = true;
7942 }
7943
7944 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7945 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7946 return -EINVAL;
7947 new_triggers.disconnect = true;
7948 }
7949
7950 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7951 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7952 return -EINVAL;
7953 new_triggers.magic_pkt = true;
7954 }
7955
Johannes Berg77dbbb12011-07-13 10:48:55 +02007956 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7957 return -EINVAL;
7958
7959 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7960 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7961 return -EINVAL;
7962 new_triggers.gtk_rekey_failure = true;
7963 }
7964
7965 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7966 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7967 return -EINVAL;
7968 new_triggers.eap_identity_req = true;
7969 }
7970
7971 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7972 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7973 return -EINVAL;
7974 new_triggers.four_way_handshake = true;
7975 }
7976
7977 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7978 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7979 return -EINVAL;
7980 new_triggers.rfkill_release = true;
7981 }
7982
Johannes Bergff1b6e62011-05-04 15:37:28 +02007983 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7984 struct nlattr *pat;
7985 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007986 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007987 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007988
7989 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7990 rem)
7991 n_patterns++;
7992 if (n_patterns > wowlan->n_patterns)
7993 return -EINVAL;
7994
7995 new_triggers.patterns = kcalloc(n_patterns,
7996 sizeof(new_triggers.patterns[0]),
7997 GFP_KERNEL);
7998 if (!new_triggers.patterns)
7999 return -ENOMEM;
8000
8001 new_triggers.n_patterns = n_patterns;
8002 i = 0;
8003
8004 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8005 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008006 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8007 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008008 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008009 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8010 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008011 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008012 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008013 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008014 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008015 goto error;
8016 if (pat_len > wowlan->pattern_max_len ||
8017 pat_len < wowlan->pattern_min_len)
8018 goto error;
8019
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008020 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008021 pkt_offset = 0;
8022 else
8023 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008024 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008025 if (pkt_offset > wowlan->max_pkt_offset)
8026 goto error;
8027 new_triggers.patterns[i].pkt_offset = pkt_offset;
8028
Johannes Bergff1b6e62011-05-04 15:37:28 +02008029 new_triggers.patterns[i].mask =
8030 kmalloc(mask_len + pat_len, GFP_KERNEL);
8031 if (!new_triggers.patterns[i].mask) {
8032 err = -ENOMEM;
8033 goto error;
8034 }
8035 new_triggers.patterns[i].pattern =
8036 new_triggers.patterns[i].mask + mask_len;
8037 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008038 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008039 mask_len);
8040 new_triggers.patterns[i].pattern_len = pat_len;
8041 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008042 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008043 pat_len);
8044 i++;
8045 }
8046 }
8047
Johannes Berg2a0e0472013-01-23 22:57:40 +01008048 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8049 err = nl80211_parse_wowlan_tcp(
8050 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8051 &new_triggers);
8052 if (err)
8053 goto error;
8054 }
8055
Johannes Bergae33bd82012-07-12 16:25:02 +02008056 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8057 if (!ntrig) {
8058 err = -ENOMEM;
8059 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008060 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008061 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008062 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008063
Johannes Bergae33bd82012-07-12 16:25:02 +02008064 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008065 if (rdev->ops->set_wakeup &&
8066 prev_enabled != !!rdev->wiphy.wowlan_config)
8067 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008068
Johannes Bergff1b6e62011-05-04 15:37:28 +02008069 return 0;
8070 error:
8071 for (i = 0; i < new_triggers.n_patterns; i++)
8072 kfree(new_triggers.patterns[i].mask);
8073 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008074 if (new_triggers.tcp && new_triggers.tcp->sock)
8075 sock_release(new_triggers.tcp->sock);
8076 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008077 return err;
8078}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008079#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008080
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008081static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8082 struct cfg80211_registered_device *rdev)
8083{
8084 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8085 int i, j, pat_len;
8086 struct cfg80211_coalesce_rules *rule;
8087
8088 if (!rdev->coalesce->n_rules)
8089 return 0;
8090
8091 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8092 if (!nl_rules)
8093 return -ENOBUFS;
8094
8095 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8096 nl_rule = nla_nest_start(msg, i + 1);
8097 if (!nl_rule)
8098 return -ENOBUFS;
8099
8100 rule = &rdev->coalesce->rules[i];
8101 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8102 rule->delay))
8103 return -ENOBUFS;
8104
8105 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8106 rule->condition))
8107 return -ENOBUFS;
8108
8109 nl_pats = nla_nest_start(msg,
8110 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8111 if (!nl_pats)
8112 return -ENOBUFS;
8113
8114 for (j = 0; j < rule->n_patterns; j++) {
8115 nl_pat = nla_nest_start(msg, j + 1);
8116 if (!nl_pat)
8117 return -ENOBUFS;
8118 pat_len = rule->patterns[j].pattern_len;
8119 if (nla_put(msg, NL80211_PKTPAT_MASK,
8120 DIV_ROUND_UP(pat_len, 8),
8121 rule->patterns[j].mask) ||
8122 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8123 rule->patterns[j].pattern) ||
8124 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8125 rule->patterns[j].pkt_offset))
8126 return -ENOBUFS;
8127 nla_nest_end(msg, nl_pat);
8128 }
8129 nla_nest_end(msg, nl_pats);
8130 nla_nest_end(msg, nl_rule);
8131 }
8132 nla_nest_end(msg, nl_rules);
8133
8134 return 0;
8135}
8136
8137static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8138{
8139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8140 struct sk_buff *msg;
8141 void *hdr;
8142
8143 if (!rdev->wiphy.coalesce)
8144 return -EOPNOTSUPP;
8145
8146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8147 if (!msg)
8148 return -ENOMEM;
8149
8150 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8151 NL80211_CMD_GET_COALESCE);
8152 if (!hdr)
8153 goto nla_put_failure;
8154
8155 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8156 goto nla_put_failure;
8157
8158 genlmsg_end(msg, hdr);
8159 return genlmsg_reply(msg, info);
8160
8161nla_put_failure:
8162 nlmsg_free(msg);
8163 return -ENOBUFS;
8164}
8165
8166void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8167{
8168 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8169 int i, j;
8170 struct cfg80211_coalesce_rules *rule;
8171
8172 if (!coalesce)
8173 return;
8174
8175 for (i = 0; i < coalesce->n_rules; i++) {
8176 rule = &coalesce->rules[i];
8177 for (j = 0; j < rule->n_patterns; j++)
8178 kfree(rule->patterns[j].mask);
8179 kfree(rule->patterns);
8180 }
8181 kfree(coalesce->rules);
8182 kfree(coalesce);
8183 rdev->coalesce = NULL;
8184}
8185
8186static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8187 struct nlattr *rule,
8188 struct cfg80211_coalesce_rules *new_rule)
8189{
8190 int err, i;
8191 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8192 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8193 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8194 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8195
8196 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8197 nla_len(rule), nl80211_coalesce_policy);
8198 if (err)
8199 return err;
8200
8201 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8202 new_rule->delay =
8203 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8204 if (new_rule->delay > coalesce->max_delay)
8205 return -EINVAL;
8206
8207 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8208 new_rule->condition =
8209 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8210 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8211 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8212 return -EINVAL;
8213
8214 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8215 return -EINVAL;
8216
8217 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8218 rem)
8219 n_patterns++;
8220 if (n_patterns > coalesce->n_patterns)
8221 return -EINVAL;
8222
8223 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8224 GFP_KERNEL);
8225 if (!new_rule->patterns)
8226 return -ENOMEM;
8227
8228 new_rule->n_patterns = n_patterns;
8229 i = 0;
8230
8231 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8232 rem) {
8233 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8234 nla_len(pat), NULL);
8235 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8236 !pat_tb[NL80211_PKTPAT_PATTERN])
8237 return -EINVAL;
8238 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8239 mask_len = DIV_ROUND_UP(pat_len, 8);
8240 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8241 return -EINVAL;
8242 if (pat_len > coalesce->pattern_max_len ||
8243 pat_len < coalesce->pattern_min_len)
8244 return -EINVAL;
8245
8246 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8247 pkt_offset = 0;
8248 else
8249 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8250 if (pkt_offset > coalesce->max_pkt_offset)
8251 return -EINVAL;
8252 new_rule->patterns[i].pkt_offset = pkt_offset;
8253
8254 new_rule->patterns[i].mask =
8255 kmalloc(mask_len + pat_len, GFP_KERNEL);
8256 if (!new_rule->patterns[i].mask)
8257 return -ENOMEM;
8258 new_rule->patterns[i].pattern =
8259 new_rule->patterns[i].mask + mask_len;
8260 memcpy(new_rule->patterns[i].mask,
8261 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8262 new_rule->patterns[i].pattern_len = pat_len;
8263 memcpy(new_rule->patterns[i].pattern,
8264 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8265 i++;
8266 }
8267
8268 return 0;
8269}
8270
8271static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8272{
8273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8274 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8275 struct cfg80211_coalesce new_coalesce = {};
8276 struct cfg80211_coalesce *n_coalesce;
8277 int err, rem_rule, n_rules = 0, i, j;
8278 struct nlattr *rule;
8279 struct cfg80211_coalesce_rules *tmp_rule;
8280
8281 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8282 return -EOPNOTSUPP;
8283
8284 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8285 cfg80211_rdev_free_coalesce(rdev);
8286 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8287 return 0;
8288 }
8289
8290 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8291 rem_rule)
8292 n_rules++;
8293 if (n_rules > coalesce->n_rules)
8294 return -EINVAL;
8295
8296 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8297 GFP_KERNEL);
8298 if (!new_coalesce.rules)
8299 return -ENOMEM;
8300
8301 new_coalesce.n_rules = n_rules;
8302 i = 0;
8303
8304 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8305 rem_rule) {
8306 err = nl80211_parse_coalesce_rule(rdev, rule,
8307 &new_coalesce.rules[i]);
8308 if (err)
8309 goto error;
8310
8311 i++;
8312 }
8313
8314 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8315 if (err)
8316 goto error;
8317
8318 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8319 if (!n_coalesce) {
8320 err = -ENOMEM;
8321 goto error;
8322 }
8323 cfg80211_rdev_free_coalesce(rdev);
8324 rdev->coalesce = n_coalesce;
8325
8326 return 0;
8327error:
8328 for (i = 0; i < new_coalesce.n_rules; i++) {
8329 tmp_rule = &new_coalesce.rules[i];
8330 for (j = 0; j < tmp_rule->n_patterns; j++)
8331 kfree(tmp_rule->patterns[j].mask);
8332 kfree(tmp_rule->patterns);
8333 }
8334 kfree(new_coalesce.rules);
8335
8336 return err;
8337}
8338
Johannes Berge5497d72011-07-05 16:35:40 +02008339static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8340{
8341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8342 struct net_device *dev = info->user_ptr[1];
8343 struct wireless_dev *wdev = dev->ieee80211_ptr;
8344 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8345 struct cfg80211_gtk_rekey_data rekey_data;
8346 int err;
8347
8348 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8349 return -EINVAL;
8350
8351 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8352 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8353 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8354 nl80211_rekey_policy);
8355 if (err)
8356 return err;
8357
8358 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8359 return -ERANGE;
8360 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8361 return -ERANGE;
8362 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8363 return -ERANGE;
8364
8365 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8366 NL80211_KEK_LEN);
8367 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8368 NL80211_KCK_LEN);
8369 memcpy(rekey_data.replay_ctr,
8370 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8371 NL80211_REPLAY_CTR_LEN);
8372
8373 wdev_lock(wdev);
8374 if (!wdev->current_bss) {
8375 err = -ENOTCONN;
8376 goto out;
8377 }
8378
8379 if (!rdev->ops->set_rekey_data) {
8380 err = -EOPNOTSUPP;
8381 goto out;
8382 }
8383
Hila Gonene35e4d22012-06-27 17:19:42 +03008384 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008385 out:
8386 wdev_unlock(wdev);
8387 return err;
8388}
8389
Johannes Berg28946da2011-11-04 11:18:12 +01008390static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8391 struct genl_info *info)
8392{
8393 struct net_device *dev = info->user_ptr[1];
8394 struct wireless_dev *wdev = dev->ieee80211_ptr;
8395
8396 if (wdev->iftype != NL80211_IFTYPE_AP &&
8397 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8398 return -EINVAL;
8399
Eric W. Biederman15e47302012-09-07 20:12:54 +00008400 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008401 return -EBUSY;
8402
Eric W. Biederman15e47302012-09-07 20:12:54 +00008403 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008404 return 0;
8405}
8406
Johannes Berg7f6cf312011-11-04 11:18:15 +01008407static int nl80211_probe_client(struct sk_buff *skb,
8408 struct genl_info *info)
8409{
8410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8411 struct net_device *dev = info->user_ptr[1];
8412 struct wireless_dev *wdev = dev->ieee80211_ptr;
8413 struct sk_buff *msg;
8414 void *hdr;
8415 const u8 *addr;
8416 u64 cookie;
8417 int err;
8418
8419 if (wdev->iftype != NL80211_IFTYPE_AP &&
8420 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8421 return -EOPNOTSUPP;
8422
8423 if (!info->attrs[NL80211_ATTR_MAC])
8424 return -EINVAL;
8425
8426 if (!rdev->ops->probe_client)
8427 return -EOPNOTSUPP;
8428
8429 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8430 if (!msg)
8431 return -ENOMEM;
8432
Eric W. Biederman15e47302012-09-07 20:12:54 +00008433 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008434 NL80211_CMD_PROBE_CLIENT);
8435
8436 if (IS_ERR(hdr)) {
8437 err = PTR_ERR(hdr);
8438 goto free_msg;
8439 }
8440
8441 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8442
Hila Gonene35e4d22012-06-27 17:19:42 +03008443 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008444 if (err)
8445 goto free_msg;
8446
David S. Miller9360ffd2012-03-29 04:41:26 -04008447 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8448 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008449
8450 genlmsg_end(msg, hdr);
8451
8452 return genlmsg_reply(msg, info);
8453
8454 nla_put_failure:
8455 err = -ENOBUFS;
8456 free_msg:
8457 nlmsg_free(msg);
8458 return err;
8459}
8460
Johannes Berg5e760232011-11-04 11:18:17 +01008461static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8462{
8463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008464 struct cfg80211_beacon_registration *reg, *nreg;
8465 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008466
8467 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8468 return -EOPNOTSUPP;
8469
Ben Greear37c73b52012-10-26 14:49:25 -07008470 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8471 if (!nreg)
8472 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008473
Ben Greear37c73b52012-10-26 14:49:25 -07008474 /* First, check if already registered. */
8475 spin_lock_bh(&rdev->beacon_registrations_lock);
8476 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8477 if (reg->nlportid == info->snd_portid) {
8478 rv = -EALREADY;
8479 goto out_err;
8480 }
8481 }
8482 /* Add it to the list */
8483 nreg->nlportid = info->snd_portid;
8484 list_add(&nreg->list, &rdev->beacon_registrations);
8485
8486 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008487
8488 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008489out_err:
8490 spin_unlock_bh(&rdev->beacon_registrations_lock);
8491 kfree(nreg);
8492 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008493}
8494
Johannes Berg98104fde2012-06-16 00:19:54 +02008495static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8496{
8497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8498 struct wireless_dev *wdev = info->user_ptr[1];
8499 int err;
8500
8501 if (!rdev->ops->start_p2p_device)
8502 return -EOPNOTSUPP;
8503
8504 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8505 return -EOPNOTSUPP;
8506
8507 if (wdev->p2p_started)
8508 return 0;
8509
Johannes Berg98104fde2012-06-16 00:19:54 +02008510 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008511 if (err)
8512 return err;
8513
Johannes Bergeeb126e2012-10-23 15:16:50 +02008514 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008515 if (err)
8516 return err;
8517
8518 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008519 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008520
8521 return 0;
8522}
8523
8524static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8525{
8526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8527 struct wireless_dev *wdev = info->user_ptr[1];
8528
8529 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8530 return -EOPNOTSUPP;
8531
8532 if (!rdev->ops->stop_p2p_device)
8533 return -EOPNOTSUPP;
8534
Johannes Bergf9f47522013-03-19 15:04:07 +01008535 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008536
8537 return 0;
8538}
8539
Johannes Berg3713b4e2013-02-14 16:19:38 +01008540static int nl80211_get_protocol_features(struct sk_buff *skb,
8541 struct genl_info *info)
8542{
8543 void *hdr;
8544 struct sk_buff *msg;
8545
8546 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8547 if (!msg)
8548 return -ENOMEM;
8549
8550 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8551 NL80211_CMD_GET_PROTOCOL_FEATURES);
8552 if (!hdr)
8553 goto nla_put_failure;
8554
8555 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8556 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8557 goto nla_put_failure;
8558
8559 genlmsg_end(msg, hdr);
8560 return genlmsg_reply(msg, info);
8561
8562 nla_put_failure:
8563 kfree_skb(msg);
8564 return -ENOBUFS;
8565}
8566
Jouni Malinen355199e2013-02-27 17:14:27 +02008567static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8568{
8569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8570 struct cfg80211_update_ft_ies_params ft_params;
8571 struct net_device *dev = info->user_ptr[1];
8572
8573 if (!rdev->ops->update_ft_ies)
8574 return -EOPNOTSUPP;
8575
8576 if (!info->attrs[NL80211_ATTR_MDID] ||
8577 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8578 return -EINVAL;
8579
8580 memset(&ft_params, 0, sizeof(ft_params));
8581 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8582 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8583 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8584
8585 return rdev_update_ft_ies(rdev, dev, &ft_params);
8586}
8587
Arend van Spriel5de17982013-04-18 15:49:00 +02008588static int nl80211_crit_protocol_start(struct sk_buff *skb,
8589 struct genl_info *info)
8590{
8591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8592 struct wireless_dev *wdev = info->user_ptr[1];
8593 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8594 u16 duration;
8595 int ret;
8596
8597 if (!rdev->ops->crit_proto_start)
8598 return -EOPNOTSUPP;
8599
8600 if (WARN_ON(!rdev->ops->crit_proto_stop))
8601 return -EINVAL;
8602
8603 if (rdev->crit_proto_nlportid)
8604 return -EBUSY;
8605
8606 /* determine protocol if provided */
8607 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8608 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8609
8610 if (proto >= NUM_NL80211_CRIT_PROTO)
8611 return -EINVAL;
8612
8613 /* timeout must be provided */
8614 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8615 return -EINVAL;
8616
8617 duration =
8618 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8619
8620 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8621 return -ERANGE;
8622
8623 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8624 if (!ret)
8625 rdev->crit_proto_nlportid = info->snd_portid;
8626
8627 return ret;
8628}
8629
8630static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8631 struct genl_info *info)
8632{
8633 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8634 struct wireless_dev *wdev = info->user_ptr[1];
8635
8636 if (!rdev->ops->crit_proto_stop)
8637 return -EOPNOTSUPP;
8638
8639 if (rdev->crit_proto_nlportid) {
8640 rdev->crit_proto_nlportid = 0;
8641 rdev_crit_proto_stop(rdev, wdev);
8642 }
8643 return 0;
8644}
8645
Johannes Berg4c476992010-10-04 21:36:35 +02008646#define NL80211_FLAG_NEED_WIPHY 0x01
8647#define NL80211_FLAG_NEED_NETDEV 0x02
8648#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008649#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8650#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8651 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008652#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008653/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008654#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8655 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008656
8657static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8658 struct genl_info *info)
8659{
8660 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008661 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008662 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008663 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8664
8665 if (rtnl)
8666 rtnl_lock();
8667
8668 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008669 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008670 if (IS_ERR(rdev)) {
8671 if (rtnl)
8672 rtnl_unlock();
8673 return PTR_ERR(rdev);
8674 }
8675 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008676 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8677 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008678 ASSERT_RTNL();
8679
Johannes Berg89a54e42012-06-15 14:33:17 +02008680 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8681 info->attrs);
8682 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008683 if (rtnl)
8684 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008685 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008686 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008687
Johannes Berg89a54e42012-06-15 14:33:17 +02008688 dev = wdev->netdev;
8689 rdev = wiphy_to_dev(wdev->wiphy);
8690
Johannes Berg1bf614e2012-06-15 15:23:36 +02008691 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8692 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008693 if (rtnl)
8694 rtnl_unlock();
8695 return -EINVAL;
8696 }
8697
8698 info->user_ptr[1] = dev;
8699 } else {
8700 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008701 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008702
Johannes Berg1bf614e2012-06-15 15:23:36 +02008703 if (dev) {
8704 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8705 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008706 if (rtnl)
8707 rtnl_unlock();
8708 return -ENETDOWN;
8709 }
8710
8711 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008712 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8713 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008714 if (rtnl)
8715 rtnl_unlock();
8716 return -ENETDOWN;
8717 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008718 }
8719
Johannes Berg4c476992010-10-04 21:36:35 +02008720 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008721 }
8722
8723 return 0;
8724}
8725
8726static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8727 struct genl_info *info)
8728{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008729 if (info->user_ptr[1]) {
8730 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8731 struct wireless_dev *wdev = info->user_ptr[1];
8732
8733 if (wdev->netdev)
8734 dev_put(wdev->netdev);
8735 } else {
8736 dev_put(info->user_ptr[1]);
8737 }
8738 }
Johannes Berg4c476992010-10-04 21:36:35 +02008739 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8740 rtnl_unlock();
8741}
8742
Johannes Berg55682962007-09-20 13:09:35 -04008743static struct genl_ops nl80211_ops[] = {
8744 {
8745 .cmd = NL80211_CMD_GET_WIPHY,
8746 .doit = nl80211_get_wiphy,
8747 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008748 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008749 .policy = nl80211_policy,
8750 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008751 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8752 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008753 },
8754 {
8755 .cmd = NL80211_CMD_SET_WIPHY,
8756 .doit = nl80211_set_wiphy,
8757 .policy = nl80211_policy,
8758 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008759 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008760 },
8761 {
8762 .cmd = NL80211_CMD_GET_INTERFACE,
8763 .doit = nl80211_get_interface,
8764 .dumpit = nl80211_dump_interface,
8765 .policy = nl80211_policy,
8766 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008767 .internal_flags = NL80211_FLAG_NEED_WDEV |
8768 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008769 },
8770 {
8771 .cmd = NL80211_CMD_SET_INTERFACE,
8772 .doit = nl80211_set_interface,
8773 .policy = nl80211_policy,
8774 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008775 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8776 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008777 },
8778 {
8779 .cmd = NL80211_CMD_NEW_INTERFACE,
8780 .doit = nl80211_new_interface,
8781 .policy = nl80211_policy,
8782 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008783 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8784 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008785 },
8786 {
8787 .cmd = NL80211_CMD_DEL_INTERFACE,
8788 .doit = nl80211_del_interface,
8789 .policy = nl80211_policy,
8790 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008791 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008792 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008793 },
Johannes Berg41ade002007-12-19 02:03:29 +01008794 {
8795 .cmd = NL80211_CMD_GET_KEY,
8796 .doit = nl80211_get_key,
8797 .policy = nl80211_policy,
8798 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008799 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008800 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008801 },
8802 {
8803 .cmd = NL80211_CMD_SET_KEY,
8804 .doit = nl80211_set_key,
8805 .policy = nl80211_policy,
8806 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008807 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008808 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008809 },
8810 {
8811 .cmd = NL80211_CMD_NEW_KEY,
8812 .doit = nl80211_new_key,
8813 .policy = nl80211_policy,
8814 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008815 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008816 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008817 },
8818 {
8819 .cmd = NL80211_CMD_DEL_KEY,
8820 .doit = nl80211_del_key,
8821 .policy = nl80211_policy,
8822 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008823 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008824 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008825 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008826 {
8827 .cmd = NL80211_CMD_SET_BEACON,
8828 .policy = nl80211_policy,
8829 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008830 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008831 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008832 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008833 },
8834 {
Johannes Berg88600202012-02-13 15:17:18 +01008835 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008836 .policy = nl80211_policy,
8837 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008838 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008839 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008840 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008841 },
8842 {
Johannes Berg88600202012-02-13 15:17:18 +01008843 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008844 .policy = nl80211_policy,
8845 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008846 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008847 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008848 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008849 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008850 {
8851 .cmd = NL80211_CMD_GET_STATION,
8852 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008853 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008854 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008855 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8856 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008857 },
8858 {
8859 .cmd = NL80211_CMD_SET_STATION,
8860 .doit = nl80211_set_station,
8861 .policy = nl80211_policy,
8862 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008863 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008864 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008865 },
8866 {
8867 .cmd = NL80211_CMD_NEW_STATION,
8868 .doit = nl80211_new_station,
8869 .policy = nl80211_policy,
8870 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008871 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008872 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008873 },
8874 {
8875 .cmd = NL80211_CMD_DEL_STATION,
8876 .doit = nl80211_del_station,
8877 .policy = nl80211_policy,
8878 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008880 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008881 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008882 {
8883 .cmd = NL80211_CMD_GET_MPATH,
8884 .doit = nl80211_get_mpath,
8885 .dumpit = nl80211_dump_mpath,
8886 .policy = nl80211_policy,
8887 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008889 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008890 },
8891 {
8892 .cmd = NL80211_CMD_SET_MPATH,
8893 .doit = nl80211_set_mpath,
8894 .policy = nl80211_policy,
8895 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008897 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008898 },
8899 {
8900 .cmd = NL80211_CMD_NEW_MPATH,
8901 .doit = nl80211_new_mpath,
8902 .policy = nl80211_policy,
8903 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008904 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008905 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008906 },
8907 {
8908 .cmd = NL80211_CMD_DEL_MPATH,
8909 .doit = nl80211_del_mpath,
8910 .policy = nl80211_policy,
8911 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008912 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008913 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008914 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008915 {
8916 .cmd = NL80211_CMD_SET_BSS,
8917 .doit = nl80211_set_bss,
8918 .policy = nl80211_policy,
8919 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008920 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008921 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008922 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008923 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008924 .cmd = NL80211_CMD_GET_REG,
8925 .doit = nl80211_get_reg,
8926 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008927 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008928 /* can be retrieved by unprivileged users */
8929 },
8930 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008931 .cmd = NL80211_CMD_SET_REG,
8932 .doit = nl80211_set_reg,
8933 .policy = nl80211_policy,
8934 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008935 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008936 },
8937 {
8938 .cmd = NL80211_CMD_REQ_SET_REG,
8939 .doit = nl80211_req_set_reg,
8940 .policy = nl80211_policy,
8941 .flags = GENL_ADMIN_PERM,
8942 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008943 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008944 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8945 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008946 .policy = nl80211_policy,
8947 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008949 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008950 },
8951 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008952 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8953 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008954 .policy = nl80211_policy,
8955 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008956 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008957 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008958 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008959 {
Johannes Berg2a519312009-02-10 21:25:55 +01008960 .cmd = NL80211_CMD_TRIGGER_SCAN,
8961 .doit = nl80211_trigger_scan,
8962 .policy = nl80211_policy,
8963 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008964 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008965 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008966 },
8967 {
8968 .cmd = NL80211_CMD_GET_SCAN,
8969 .policy = nl80211_policy,
8970 .dumpit = nl80211_dump_scan,
8971 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008972 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008973 .cmd = NL80211_CMD_START_SCHED_SCAN,
8974 .doit = nl80211_start_sched_scan,
8975 .policy = nl80211_policy,
8976 .flags = GENL_ADMIN_PERM,
8977 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8978 NL80211_FLAG_NEED_RTNL,
8979 },
8980 {
8981 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8982 .doit = nl80211_stop_sched_scan,
8983 .policy = nl80211_policy,
8984 .flags = GENL_ADMIN_PERM,
8985 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8986 NL80211_FLAG_NEED_RTNL,
8987 },
8988 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008989 .cmd = NL80211_CMD_AUTHENTICATE,
8990 .doit = nl80211_authenticate,
8991 .policy = nl80211_policy,
8992 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008993 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008994 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008995 },
8996 {
8997 .cmd = NL80211_CMD_ASSOCIATE,
8998 .doit = nl80211_associate,
8999 .policy = nl80211_policy,
9000 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009001 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009002 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009003 },
9004 {
9005 .cmd = NL80211_CMD_DEAUTHENTICATE,
9006 .doit = nl80211_deauthenticate,
9007 .policy = nl80211_policy,
9008 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009010 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009011 },
9012 {
9013 .cmd = NL80211_CMD_DISASSOCIATE,
9014 .doit = nl80211_disassociate,
9015 .policy = nl80211_policy,
9016 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009017 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009018 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009019 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009020 {
9021 .cmd = NL80211_CMD_JOIN_IBSS,
9022 .doit = nl80211_join_ibss,
9023 .policy = nl80211_policy,
9024 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009026 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009027 },
9028 {
9029 .cmd = NL80211_CMD_LEAVE_IBSS,
9030 .doit = nl80211_leave_ibss,
9031 .policy = nl80211_policy,
9032 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009034 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009035 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009036#ifdef CONFIG_NL80211_TESTMODE
9037 {
9038 .cmd = NL80211_CMD_TESTMODE,
9039 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009040 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009041 .policy = nl80211_policy,
9042 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009043 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9044 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009045 },
9046#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009047 {
9048 .cmd = NL80211_CMD_CONNECT,
9049 .doit = nl80211_connect,
9050 .policy = nl80211_policy,
9051 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009052 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009053 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009054 },
9055 {
9056 .cmd = NL80211_CMD_DISCONNECT,
9057 .doit = nl80211_disconnect,
9058 .policy = nl80211_policy,
9059 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009061 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009062 },
Johannes Berg463d0182009-07-14 00:33:35 +02009063 {
9064 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9065 .doit = nl80211_wiphy_netns,
9066 .policy = nl80211_policy,
9067 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009068 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9069 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009070 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009071 {
9072 .cmd = NL80211_CMD_GET_SURVEY,
9073 .policy = nl80211_policy,
9074 .dumpit = nl80211_dump_survey,
9075 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009076 {
9077 .cmd = NL80211_CMD_SET_PMKSA,
9078 .doit = nl80211_setdel_pmksa,
9079 .policy = nl80211_policy,
9080 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009081 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009082 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009083 },
9084 {
9085 .cmd = NL80211_CMD_DEL_PMKSA,
9086 .doit = nl80211_setdel_pmksa,
9087 .policy = nl80211_policy,
9088 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009089 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009090 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009091 },
9092 {
9093 .cmd = NL80211_CMD_FLUSH_PMKSA,
9094 .doit = nl80211_flush_pmksa,
9095 .policy = nl80211_policy,
9096 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009098 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009099 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009100 {
9101 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9102 .doit = nl80211_remain_on_channel,
9103 .policy = nl80211_policy,
9104 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009105 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009106 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009107 },
9108 {
9109 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9110 .doit = nl80211_cancel_remain_on_channel,
9111 .policy = nl80211_policy,
9112 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009113 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009114 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009115 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009116 {
9117 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9118 .doit = nl80211_set_tx_bitrate_mask,
9119 .policy = nl80211_policy,
9120 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009121 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9122 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009123 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009124 {
Johannes Berg2e161f782010-08-12 15:38:38 +02009125 .cmd = NL80211_CMD_REGISTER_FRAME,
9126 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009127 .policy = nl80211_policy,
9128 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009129 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009130 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009131 },
9132 {
Johannes Berg2e161f782010-08-12 15:38:38 +02009133 .cmd = NL80211_CMD_FRAME,
9134 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009135 .policy = nl80211_policy,
9136 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009137 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009138 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009139 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009140 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009141 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9142 .doit = nl80211_tx_mgmt_cancel_wait,
9143 .policy = nl80211_policy,
9144 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009145 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009146 NL80211_FLAG_NEED_RTNL,
9147 },
9148 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009149 .cmd = NL80211_CMD_SET_POWER_SAVE,
9150 .doit = nl80211_set_power_save,
9151 .policy = nl80211_policy,
9152 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009153 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9154 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009155 },
9156 {
9157 .cmd = NL80211_CMD_GET_POWER_SAVE,
9158 .doit = nl80211_get_power_save,
9159 .policy = nl80211_policy,
9160 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009161 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9162 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009163 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009164 {
9165 .cmd = NL80211_CMD_SET_CQM,
9166 .doit = nl80211_set_cqm,
9167 .policy = nl80211_policy,
9168 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009169 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9170 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009171 },
Johannes Bergf444de02010-05-05 15:25:02 +02009172 {
9173 .cmd = NL80211_CMD_SET_CHANNEL,
9174 .doit = nl80211_set_channel,
9175 .policy = nl80211_policy,
9176 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009177 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9178 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009179 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009180 {
9181 .cmd = NL80211_CMD_SET_WDS_PEER,
9182 .doit = nl80211_set_wds_peer,
9183 .policy = nl80211_policy,
9184 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009185 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9186 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009187 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009188 {
9189 .cmd = NL80211_CMD_JOIN_MESH,
9190 .doit = nl80211_join_mesh,
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_LEAVE_MESH,
9198 .doit = nl80211_leave_mesh,
9199 .policy = nl80211_policy,
9200 .flags = GENL_ADMIN_PERM,
9201 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9202 NL80211_FLAG_NEED_RTNL,
9203 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009204#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009205 {
9206 .cmd = NL80211_CMD_GET_WOWLAN,
9207 .doit = nl80211_get_wowlan,
9208 .policy = nl80211_policy,
9209 /* can be retrieved by unprivileged users */
9210 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9211 NL80211_FLAG_NEED_RTNL,
9212 },
9213 {
9214 .cmd = NL80211_CMD_SET_WOWLAN,
9215 .doit = nl80211_set_wowlan,
9216 .policy = nl80211_policy,
9217 .flags = GENL_ADMIN_PERM,
9218 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9219 NL80211_FLAG_NEED_RTNL,
9220 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009221#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009222 {
9223 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9224 .doit = nl80211_set_rekey_data,
9225 .policy = nl80211_policy,
9226 .flags = GENL_ADMIN_PERM,
9227 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9228 NL80211_FLAG_NEED_RTNL,
9229 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009230 {
9231 .cmd = NL80211_CMD_TDLS_MGMT,
9232 .doit = nl80211_tdls_mgmt,
9233 .policy = nl80211_policy,
9234 .flags = GENL_ADMIN_PERM,
9235 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9236 NL80211_FLAG_NEED_RTNL,
9237 },
9238 {
9239 .cmd = NL80211_CMD_TDLS_OPER,
9240 .doit = nl80211_tdls_oper,
9241 .policy = nl80211_policy,
9242 .flags = GENL_ADMIN_PERM,
9243 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9244 NL80211_FLAG_NEED_RTNL,
9245 },
Johannes Berg28946da2011-11-04 11:18:12 +01009246 {
9247 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9248 .doit = nl80211_register_unexpected_frame,
9249 .policy = nl80211_policy,
9250 .flags = GENL_ADMIN_PERM,
9251 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9252 NL80211_FLAG_NEED_RTNL,
9253 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009254 {
9255 .cmd = NL80211_CMD_PROBE_CLIENT,
9256 .doit = nl80211_probe_client,
9257 .policy = nl80211_policy,
9258 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009259 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009260 NL80211_FLAG_NEED_RTNL,
9261 },
Johannes Berg5e760232011-11-04 11:18:17 +01009262 {
9263 .cmd = NL80211_CMD_REGISTER_BEACONS,
9264 .doit = nl80211_register_beacons,
9265 .policy = nl80211_policy,
9266 .flags = GENL_ADMIN_PERM,
9267 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9268 NL80211_FLAG_NEED_RTNL,
9269 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009270 {
9271 .cmd = NL80211_CMD_SET_NOACK_MAP,
9272 .doit = nl80211_set_noack_map,
9273 .policy = nl80211_policy,
9274 .flags = GENL_ADMIN_PERM,
9275 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9276 NL80211_FLAG_NEED_RTNL,
9277 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009278 {
9279 .cmd = NL80211_CMD_START_P2P_DEVICE,
9280 .doit = nl80211_start_p2p_device,
9281 .policy = nl80211_policy,
9282 .flags = GENL_ADMIN_PERM,
9283 .internal_flags = NL80211_FLAG_NEED_WDEV |
9284 NL80211_FLAG_NEED_RTNL,
9285 },
9286 {
9287 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9288 .doit = nl80211_stop_p2p_device,
9289 .policy = nl80211_policy,
9290 .flags = GENL_ADMIN_PERM,
9291 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9292 NL80211_FLAG_NEED_RTNL,
9293 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009294 {
9295 .cmd = NL80211_CMD_SET_MCAST_RATE,
9296 .doit = nl80211_set_mcast_rate,
9297 .policy = nl80211_policy,
9298 .flags = GENL_ADMIN_PERM,
9299 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9300 NL80211_FLAG_NEED_RTNL,
9301 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309302 {
9303 .cmd = NL80211_CMD_SET_MAC_ACL,
9304 .doit = nl80211_set_mac_acl,
9305 .policy = nl80211_policy,
9306 .flags = GENL_ADMIN_PERM,
9307 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9308 NL80211_FLAG_NEED_RTNL,
9309 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009310 {
9311 .cmd = NL80211_CMD_RADAR_DETECT,
9312 .doit = nl80211_start_radar_detection,
9313 .policy = nl80211_policy,
9314 .flags = GENL_ADMIN_PERM,
9315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9316 NL80211_FLAG_NEED_RTNL,
9317 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009318 {
9319 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9320 .doit = nl80211_get_protocol_features,
9321 .policy = nl80211_policy,
9322 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009323 {
9324 .cmd = NL80211_CMD_UPDATE_FT_IES,
9325 .doit = nl80211_update_ft_ies,
9326 .policy = nl80211_policy,
9327 .flags = GENL_ADMIN_PERM,
9328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9329 NL80211_FLAG_NEED_RTNL,
9330 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009331 {
9332 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9333 .doit = nl80211_crit_protocol_start,
9334 .policy = nl80211_policy,
9335 .flags = GENL_ADMIN_PERM,
9336 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9337 NL80211_FLAG_NEED_RTNL,
9338 },
9339 {
9340 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9341 .doit = nl80211_crit_protocol_stop,
9342 .policy = nl80211_policy,
9343 .flags = GENL_ADMIN_PERM,
9344 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9345 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009346 },
9347 {
9348 .cmd = NL80211_CMD_GET_COALESCE,
9349 .doit = nl80211_get_coalesce,
9350 .policy = nl80211_policy,
9351 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9352 NL80211_FLAG_NEED_RTNL,
9353 },
9354 {
9355 .cmd = NL80211_CMD_SET_COALESCE,
9356 .doit = nl80211_set_coalesce,
9357 .policy = nl80211_policy,
9358 .flags = GENL_ADMIN_PERM,
9359 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9360 NL80211_FLAG_NEED_RTNL,
Arend van Spriel5de17982013-04-18 15:49:00 +02009361 }
Johannes Berg55682962007-09-20 13:09:35 -04009362};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009363
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009364static struct genl_multicast_group nl80211_mlme_mcgrp = {
9365 .name = "mlme",
9366};
Johannes Berg55682962007-09-20 13:09:35 -04009367
9368/* multicast groups */
9369static struct genl_multicast_group nl80211_config_mcgrp = {
9370 .name = "config",
9371};
Johannes Berg2a519312009-02-10 21:25:55 +01009372static struct genl_multicast_group nl80211_scan_mcgrp = {
9373 .name = "scan",
9374};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009375static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9376 .name = "regulatory",
9377};
Johannes Berg55682962007-09-20 13:09:35 -04009378
9379/* notification functions */
9380
9381void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9382{
9383 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009384 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009385
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009386 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009387 if (!msg)
9388 return;
9389
Johannes Berg86e8cf92013-06-19 10:57:22 +02009390 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009391 nlmsg_free(msg);
9392 return;
9393 }
9394
Johannes Berg463d0182009-07-14 00:33:35 +02009395 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9396 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009397}
9398
Johannes Berg362a4152009-05-24 16:43:15 +02009399static int nl80211_add_scan_req(struct sk_buff *msg,
9400 struct cfg80211_registered_device *rdev)
9401{
9402 struct cfg80211_scan_request *req = rdev->scan_req;
9403 struct nlattr *nest;
9404 int i;
9405
9406 if (WARN_ON(!req))
9407 return 0;
9408
9409 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9410 if (!nest)
9411 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009412 for (i = 0; i < req->n_ssids; i++) {
9413 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9414 goto nla_put_failure;
9415 }
Johannes Berg362a4152009-05-24 16:43:15 +02009416 nla_nest_end(msg, nest);
9417
9418 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9419 if (!nest)
9420 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009421 for (i = 0; i < req->n_channels; i++) {
9422 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9423 goto nla_put_failure;
9424 }
Johannes Berg362a4152009-05-24 16:43:15 +02009425 nla_nest_end(msg, nest);
9426
David S. Miller9360ffd2012-03-29 04:41:26 -04009427 if (req->ie &&
9428 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9429 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009430
Sam Lefflered4737712012-10-11 21:03:31 -07009431 if (req->flags)
9432 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9433
Johannes Berg362a4152009-05-24 16:43:15 +02009434 return 0;
9435 nla_put_failure:
9436 return -ENOBUFS;
9437}
9438
Johannes Berga538e2d2009-06-16 19:56:42 +02009439static int nl80211_send_scan_msg(struct sk_buff *msg,
9440 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009441 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009442 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009443 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009444{
9445 void *hdr;
9446
Eric W. Biederman15e47302012-09-07 20:12:54 +00009447 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009448 if (!hdr)
9449 return -1;
9450
David S. Miller9360ffd2012-03-29 04:41:26 -04009451 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009452 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9453 wdev->netdev->ifindex)) ||
9454 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009455 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009456
Johannes Berg362a4152009-05-24 16:43:15 +02009457 /* ignore errors and send incomplete event anyway */
9458 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009459
9460 return genlmsg_end(msg, hdr);
9461
9462 nla_put_failure:
9463 genlmsg_cancel(msg, hdr);
9464 return -EMSGSIZE;
9465}
9466
Luciano Coelho807f8a82011-05-11 17:09:35 +03009467static int
9468nl80211_send_sched_scan_msg(struct sk_buff *msg,
9469 struct cfg80211_registered_device *rdev,
9470 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009471 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009472{
9473 void *hdr;
9474
Eric W. Biederman15e47302012-09-07 20:12:54 +00009475 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009476 if (!hdr)
9477 return -1;
9478
David S. Miller9360ffd2012-03-29 04:41:26 -04009479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9480 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9481 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009482
9483 return genlmsg_end(msg, hdr);
9484
9485 nla_put_failure:
9486 genlmsg_cancel(msg, hdr);
9487 return -EMSGSIZE;
9488}
9489
Johannes Berga538e2d2009-06-16 19:56:42 +02009490void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009491 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009492{
9493 struct sk_buff *msg;
9494
Thomas Graf58050fc2012-06-28 03:57:45 +00009495 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009496 if (!msg)
9497 return;
9498
Johannes Bergfd014282012-06-18 19:17:03 +02009499 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009500 NL80211_CMD_TRIGGER_SCAN) < 0) {
9501 nlmsg_free(msg);
9502 return;
9503 }
9504
Johannes Berg463d0182009-07-14 00:33:35 +02009505 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9506 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009507}
9508
Johannes Berg2a519312009-02-10 21:25:55 +01009509void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009510 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009511{
9512 struct sk_buff *msg;
9513
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009515 if (!msg)
9516 return;
9517
Johannes Bergfd014282012-06-18 19:17:03 +02009518 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009519 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009520 nlmsg_free(msg);
9521 return;
9522 }
9523
Johannes Berg463d0182009-07-14 00:33:35 +02009524 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9525 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009526}
9527
9528void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009529 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009530{
9531 struct sk_buff *msg;
9532
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009533 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009534 if (!msg)
9535 return;
9536
Johannes Bergfd014282012-06-18 19:17:03 +02009537 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009538 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009539 nlmsg_free(msg);
9540 return;
9541 }
9542
Johannes Berg463d0182009-07-14 00:33:35 +02009543 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9544 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009545}
9546
Luciano Coelho807f8a82011-05-11 17:09:35 +03009547void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9548 struct net_device *netdev)
9549{
9550 struct sk_buff *msg;
9551
9552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9553 if (!msg)
9554 return;
9555
9556 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9557 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9558 nlmsg_free(msg);
9559 return;
9560 }
9561
9562 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9563 nl80211_scan_mcgrp.id, GFP_KERNEL);
9564}
9565
9566void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9567 struct net_device *netdev, u32 cmd)
9568{
9569 struct sk_buff *msg;
9570
Thomas Graf58050fc2012-06-28 03:57:45 +00009571 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009572 if (!msg)
9573 return;
9574
9575 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9576 nlmsg_free(msg);
9577 return;
9578 }
9579
9580 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9581 nl80211_scan_mcgrp.id, GFP_KERNEL);
9582}
9583
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009584/*
9585 * This can happen on global regulatory changes or device specific settings
9586 * based on custom world regulatory domains.
9587 */
9588void nl80211_send_reg_change_event(struct regulatory_request *request)
9589{
9590 struct sk_buff *msg;
9591 void *hdr;
9592
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009593 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009594 if (!msg)
9595 return;
9596
9597 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9598 if (!hdr) {
9599 nlmsg_free(msg);
9600 return;
9601 }
9602
9603 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009604 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9605 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009606
David S. Miller9360ffd2012-03-29 04:41:26 -04009607 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9608 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9609 NL80211_REGDOM_TYPE_WORLD))
9610 goto nla_put_failure;
9611 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9612 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9613 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9614 goto nla_put_failure;
9615 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9616 request->intersect) {
9617 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9618 NL80211_REGDOM_TYPE_INTERSECTION))
9619 goto nla_put_failure;
9620 } else {
9621 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9622 NL80211_REGDOM_TYPE_COUNTRY) ||
9623 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9624 request->alpha2))
9625 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009626 }
9627
Johannes Bergf4173762012-12-03 18:23:37 +01009628 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009629 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9630 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009631
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009632 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009633
Johannes Bergbc43b282009-07-25 10:54:13 +02009634 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009635 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009636 GFP_ATOMIC);
9637 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009638
9639 return;
9640
9641nla_put_failure:
9642 genlmsg_cancel(msg, hdr);
9643 nlmsg_free(msg);
9644}
9645
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009646static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9647 struct net_device *netdev,
9648 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009649 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009650{
9651 struct sk_buff *msg;
9652 void *hdr;
9653
Johannes Berge6d6e342009-07-01 21:26:47 +02009654 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009655 if (!msg)
9656 return;
9657
9658 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9659 if (!hdr) {
9660 nlmsg_free(msg);
9661 return;
9662 }
9663
David S. Miller9360ffd2012-03-29 04:41:26 -04009664 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9665 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9666 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9667 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009668
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009669 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009670
Johannes Berg463d0182009-07-14 00:33:35 +02009671 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9672 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009673 return;
9674
9675 nla_put_failure:
9676 genlmsg_cancel(msg, hdr);
9677 nlmsg_free(msg);
9678}
9679
9680void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009681 struct net_device *netdev, const u8 *buf,
9682 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009683{
9684 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009685 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009686}
9687
9688void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9689 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009690 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009691{
Johannes Berge6d6e342009-07-01 21:26:47 +02009692 nl80211_send_mlme_event(rdev, netdev, buf, len,
9693 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009694}
9695
Jouni Malinen53b46b82009-03-27 20:53:56 +02009696void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009697 struct net_device *netdev, const u8 *buf,
9698 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009699{
9700 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009701 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009702}
9703
Jouni Malinen53b46b82009-03-27 20:53:56 +02009704void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9705 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009706 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009707{
9708 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009709 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009710}
9711
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009712void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9713 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009714{
Johannes Berg947add32013-02-22 22:05:20 +01009715 struct wireless_dev *wdev = dev->ieee80211_ptr;
9716 struct wiphy *wiphy = wdev->wiphy;
9717 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009718 const struct ieee80211_mgmt *mgmt = (void *)buf;
9719 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009720
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009721 if (WARN_ON(len < 2))
9722 return;
9723
9724 if (ieee80211_is_deauth(mgmt->frame_control))
9725 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9726 else
9727 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9728
9729 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9730 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009731}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009732EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009733
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009734static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9735 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009736 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009737{
9738 struct sk_buff *msg;
9739 void *hdr;
9740
Johannes Berge6d6e342009-07-01 21:26:47 +02009741 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009742 if (!msg)
9743 return;
9744
9745 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9746 if (!hdr) {
9747 nlmsg_free(msg);
9748 return;
9749 }
9750
David S. Miller9360ffd2012-03-29 04:41:26 -04009751 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9752 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9753 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9754 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9755 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009756
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009757 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009758
Johannes Berg463d0182009-07-14 00:33:35 +02009759 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9760 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009761 return;
9762
9763 nla_put_failure:
9764 genlmsg_cancel(msg, hdr);
9765 nlmsg_free(msg);
9766}
9767
9768void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009769 struct net_device *netdev, const u8 *addr,
9770 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009771{
9772 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009773 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009774}
9775
9776void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009777 struct net_device *netdev, const u8 *addr,
9778 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009779{
Johannes Berge6d6e342009-07-01 21:26:47 +02009780 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9781 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009782}
9783
Samuel Ortizb23aa672009-07-01 21:26:54 +02009784void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9785 struct net_device *netdev, const u8 *bssid,
9786 const u8 *req_ie, size_t req_ie_len,
9787 const u8 *resp_ie, size_t resp_ie_len,
9788 u16 status, gfp_t gfp)
9789{
9790 struct sk_buff *msg;
9791 void *hdr;
9792
Thomas Graf58050fc2012-06-28 03:57:45 +00009793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009794 if (!msg)
9795 return;
9796
9797 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9798 if (!hdr) {
9799 nlmsg_free(msg);
9800 return;
9801 }
9802
David S. Miller9360ffd2012-03-29 04:41:26 -04009803 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9804 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9805 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9806 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9807 (req_ie &&
9808 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9809 (resp_ie &&
9810 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9811 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009812
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009813 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009814
Johannes Berg463d0182009-07-14 00:33:35 +02009815 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9816 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009817 return;
9818
9819 nla_put_failure:
9820 genlmsg_cancel(msg, hdr);
9821 nlmsg_free(msg);
9822
9823}
9824
9825void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9826 struct net_device *netdev, const u8 *bssid,
9827 const u8 *req_ie, size_t req_ie_len,
9828 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9829{
9830 struct sk_buff *msg;
9831 void *hdr;
9832
Thomas Graf58050fc2012-06-28 03:57:45 +00009833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009834 if (!msg)
9835 return;
9836
9837 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9838 if (!hdr) {
9839 nlmsg_free(msg);
9840 return;
9841 }
9842
David S. Miller9360ffd2012-03-29 04:41:26 -04009843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9845 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9846 (req_ie &&
9847 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9848 (resp_ie &&
9849 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9850 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009851
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009852 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009853
Johannes Berg463d0182009-07-14 00:33:35 +02009854 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9855 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009856 return;
9857
9858 nla_put_failure:
9859 genlmsg_cancel(msg, hdr);
9860 nlmsg_free(msg);
9861
9862}
9863
9864void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9865 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009866 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009867{
9868 struct sk_buff *msg;
9869 void *hdr;
9870
Thomas Graf58050fc2012-06-28 03:57:45 +00009871 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009872 if (!msg)
9873 return;
9874
9875 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9876 if (!hdr) {
9877 nlmsg_free(msg);
9878 return;
9879 }
9880
David S. Miller9360ffd2012-03-29 04:41:26 -04009881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9883 (from_ap && reason &&
9884 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9885 (from_ap &&
9886 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9887 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9888 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009889
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009890 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009891
Johannes Berg463d0182009-07-14 00:33:35 +02009892 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9893 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009894 return;
9895
9896 nla_put_failure:
9897 genlmsg_cancel(msg, hdr);
9898 nlmsg_free(msg);
9899
9900}
9901
Johannes Berg04a773a2009-04-19 21:24:32 +02009902void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9903 struct net_device *netdev, const u8 *bssid,
9904 gfp_t gfp)
9905{
9906 struct sk_buff *msg;
9907 void *hdr;
9908
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009910 if (!msg)
9911 return;
9912
9913 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9914 if (!hdr) {
9915 nlmsg_free(msg);
9916 return;
9917 }
9918
David S. Miller9360ffd2012-03-29 04:41:26 -04009919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9920 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9921 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9922 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009923
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009924 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009925
Johannes Berg463d0182009-07-14 00:33:35 +02009926 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9927 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009928 return;
9929
9930 nla_put_failure:
9931 genlmsg_cancel(msg, hdr);
9932 nlmsg_free(msg);
9933}
9934
Johannes Berg947add32013-02-22 22:05:20 +01009935void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9936 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009937{
Johannes Berg947add32013-02-22 22:05:20 +01009938 struct wireless_dev *wdev = dev->ieee80211_ptr;
9939 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009940 struct sk_buff *msg;
9941 void *hdr;
9942
Johannes Berg947add32013-02-22 22:05:20 +01009943 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9944 return;
9945
9946 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9947
Javier Cardonac93b5e72011-04-07 15:08:34 -07009948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9949 if (!msg)
9950 return;
9951
9952 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9953 if (!hdr) {
9954 nlmsg_free(msg);
9955 return;
9956 }
9957
David S. Miller9360ffd2012-03-29 04:41:26 -04009958 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009959 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9960 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009961 (ie_len && ie &&
9962 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9963 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009964
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009965 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009966
9967 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9968 nl80211_mlme_mcgrp.id, gfp);
9969 return;
9970
9971 nla_put_failure:
9972 genlmsg_cancel(msg, hdr);
9973 nlmsg_free(msg);
9974}
Johannes Berg947add32013-02-22 22:05:20 +01009975EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009976
Jouni Malinena3b8b052009-03-27 21:59:49 +02009977void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9978 struct net_device *netdev, const u8 *addr,
9979 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009980 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009981{
9982 struct sk_buff *msg;
9983 void *hdr;
9984
Johannes Berge6d6e342009-07-01 21:26:47 +02009985 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009986 if (!msg)
9987 return;
9988
9989 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9990 if (!hdr) {
9991 nlmsg_free(msg);
9992 return;
9993 }
9994
David S. Miller9360ffd2012-03-29 04:41:26 -04009995 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9997 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9998 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9999 (key_id != -1 &&
10000 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10001 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10002 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010003
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010004 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010005
Johannes Berg463d0182009-07-14 00:33:35 +020010006 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10007 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010008 return;
10009
10010 nla_put_failure:
10011 genlmsg_cancel(msg, hdr);
10012 nlmsg_free(msg);
10013}
10014
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010015void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10016 struct ieee80211_channel *channel_before,
10017 struct ieee80211_channel *channel_after)
10018{
10019 struct sk_buff *msg;
10020 void *hdr;
10021 struct nlattr *nl_freq;
10022
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010023 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010024 if (!msg)
10025 return;
10026
10027 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10028 if (!hdr) {
10029 nlmsg_free(msg);
10030 return;
10031 }
10032
10033 /*
10034 * Since we are applying the beacon hint to a wiphy we know its
10035 * wiphy_idx is valid
10036 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010037 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10038 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010039
10040 /* Before */
10041 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10042 if (!nl_freq)
10043 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010044 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010045 goto nla_put_failure;
10046 nla_nest_end(msg, nl_freq);
10047
10048 /* After */
10049 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10050 if (!nl_freq)
10051 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010052 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010053 goto nla_put_failure;
10054 nla_nest_end(msg, nl_freq);
10055
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010056 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010057
Johannes Berg463d0182009-07-14 00:33:35 +020010058 rcu_read_lock();
10059 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10060 GFP_ATOMIC);
10061 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010062
10063 return;
10064
10065nla_put_failure:
10066 genlmsg_cancel(msg, hdr);
10067 nlmsg_free(msg);
10068}
10069
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010070static void nl80211_send_remain_on_chan_event(
10071 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010072 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010073 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010074 unsigned int duration, gfp_t gfp)
10075{
10076 struct sk_buff *msg;
10077 void *hdr;
10078
10079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10080 if (!msg)
10081 return;
10082
10083 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10084 if (!hdr) {
10085 nlmsg_free(msg);
10086 return;
10087 }
10088
David S. Miller9360ffd2012-03-29 04:41:26 -040010089 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010090 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10091 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010092 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010093 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010094 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10095 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010096 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10097 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010098
David S. Miller9360ffd2012-03-29 04:41:26 -040010099 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10100 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10101 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010102
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010103 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010104
10105 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10106 nl80211_mlme_mcgrp.id, gfp);
10107 return;
10108
10109 nla_put_failure:
10110 genlmsg_cancel(msg, hdr);
10111 nlmsg_free(msg);
10112}
10113
Johannes Berg947add32013-02-22 22:05:20 +010010114void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10115 struct ieee80211_channel *chan,
10116 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010117{
Johannes Berg947add32013-02-22 22:05:20 +010010118 struct wiphy *wiphy = wdev->wiphy;
10119 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10120
10121 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010122 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010123 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010124 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010125}
Johannes Berg947add32013-02-22 22:05:20 +010010126EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010127
Johannes Berg947add32013-02-22 22:05:20 +010010128void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10129 struct ieee80211_channel *chan,
10130 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010131{
Johannes Berg947add32013-02-22 22:05:20 +010010132 struct wiphy *wiphy = wdev->wiphy;
10133 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10134
10135 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010136 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010137 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010138}
Johannes Berg947add32013-02-22 22:05:20 +010010139EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010140
Johannes Berg947add32013-02-22 22:05:20 +010010141void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10142 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010143{
Johannes Berg947add32013-02-22 22:05:20 +010010144 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10145 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010146 struct sk_buff *msg;
10147
Johannes Berg947add32013-02-22 22:05:20 +010010148 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10149
Thomas Graf58050fc2012-06-28 03:57:45 +000010150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010151 if (!msg)
10152 return;
10153
John W. Linville66266b32012-03-15 13:25:41 -040010154 if (nl80211_send_station(msg, 0, 0, 0,
10155 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010156 nlmsg_free(msg);
10157 return;
10158 }
10159
10160 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10161 nl80211_mlme_mcgrp.id, gfp);
10162}
Johannes Berg947add32013-02-22 22:05:20 +010010163EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010164
Johannes Berg947add32013-02-22 22:05:20 +010010165void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010166{
Johannes Berg947add32013-02-22 22:05:20 +010010167 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10168 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010169 struct sk_buff *msg;
10170 void *hdr;
10171
Johannes Berg947add32013-02-22 22:05:20 +010010172 trace_cfg80211_del_sta(dev, mac_addr);
10173
Thomas Graf58050fc2012-06-28 03:57:45 +000010174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010175 if (!msg)
10176 return;
10177
10178 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10179 if (!hdr) {
10180 nlmsg_free(msg);
10181 return;
10182 }
10183
David S. Miller9360ffd2012-03-29 04:41:26 -040010184 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10185 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10186 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010187
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010188 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010189
10190 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10191 nl80211_mlme_mcgrp.id, gfp);
10192 return;
10193
10194 nla_put_failure:
10195 genlmsg_cancel(msg, hdr);
10196 nlmsg_free(msg);
10197}
Johannes Berg947add32013-02-22 22:05:20 +010010198EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010199
Johannes Berg947add32013-02-22 22:05:20 +010010200void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10201 enum nl80211_connect_failed_reason reason,
10202 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010203{
Johannes Berg947add32013-02-22 22:05:20 +010010204 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10205 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010206 struct sk_buff *msg;
10207 void *hdr;
10208
10209 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10210 if (!msg)
10211 return;
10212
10213 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10214 if (!hdr) {
10215 nlmsg_free(msg);
10216 return;
10217 }
10218
10219 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10220 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10221 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10222 goto nla_put_failure;
10223
10224 genlmsg_end(msg, hdr);
10225
10226 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10227 nl80211_mlme_mcgrp.id, gfp);
10228 return;
10229
10230 nla_put_failure:
10231 genlmsg_cancel(msg, hdr);
10232 nlmsg_free(msg);
10233}
Johannes Berg947add32013-02-22 22:05:20 +010010234EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010235
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010236static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10237 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010238{
10239 struct wireless_dev *wdev = dev->ieee80211_ptr;
10240 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10241 struct sk_buff *msg;
10242 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010243 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010244
Eric W. Biederman15e47302012-09-07 20:12:54 +000010245 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010246 return false;
10247
10248 msg = nlmsg_new(100, gfp);
10249 if (!msg)
10250 return true;
10251
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010252 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010253 if (!hdr) {
10254 nlmsg_free(msg);
10255 return true;
10256 }
10257
David S. Miller9360ffd2012-03-29 04:41:26 -040010258 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10259 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10260 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10261 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010262
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010263 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010264 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010265 return true;
10266
10267 nla_put_failure:
10268 genlmsg_cancel(msg, hdr);
10269 nlmsg_free(msg);
10270 return true;
10271}
10272
Johannes Berg947add32013-02-22 22:05:20 +010010273bool cfg80211_rx_spurious_frame(struct net_device *dev,
10274 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010275{
Johannes Berg947add32013-02-22 22:05:20 +010010276 struct wireless_dev *wdev = dev->ieee80211_ptr;
10277 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010278
Johannes Berg947add32013-02-22 22:05:20 +010010279 trace_cfg80211_rx_spurious_frame(dev, addr);
10280
10281 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10282 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10283 trace_cfg80211_return_bool(false);
10284 return false;
10285 }
10286 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10287 addr, gfp);
10288 trace_cfg80211_return_bool(ret);
10289 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010290}
Johannes Berg947add32013-02-22 22:05:20 +010010291EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10292
10293bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10294 const u8 *addr, gfp_t gfp)
10295{
10296 struct wireless_dev *wdev = dev->ieee80211_ptr;
10297 bool ret;
10298
10299 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10300
10301 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10302 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10303 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10304 trace_cfg80211_return_bool(false);
10305 return false;
10306 }
10307 ret = __nl80211_unexpected_frame(dev,
10308 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10309 addr, gfp);
10310 trace_cfg80211_return_bool(ret);
10311 return ret;
10312}
10313EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010314
Johannes Berg2e161f782010-08-12 15:38:38 +020010315int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010316 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010317 int freq, int sig_dbm,
10318 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010319{
Johannes Berg71bbc992012-06-15 15:30:18 +020010320 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010321 struct sk_buff *msg;
10322 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010323
10324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10325 if (!msg)
10326 return -ENOMEM;
10327
Johannes Berg2e161f782010-08-12 15:38:38 +020010328 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010329 if (!hdr) {
10330 nlmsg_free(msg);
10331 return -ENOMEM;
10332 }
10333
David S. Miller9360ffd2012-03-29 04:41:26 -040010334 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010335 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10336 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010337 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010338 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10339 (sig_dbm &&
10340 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10341 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10342 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010343
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010344 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010345
Eric W. Biederman15e47302012-09-07 20:12:54 +000010346 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010347
10348 nla_put_failure:
10349 genlmsg_cancel(msg, hdr);
10350 nlmsg_free(msg);
10351 return -ENOBUFS;
10352}
10353
Johannes Berg947add32013-02-22 22:05:20 +010010354void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10355 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010356{
Johannes Berg947add32013-02-22 22:05:20 +010010357 struct wiphy *wiphy = wdev->wiphy;
10358 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010359 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010360 struct sk_buff *msg;
10361 void *hdr;
10362
Johannes Berg947add32013-02-22 22:05:20 +010010363 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10364
Jouni Malinen026331c2010-02-15 12:53:10 +020010365 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10366 if (!msg)
10367 return;
10368
Johannes Berg2e161f782010-08-12 15:38:38 +020010369 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010370 if (!hdr) {
10371 nlmsg_free(msg);
10372 return;
10373 }
10374
David S. Miller9360ffd2012-03-29 04:41:26 -040010375 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010376 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10377 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010378 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010379 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10380 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10381 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10382 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010383
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010384 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010385
10386 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10387 return;
10388
10389 nla_put_failure:
10390 genlmsg_cancel(msg, hdr);
10391 nlmsg_free(msg);
10392}
Johannes Berg947add32013-02-22 22:05:20 +010010393EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010394
Johannes Berg947add32013-02-22 22:05:20 +010010395void cfg80211_cqm_rssi_notify(struct net_device *dev,
10396 enum nl80211_cqm_rssi_threshold_event rssi_event,
10397 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010398{
Johannes Berg947add32013-02-22 22:05:20 +010010399 struct wireless_dev *wdev = dev->ieee80211_ptr;
10400 struct wiphy *wiphy = wdev->wiphy;
10401 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010402 struct sk_buff *msg;
10403 struct nlattr *pinfoattr;
10404 void *hdr;
10405
Johannes Berg947add32013-02-22 22:05:20 +010010406 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10407
Thomas Graf58050fc2012-06-28 03:57:45 +000010408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010409 if (!msg)
10410 return;
10411
10412 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10413 if (!hdr) {
10414 nlmsg_free(msg);
10415 return;
10416 }
10417
David S. Miller9360ffd2012-03-29 04:41:26 -040010418 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010419 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010420 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010421
10422 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10423 if (!pinfoattr)
10424 goto nla_put_failure;
10425
David S. Miller9360ffd2012-03-29 04:41:26 -040010426 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10427 rssi_event))
10428 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010429
10430 nla_nest_end(msg, pinfoattr);
10431
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010432 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010433
10434 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10435 nl80211_mlme_mcgrp.id, gfp);
10436 return;
10437
10438 nla_put_failure:
10439 genlmsg_cancel(msg, hdr);
10440 nlmsg_free(msg);
10441}
Johannes Berg947add32013-02-22 22:05:20 +010010442EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010443
Johannes Berg947add32013-02-22 22:05:20 +010010444static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10445 struct net_device *netdev, const u8 *bssid,
10446 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010447{
10448 struct sk_buff *msg;
10449 struct nlattr *rekey_attr;
10450 void *hdr;
10451
Thomas Graf58050fc2012-06-28 03:57:45 +000010452 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010453 if (!msg)
10454 return;
10455
10456 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10457 if (!hdr) {
10458 nlmsg_free(msg);
10459 return;
10460 }
10461
David S. Miller9360ffd2012-03-29 04:41:26 -040010462 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10463 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10464 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10465 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010466
10467 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10468 if (!rekey_attr)
10469 goto nla_put_failure;
10470
David S. Miller9360ffd2012-03-29 04:41:26 -040010471 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10472 NL80211_REPLAY_CTR_LEN, replay_ctr))
10473 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010474
10475 nla_nest_end(msg, rekey_attr);
10476
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010477 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010478
10479 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10480 nl80211_mlme_mcgrp.id, gfp);
10481 return;
10482
10483 nla_put_failure:
10484 genlmsg_cancel(msg, hdr);
10485 nlmsg_free(msg);
10486}
10487
Johannes Berg947add32013-02-22 22:05:20 +010010488void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10489 const u8 *replay_ctr, gfp_t gfp)
10490{
10491 struct wireless_dev *wdev = dev->ieee80211_ptr;
10492 struct wiphy *wiphy = wdev->wiphy;
10493 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10494
10495 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10496 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10497}
10498EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10499
10500static void
10501nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10502 struct net_device *netdev, int index,
10503 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010504{
10505 struct sk_buff *msg;
10506 struct nlattr *attr;
10507 void *hdr;
10508
Thomas Graf58050fc2012-06-28 03:57:45 +000010509 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010510 if (!msg)
10511 return;
10512
10513 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10514 if (!hdr) {
10515 nlmsg_free(msg);
10516 return;
10517 }
10518
David S. Miller9360ffd2012-03-29 04:41:26 -040010519 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10520 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10521 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010522
10523 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10524 if (!attr)
10525 goto nla_put_failure;
10526
David S. Miller9360ffd2012-03-29 04:41:26 -040010527 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10528 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10529 (preauth &&
10530 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10531 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010532
10533 nla_nest_end(msg, attr);
10534
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010535 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010536
10537 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10538 nl80211_mlme_mcgrp.id, gfp);
10539 return;
10540
10541 nla_put_failure:
10542 genlmsg_cancel(msg, hdr);
10543 nlmsg_free(msg);
10544}
10545
Johannes Berg947add32013-02-22 22:05:20 +010010546void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10547 const u8 *bssid, bool preauth, gfp_t gfp)
10548{
10549 struct wireless_dev *wdev = dev->ieee80211_ptr;
10550 struct wiphy *wiphy = wdev->wiphy;
10551 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10552
10553 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10554 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10555}
10556EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10557
10558static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10559 struct net_device *netdev,
10560 struct cfg80211_chan_def *chandef,
10561 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010562{
10563 struct sk_buff *msg;
10564 void *hdr;
10565
Thomas Graf58050fc2012-06-28 03:57:45 +000010566 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010567 if (!msg)
10568 return;
10569
10570 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10571 if (!hdr) {
10572 nlmsg_free(msg);
10573 return;
10574 }
10575
Johannes Berg683b6d32012-11-08 21:25:48 +010010576 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10577 goto nla_put_failure;
10578
10579 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010580 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010581
10582 genlmsg_end(msg, hdr);
10583
10584 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10585 nl80211_mlme_mcgrp.id, gfp);
10586 return;
10587
10588 nla_put_failure:
10589 genlmsg_cancel(msg, hdr);
10590 nlmsg_free(msg);
10591}
10592
Johannes Berg947add32013-02-22 22:05:20 +010010593void cfg80211_ch_switch_notify(struct net_device *dev,
10594 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010595{
Johannes Berg947add32013-02-22 22:05:20 +010010596 struct wireless_dev *wdev = dev->ieee80211_ptr;
10597 struct wiphy *wiphy = wdev->wiphy;
10598 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10599
10600 trace_cfg80211_ch_switch_notify(dev, chandef);
10601
10602 wdev_lock(wdev);
10603
10604 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10605 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10606 goto out;
10607
10608 wdev->channel = chandef->chan;
10609 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10610out:
10611 wdev_unlock(wdev);
10612 return;
10613}
10614EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10615
10616void cfg80211_cqm_txe_notify(struct net_device *dev,
10617 const u8 *peer, u32 num_packets,
10618 u32 rate, u32 intvl, gfp_t gfp)
10619{
10620 struct wireless_dev *wdev = dev->ieee80211_ptr;
10621 struct wiphy *wiphy = wdev->wiphy;
10622 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010623 struct sk_buff *msg;
10624 struct nlattr *pinfoattr;
10625 void *hdr;
10626
10627 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10628 if (!msg)
10629 return;
10630
10631 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10632 if (!hdr) {
10633 nlmsg_free(msg);
10634 return;
10635 }
10636
10637 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010638 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010639 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10640 goto nla_put_failure;
10641
10642 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10643 if (!pinfoattr)
10644 goto nla_put_failure;
10645
10646 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10647 goto nla_put_failure;
10648
10649 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10650 goto nla_put_failure;
10651
10652 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10653 goto nla_put_failure;
10654
10655 nla_nest_end(msg, pinfoattr);
10656
10657 genlmsg_end(msg, hdr);
10658
10659 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10660 nl80211_mlme_mcgrp.id, gfp);
10661 return;
10662
10663 nla_put_failure:
10664 genlmsg_cancel(msg, hdr);
10665 nlmsg_free(msg);
10666}
Johannes Berg947add32013-02-22 22:05:20 +010010667EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010668
10669void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010670nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10671 struct cfg80211_chan_def *chandef,
10672 enum nl80211_radar_event event,
10673 struct net_device *netdev, gfp_t gfp)
10674{
10675 struct sk_buff *msg;
10676 void *hdr;
10677
10678 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10679 if (!msg)
10680 return;
10681
10682 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10683 if (!hdr) {
10684 nlmsg_free(msg);
10685 return;
10686 }
10687
10688 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10689 goto nla_put_failure;
10690
10691 /* NOP and radar events don't need a netdev parameter */
10692 if (netdev) {
10693 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10694
10695 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10696 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10697 goto nla_put_failure;
10698 }
10699
10700 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10701 goto nla_put_failure;
10702
10703 if (nl80211_send_chandef(msg, chandef))
10704 goto nla_put_failure;
10705
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010706 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010707
10708 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10709 nl80211_mlme_mcgrp.id, gfp);
10710 return;
10711
10712 nla_put_failure:
10713 genlmsg_cancel(msg, hdr);
10714 nlmsg_free(msg);
10715}
10716
Johannes Berg947add32013-02-22 22:05:20 +010010717void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10718 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010719{
Johannes Berg947add32013-02-22 22:05:20 +010010720 struct wireless_dev *wdev = dev->ieee80211_ptr;
10721 struct wiphy *wiphy = wdev->wiphy;
10722 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010723 struct sk_buff *msg;
10724 struct nlattr *pinfoattr;
10725 void *hdr;
10726
Johannes Berg947add32013-02-22 22:05:20 +010010727 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10728
Thomas Graf58050fc2012-06-28 03:57:45 +000010729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010730 if (!msg)
10731 return;
10732
10733 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10734 if (!hdr) {
10735 nlmsg_free(msg);
10736 return;
10737 }
10738
David S. Miller9360ffd2012-03-29 04:41:26 -040010739 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010740 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010741 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10742 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010743
10744 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10745 if (!pinfoattr)
10746 goto nla_put_failure;
10747
David S. Miller9360ffd2012-03-29 04:41:26 -040010748 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10749 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010750
10751 nla_nest_end(msg, pinfoattr);
10752
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010753 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010754
10755 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10756 nl80211_mlme_mcgrp.id, gfp);
10757 return;
10758
10759 nla_put_failure:
10760 genlmsg_cancel(msg, hdr);
10761 nlmsg_free(msg);
10762}
Johannes Berg947add32013-02-22 22:05:20 +010010763EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010764
Johannes Berg7f6cf312011-11-04 11:18:15 +010010765void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10766 u64 cookie, bool acked, gfp_t gfp)
10767{
10768 struct wireless_dev *wdev = dev->ieee80211_ptr;
10769 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10770 struct sk_buff *msg;
10771 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010772
Beni Lev4ee3e062012-08-27 12:49:39 +030010773 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10774
Thomas Graf58050fc2012-06-28 03:57:45 +000010775 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010776
Johannes Berg7f6cf312011-11-04 11:18:15 +010010777 if (!msg)
10778 return;
10779
10780 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10781 if (!hdr) {
10782 nlmsg_free(msg);
10783 return;
10784 }
10785
David S. Miller9360ffd2012-03-29 04:41:26 -040010786 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10787 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10788 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10789 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10790 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10791 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010792
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010793 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010794
10795 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10796 nl80211_mlme_mcgrp.id, gfp);
10797 return;
10798
10799 nla_put_failure:
10800 genlmsg_cancel(msg, hdr);
10801 nlmsg_free(msg);
10802}
10803EXPORT_SYMBOL(cfg80211_probe_status);
10804
Johannes Berg5e760232011-11-04 11:18:17 +010010805void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10806 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010807 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010808{
10809 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10810 struct sk_buff *msg;
10811 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010812 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010813
Beni Lev4ee3e062012-08-27 12:49:39 +030010814 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10815
Ben Greear37c73b52012-10-26 14:49:25 -070010816 spin_lock_bh(&rdev->beacon_registrations_lock);
10817 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10818 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10819 if (!msg) {
10820 spin_unlock_bh(&rdev->beacon_registrations_lock);
10821 return;
10822 }
Johannes Berg5e760232011-11-04 11:18:17 +010010823
Ben Greear37c73b52012-10-26 14:49:25 -070010824 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10825 if (!hdr)
10826 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010827
Ben Greear37c73b52012-10-26 14:49:25 -070010828 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10829 (freq &&
10830 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10831 (sig_dbm &&
10832 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10833 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10834 goto nla_put_failure;
10835
10836 genlmsg_end(msg, hdr);
10837
10838 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010839 }
Ben Greear37c73b52012-10-26 14:49:25 -070010840 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010841 return;
10842
10843 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010844 spin_unlock_bh(&rdev->beacon_registrations_lock);
10845 if (hdr)
10846 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010847 nlmsg_free(msg);
10848}
10849EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10850
Johannes Bergcd8f7cb42013-01-22 12:34:29 +010010851#ifdef CONFIG_PM
10852void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10853 struct cfg80211_wowlan_wakeup *wakeup,
10854 gfp_t gfp)
10855{
10856 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10857 struct sk_buff *msg;
10858 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010859 int size = 200;
Johannes Bergcd8f7cb42013-01-22 12:34:29 +010010860
10861 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10862
10863 if (wakeup)
10864 size += wakeup->packet_present_len;
10865
10866 msg = nlmsg_new(size, gfp);
10867 if (!msg)
10868 return;
10869
10870 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10871 if (!hdr)
10872 goto free_msg;
10873
10874 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10875 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10876 goto free_msg;
10877
10878 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10879 wdev->netdev->ifindex))
10880 goto free_msg;
10881
10882 if (wakeup) {
10883 struct nlattr *reasons;
10884
10885 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10886
10887 if (wakeup->disconnect &&
10888 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10889 goto free_msg;
10890 if (wakeup->magic_pkt &&
10891 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10892 goto free_msg;
10893 if (wakeup->gtk_rekey_failure &&
10894 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10895 goto free_msg;
10896 if (wakeup->eap_identity_req &&
10897 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10898 goto free_msg;
10899 if (wakeup->four_way_handshake &&
10900 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10901 goto free_msg;
10902 if (wakeup->rfkill_release &&
10903 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10904 goto free_msg;
10905
10906 if (wakeup->pattern_idx >= 0 &&
10907 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10908 wakeup->pattern_idx))
10909 goto free_msg;
10910
Johannes Berg2a0e0472013-01-23 22:57:40 +010010911 if (wakeup->tcp_match)
10912 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10913
10914 if (wakeup->tcp_connlost)
10915 nla_put_flag(msg,
10916 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10917
10918 if (wakeup->tcp_nomoretokens)
10919 nla_put_flag(msg,
10920 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10921
Johannes Bergcd8f7cb42013-01-22 12:34:29 +010010922 if (wakeup->packet) {
10923 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10924 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10925
10926 if (!wakeup->packet_80211) {
10927 pkt_attr =
10928 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10929 len_attr =
10930 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10931 }
10932
10933 if (wakeup->packet_len &&
10934 nla_put_u32(msg, len_attr, wakeup->packet_len))
10935 goto free_msg;
10936
10937 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10938 wakeup->packet))
10939 goto free_msg;
10940 }
10941
10942 nla_nest_end(msg, reasons);
10943 }
10944
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010945 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb42013-01-22 12:34:29 +010010946
10947 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10948 nl80211_mlme_mcgrp.id, gfp);
10949 return;
10950
10951 free_msg:
10952 nlmsg_free(msg);
10953}
10954EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10955#endif
10956
Jouni Malinen3475b092012-11-16 22:49:57 +020010957void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10958 enum nl80211_tdls_operation oper,
10959 u16 reason_code, gfp_t gfp)
10960{
10961 struct wireless_dev *wdev = dev->ieee80211_ptr;
10962 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10963 struct sk_buff *msg;
10964 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010965
10966 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10967 reason_code);
10968
10969 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10970 if (!msg)
10971 return;
10972
10973 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10974 if (!hdr) {
10975 nlmsg_free(msg);
10976 return;
10977 }
10978
10979 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10980 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10981 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10982 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10983 (reason_code > 0 &&
10984 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10985 goto nla_put_failure;
10986
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010987 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010988
10989 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10990 nl80211_mlme_mcgrp.id, gfp);
10991 return;
10992
10993 nla_put_failure:
10994 genlmsg_cancel(msg, hdr);
10995 nlmsg_free(msg);
10996}
10997EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10998
Jouni Malinen026331c2010-02-15 12:53:10 +020010999static int nl80211_netlink_notify(struct notifier_block * nb,
11000 unsigned long state,
11001 void *_notify)
11002{
11003 struct netlink_notify *notify = _notify;
11004 struct cfg80211_registered_device *rdev;
11005 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011006 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011007
11008 if (state != NETLINK_URELEASE)
11009 return NOTIFY_DONE;
11010
11011 rcu_read_lock();
11012
Johannes Berg5e760232011-11-04 11:18:17 +010011013 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011014 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011015 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011016
11017 spin_lock_bh(&rdev->beacon_registrations_lock);
11018 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11019 list) {
11020 if (reg->nlportid == notify->portid) {
11021 list_del(&reg->list);
11022 kfree(reg);
11023 break;
11024 }
11025 }
11026 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011027 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011028
11029 rcu_read_unlock();
11030
11031 return NOTIFY_DONE;
11032}
11033
11034static struct notifier_block nl80211_netlink_notifier = {
11035 .notifier_call = nl80211_netlink_notify,
11036};
11037
Jouni Malinen355199e2013-02-27 17:14:27 +020011038void cfg80211_ft_event(struct net_device *netdev,
11039 struct cfg80211_ft_event_params *ft_event)
11040{
11041 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11042 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11043 struct sk_buff *msg;
11044 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011045
11046 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11047
11048 if (!ft_event->target_ap)
11049 return;
11050
11051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11052 if (!msg)
11053 return;
11054
11055 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11056 if (!hdr) {
11057 nlmsg_free(msg);
11058 return;
11059 }
11060
11061 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11062 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11063 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11064 if (ft_event->ies)
11065 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11066 if (ft_event->ric_ies)
11067 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11068 ft_event->ric_ies);
11069
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011070 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011071
11072 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11073 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11074}
11075EXPORT_SYMBOL(cfg80211_ft_event);
11076
Arend van Spriel5de17982013-04-18 15:49:00 +020011077void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11078{
11079 struct cfg80211_registered_device *rdev;
11080 struct sk_buff *msg;
11081 void *hdr;
11082 u32 nlportid;
11083
11084 rdev = wiphy_to_dev(wdev->wiphy);
11085 if (!rdev->crit_proto_nlportid)
11086 return;
11087
11088 nlportid = rdev->crit_proto_nlportid;
11089 rdev->crit_proto_nlportid = 0;
11090
11091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11092 if (!msg)
11093 return;
11094
11095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11096 if (!hdr)
11097 goto nla_put_failure;
11098
11099 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11100 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11101 goto nla_put_failure;
11102
11103 genlmsg_end(msg, hdr);
11104
11105 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11106 return;
11107
11108 nla_put_failure:
11109 if (hdr)
11110 genlmsg_cancel(msg, hdr);
11111 nlmsg_free(msg);
11112
11113}
11114EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11115
Johannes Berg55682962007-09-20 13:09:35 -040011116/* initialisation/exit functions */
11117
11118int nl80211_init(void)
11119{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011120 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011121
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011122 err = genl_register_family_with_ops(&nl80211_fam,
11123 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011124 if (err)
11125 return err;
11126
Johannes Berg55682962007-09-20 13:09:35 -040011127 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11128 if (err)
11129 goto err_out;
11130
Johannes Berg2a519312009-02-10 21:25:55 +010011131 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11132 if (err)
11133 goto err_out;
11134
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011135 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11136 if (err)
11137 goto err_out;
11138
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011139 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11140 if (err)
11141 goto err_out;
11142
Johannes Bergaff89a92009-07-01 21:26:51 +020011143#ifdef CONFIG_NL80211_TESTMODE
11144 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11145 if (err)
11146 goto err_out;
11147#endif
11148
Jouni Malinen026331c2010-02-15 12:53:10 +020011149 err = netlink_register_notifier(&nl80211_netlink_notifier);
11150 if (err)
11151 goto err_out;
11152
Johannes Berg55682962007-09-20 13:09:35 -040011153 return 0;
11154 err_out:
11155 genl_unregister_family(&nl80211_fam);
11156 return err;
11157}
11158
11159void nl80211_exit(void)
11160{
Jouni Malinen026331c2010-02-15 12:53:10 +020011161 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011162 genl_unregister_family(&nl80211_fam);
11163}