blob: 460638ac2d73b03a43cd0e6d575946d1658b5141 [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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Malinendc6382c2009-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 Berg2e161f72010-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 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200352 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
353 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
354 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
355 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
356 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530357 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
358 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Johannes Berg55682962007-09-20 13:09:35 -0400359};
360
Johannes Berge31b8212010-10-05 19:39:30 +0200361/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000362static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200363 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200364 [NL80211_KEY_IDX] = { .type = NLA_U8 },
365 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200366 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200367 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
368 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200369 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100370 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
371};
372
373/* policy for the key default flags */
374static const struct nla_policy
375nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
376 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
377 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200378};
379
Johannes Bergff1b6e62011-05-04 15:37:28 +0200380/* policy for WoWLAN attributes */
381static const struct nla_policy
382nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
383 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
385 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-07-13 10:48:55 +0200387 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
389 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
390 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100391 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
392};
393
394static const struct nla_policy
395nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
396 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
397 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
398 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
399 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
400 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
401 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
402 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
403 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
404 },
405 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
406 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
407 },
408 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
409 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
410 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200411};
412
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700413/* policy for coalesce rule attributes */
414static const struct nla_policy
415nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
416 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
417 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
418 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
419};
420
Johannes Berge5497d72011-07-05 16:35:40 +0200421/* policy for GTK rekey offload attributes */
422static const struct nla_policy
423nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
424 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
425 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
426 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
427};
428
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300429static const struct nla_policy
430nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200431 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300432 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700433 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300434};
435
Johannes Berg97990a02013-04-19 01:02:55 +0200436static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
437 struct netlink_callback *cb,
438 struct cfg80211_registered_device **rdev,
439 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100440{
Johannes Berg67748892010-10-04 21:14:06 +0200441 int err;
442
Johannes Berg67748892010-10-04 21:14:06 +0200443 rtnl_lock();
444
Johannes Berg97990a02013-04-19 01:02:55 +0200445 if (!cb->args[0]) {
446 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
447 nl80211_fam.attrbuf, nl80211_fam.maxattr,
448 nl80211_policy);
449 if (err)
450 goto out_unlock;
451
452 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
453 nl80211_fam.attrbuf);
454 if (IS_ERR(*wdev)) {
455 err = PTR_ERR(*wdev);
456 goto out_unlock;
457 }
458 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200459 /* 0 is the first index - add 1 to parse only once */
460 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200461 cb->args[1] = (*wdev)->identifier;
462 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200463 /* subtract the 1 again here */
464 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200465 struct wireless_dev *tmp;
466
467 if (!wiphy) {
468 err = -ENODEV;
469 goto out_unlock;
470 }
471 *rdev = wiphy_to_dev(wiphy);
472 *wdev = NULL;
473
Johannes Berg97990a02013-04-19 01:02:55 +0200474 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
475 if (tmp->identifier == cb->args[1]) {
476 *wdev = tmp;
477 break;
478 }
479 }
Johannes Berg97990a02013-04-19 01:02:55 +0200480
481 if (!*wdev) {
482 err = -ENODEV;
483 goto out_unlock;
484 }
Johannes Berg67748892010-10-04 21:14:06 +0200485 }
486
Johannes Berg67748892010-10-04 21:14:06 +0200487 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200488 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200489 rtnl_unlock();
490 return err;
491}
492
Johannes Berg97990a02013-04-19 01:02:55 +0200493static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200494{
Johannes Berg67748892010-10-04 21:14:06 +0200495 rtnl_unlock();
496}
497
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100498/* IE validation */
499static bool is_valid_ie_attr(const struct nlattr *attr)
500{
501 const u8 *pos;
502 int len;
503
504 if (!attr)
505 return true;
506
507 pos = nla_data(attr);
508 len = nla_len(attr);
509
510 while (len) {
511 u8 elemlen;
512
513 if (len < 2)
514 return false;
515 len -= 2;
516
517 elemlen = pos[1];
518 if (elemlen > len)
519 return false;
520
521 len -= elemlen;
522 pos += 2 + elemlen;
523 }
524
525 return true;
526}
527
Johannes Berg55682962007-09-20 13:09:35 -0400528/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000529static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400530 int flags, u8 cmd)
531{
532 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000533 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400534}
535
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400536static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100537 struct ieee80211_channel *chan,
538 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400539{
David S. Miller9360ffd2012-03-29 04:41:26 -0400540 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
541 chan->center_freq))
542 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400543
David S. Miller9360ffd2012-03-29 04:41:26 -0400544 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
545 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
546 goto nla_put_failure;
547 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
548 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
549 goto nla_put_failure;
550 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
551 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
552 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100553 if (chan->flags & IEEE80211_CHAN_RADAR) {
554 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
555 goto nla_put_failure;
556 if (large) {
557 u32 time;
558
559 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
560
561 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
562 chan->dfs_state))
563 goto nla_put_failure;
564 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
565 time))
566 goto nla_put_failure;
567 }
568 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400569
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100570 if (large) {
571 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
572 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
573 goto nla_put_failure;
574 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
575 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
576 goto nla_put_failure;
577 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
578 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
579 goto nla_put_failure;
580 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
581 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
582 goto nla_put_failure;
583 }
584
David S. Miller9360ffd2012-03-29 04:41:26 -0400585 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
586 DBM_TO_MBM(chan->max_power)))
587 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400588
589 return 0;
590
591 nla_put_failure:
592 return -ENOBUFS;
593}
594
Johannes Berg55682962007-09-20 13:09:35 -0400595/* netlink command implementations */
596
Johannes Bergb9454e82009-07-08 13:29:08 +0200597struct key_parse {
598 struct key_params p;
599 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200600 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200601 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100602 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200603};
604
605static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
606{
607 struct nlattr *tb[NL80211_KEY_MAX + 1];
608 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
609 nl80211_key_policy);
610 if (err)
611 return err;
612
613 k->def = !!tb[NL80211_KEY_DEFAULT];
614 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
615
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100616 if (k->def) {
617 k->def_uni = true;
618 k->def_multi = true;
619 }
620 if (k->defmgmt)
621 k->def_multi = true;
622
Johannes Bergb9454e82009-07-08 13:29:08 +0200623 if (tb[NL80211_KEY_IDX])
624 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
625
626 if (tb[NL80211_KEY_DATA]) {
627 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
628 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
629 }
630
631 if (tb[NL80211_KEY_SEQ]) {
632 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
633 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
634 }
635
636 if (tb[NL80211_KEY_CIPHER])
637 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
638
Johannes Berge31b8212010-10-05 19:39:30 +0200639 if (tb[NL80211_KEY_TYPE]) {
640 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
641 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
642 return -EINVAL;
643 }
644
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100645 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
646 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100647 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
648 tb[NL80211_KEY_DEFAULT_TYPES],
649 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100650 if (err)
651 return err;
652
653 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
654 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
655 }
656
Johannes Bergb9454e82009-07-08 13:29:08 +0200657 return 0;
658}
659
660static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
661{
662 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
663 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
664 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
665 }
666
667 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
668 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
669 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
670 }
671
672 if (info->attrs[NL80211_ATTR_KEY_IDX])
673 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
674
675 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
676 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
677
678 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
679 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
680
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100681 if (k->def) {
682 k->def_uni = true;
683 k->def_multi = true;
684 }
685 if (k->defmgmt)
686 k->def_multi = true;
687
Johannes Berge31b8212010-10-05 19:39:30 +0200688 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
689 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
690 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
691 return -EINVAL;
692 }
693
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100694 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
695 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
696 int err = nla_parse_nested(
697 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
698 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
699 nl80211_key_default_policy);
700 if (err)
701 return err;
702
703 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
704 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
705 }
706
Johannes Bergb9454e82009-07-08 13:29:08 +0200707 return 0;
708}
709
710static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
711{
712 int err;
713
714 memset(k, 0, sizeof(*k));
715 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200716 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200717
718 if (info->attrs[NL80211_ATTR_KEY])
719 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
720 else
721 err = nl80211_parse_key_old(info, k);
722
723 if (err)
724 return err;
725
726 if (k->def && k->defmgmt)
727 return -EINVAL;
728
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100729 if (k->defmgmt) {
730 if (k->def_uni || !k->def_multi)
731 return -EINVAL;
732 }
733
Johannes Bergb9454e82009-07-08 13:29:08 +0200734 if (k->idx != -1) {
735 if (k->defmgmt) {
736 if (k->idx < 4 || k->idx > 5)
737 return -EINVAL;
738 } else if (k->def) {
739 if (k->idx < 0 || k->idx > 3)
740 return -EINVAL;
741 } else {
742 if (k->idx < 0 || k->idx > 5)
743 return -EINVAL;
744 }
745 }
746
747 return 0;
748}
749
Johannes Bergfffd0932009-07-08 14:22:54 +0200750static struct cfg80211_cached_keys *
751nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530752 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200753{
754 struct key_parse parse;
755 struct nlattr *key;
756 struct cfg80211_cached_keys *result;
757 int rem, err, def = 0;
758
759 result = kzalloc(sizeof(*result), GFP_KERNEL);
760 if (!result)
761 return ERR_PTR(-ENOMEM);
762
763 result->def = -1;
764 result->defmgmt = -1;
765
766 nla_for_each_nested(key, keys, rem) {
767 memset(&parse, 0, sizeof(parse));
768 parse.idx = -1;
769
770 err = nl80211_parse_key_new(key, &parse);
771 if (err)
772 goto error;
773 err = -EINVAL;
774 if (!parse.p.key)
775 goto error;
776 if (parse.idx < 0 || parse.idx > 4)
777 goto error;
778 if (parse.def) {
779 if (def)
780 goto error;
781 def = 1;
782 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100783 if (!parse.def_uni || !parse.def_multi)
784 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200785 } else if (parse.defmgmt)
786 goto error;
787 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200788 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200789 if (err)
790 goto error;
791 result->params[parse.idx].cipher = parse.p.cipher;
792 result->params[parse.idx].key_len = parse.p.key_len;
793 result->params[parse.idx].key = result->data[parse.idx];
794 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530795
796 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
797 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
798 if (no_ht)
799 *no_ht = true;
800 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200801 }
802
803 return result;
804 error:
805 kfree(result);
806 return ERR_PTR(err);
807}
808
809static int nl80211_key_allowed(struct wireless_dev *wdev)
810{
811 ASSERT_WDEV_LOCK(wdev);
812
Johannes Bergfffd0932009-07-08 14:22:54 +0200813 switch (wdev->iftype) {
814 case NL80211_IFTYPE_AP:
815 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200816 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700817 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200818 break;
819 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200820 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200821 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200822 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200823 return -ENOLINK;
824 break;
825 default:
826 return -EINVAL;
827 }
828
829 return 0;
830}
831
Johannes Berg7527a782011-05-13 10:58:57 +0200832static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
833{
834 struct nlattr *nl_modes = nla_nest_start(msg, attr);
835 int i;
836
837 if (!nl_modes)
838 goto nla_put_failure;
839
840 i = 0;
841 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400842 if ((ifmodes & 1) && nla_put_flag(msg, i))
843 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200844 ifmodes >>= 1;
845 i++;
846 }
847
848 nla_nest_end(msg, nl_modes);
849 return 0;
850
851nla_put_failure:
852 return -ENOBUFS;
853}
854
855static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100856 struct sk_buff *msg,
857 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200858{
859 struct nlattr *nl_combis;
860 int i, j;
861
862 nl_combis = nla_nest_start(msg,
863 NL80211_ATTR_INTERFACE_COMBINATIONS);
864 if (!nl_combis)
865 goto nla_put_failure;
866
867 for (i = 0; i < wiphy->n_iface_combinations; i++) {
868 const struct ieee80211_iface_combination *c;
869 struct nlattr *nl_combi, *nl_limits;
870
871 c = &wiphy->iface_combinations[i];
872
873 nl_combi = nla_nest_start(msg, i + 1);
874 if (!nl_combi)
875 goto nla_put_failure;
876
877 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
878 if (!nl_limits)
879 goto nla_put_failure;
880
881 for (j = 0; j < c->n_limits; j++) {
882 struct nlattr *nl_limit;
883
884 nl_limit = nla_nest_start(msg, j + 1);
885 if (!nl_limit)
886 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400887 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
888 c->limits[j].max))
889 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200890 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
891 c->limits[j].types))
892 goto nla_put_failure;
893 nla_nest_end(msg, nl_limit);
894 }
895
896 nla_nest_end(msg, nl_limits);
897
David S. Miller9360ffd2012-03-29 04:41:26 -0400898 if (c->beacon_int_infra_match &&
899 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
900 goto nla_put_failure;
901 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
902 c->num_different_channels) ||
903 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
904 c->max_interfaces))
905 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100906 if (large &&
907 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
908 c->radar_detect_widths))
909 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200910
911 nla_nest_end(msg, nl_combi);
912 }
913
914 nla_nest_end(msg, nl_combis);
915
916 return 0;
917nla_put_failure:
918 return -ENOBUFS;
919}
920
Johannes Berg3713b4e2013-02-14 16:19:38 +0100921#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100922static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
923 struct sk_buff *msg)
924{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200925 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100926 struct nlattr *nl_tcp;
927
928 if (!tcp)
929 return 0;
930
931 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
932 if (!nl_tcp)
933 return -ENOBUFS;
934
935 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
936 tcp->data_payload_max))
937 return -ENOBUFS;
938
939 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
940 tcp->data_payload_max))
941 return -ENOBUFS;
942
943 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
944 return -ENOBUFS;
945
946 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
947 sizeof(*tcp->tok), tcp->tok))
948 return -ENOBUFS;
949
950 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
951 tcp->data_interval_max))
952 return -ENOBUFS;
953
954 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
955 tcp->wake_payload_max))
956 return -ENOBUFS;
957
958 nla_nest_end(msg, nl_tcp);
959 return 0;
960}
961
Johannes Berg3713b4e2013-02-14 16:19:38 +0100962static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100963 struct cfg80211_registered_device *dev,
964 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965{
966 struct nlattr *nl_wowlan;
967
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 return 0;
970
971 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
972 if (!nl_wowlan)
973 return -ENOBUFS;
974
Johannes Berg964dc9e2013-06-03 17:25:34 +0200975 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200977 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200979 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100980 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200981 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200983 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100984 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200985 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100986 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200987 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100988 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200989 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
991 return -ENOBUFS;
992
Johannes Berg964dc9e2013-06-03 17:25:34 +0200993 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700994 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200995 .max_patterns = dev->wiphy.wowlan->n_patterns,
996 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
997 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
998 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100999 };
1000
1001 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1002 sizeof(pat), &pat))
1003 return -ENOBUFS;
1004 }
1005
Johannes Bergb56cf722013-02-20 01:02:38 +01001006 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1007 return -ENOBUFS;
1008
Johannes Berg3713b4e2013-02-14 16:19:38 +01001009 nla_nest_end(msg, nl_wowlan);
1010
1011 return 0;
1012}
1013#endif
1014
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001015static int nl80211_send_coalesce(struct sk_buff *msg,
1016 struct cfg80211_registered_device *dev)
1017{
1018 struct nl80211_coalesce_rule_support rule;
1019
1020 if (!dev->wiphy.coalesce)
1021 return 0;
1022
1023 rule.max_rules = dev->wiphy.coalesce->n_rules;
1024 rule.max_delay = dev->wiphy.coalesce->max_delay;
1025 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1026 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1027 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1028 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1029
1030 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1031 return -ENOBUFS;
1032
1033 return 0;
1034}
1035
Johannes Berg3713b4e2013-02-14 16:19:38 +01001036static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1037 struct ieee80211_supported_band *sband)
1038{
1039 struct nlattr *nl_rates, *nl_rate;
1040 struct ieee80211_rate *rate;
1041 int i;
1042
1043 /* add HT info */
1044 if (sband->ht_cap.ht_supported &&
1045 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1046 sizeof(sband->ht_cap.mcs),
1047 &sband->ht_cap.mcs) ||
1048 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1049 sband->ht_cap.cap) ||
1050 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1051 sband->ht_cap.ampdu_factor) ||
1052 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1053 sband->ht_cap.ampdu_density)))
1054 return -ENOBUFS;
1055
1056 /* add VHT info */
1057 if (sband->vht_cap.vht_supported &&
1058 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1059 sizeof(sband->vht_cap.vht_mcs),
1060 &sband->vht_cap.vht_mcs) ||
1061 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1062 sband->vht_cap.cap)))
1063 return -ENOBUFS;
1064
1065 /* add bitrates */
1066 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1067 if (!nl_rates)
1068 return -ENOBUFS;
1069
1070 for (i = 0; i < sband->n_bitrates; i++) {
1071 nl_rate = nla_nest_start(msg, i);
1072 if (!nl_rate)
1073 return -ENOBUFS;
1074
1075 rate = &sband->bitrates[i];
1076 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1077 rate->bitrate))
1078 return -ENOBUFS;
1079 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1080 nla_put_flag(msg,
1081 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1082 return -ENOBUFS;
1083
1084 nla_nest_end(msg, nl_rate);
1085 }
1086
1087 nla_nest_end(msg, nl_rates);
1088
1089 return 0;
1090}
1091
1092static int
1093nl80211_send_mgmt_stypes(struct sk_buff *msg,
1094 const struct ieee80211_txrx_stypes *mgmt_stypes)
1095{
1096 u16 stypes;
1097 struct nlattr *nl_ftypes, *nl_ifs;
1098 enum nl80211_iftype ift;
1099 int i;
1100
1101 if (!mgmt_stypes)
1102 return 0;
1103
1104 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1105 if (!nl_ifs)
1106 return -ENOBUFS;
1107
1108 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1109 nl_ftypes = nla_nest_start(msg, ift);
1110 if (!nl_ftypes)
1111 return -ENOBUFS;
1112 i = 0;
1113 stypes = mgmt_stypes[ift].tx;
1114 while (stypes) {
1115 if ((stypes & 1) &&
1116 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1117 (i << 4) | IEEE80211_FTYPE_MGMT))
1118 return -ENOBUFS;
1119 stypes >>= 1;
1120 i++;
1121 }
1122 nla_nest_end(msg, nl_ftypes);
1123 }
1124
1125 nla_nest_end(msg, nl_ifs);
1126
1127 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1128 if (!nl_ifs)
1129 return -ENOBUFS;
1130
1131 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1132 nl_ftypes = nla_nest_start(msg, ift);
1133 if (!nl_ftypes)
1134 return -ENOBUFS;
1135 i = 0;
1136 stypes = mgmt_stypes[ift].rx;
1137 while (stypes) {
1138 if ((stypes & 1) &&
1139 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1140 (i << 4) | IEEE80211_FTYPE_MGMT))
1141 return -ENOBUFS;
1142 stypes >>= 1;
1143 i++;
1144 }
1145 nla_nest_end(msg, nl_ftypes);
1146 }
1147 nla_nest_end(msg, nl_ifs);
1148
1149 return 0;
1150}
1151
Johannes Berg86e8cf92013-06-19 10:57:22 +02001152struct nl80211_dump_wiphy_state {
1153 s64 filter_wiphy;
1154 long start;
1155 long split_start, band_start, chan_start;
1156 bool split;
1157};
1158
Johannes Berg3713b4e2013-02-14 16:19:38 +01001159static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1160 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001161 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001162{
1163 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001164 struct nlattr *nl_bands, *nl_band;
1165 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001166 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001167 enum ieee80211_band band;
1168 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001169 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001170 const struct ieee80211_txrx_stypes *mgmt_stypes =
1171 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001172 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001173
Eric W. Biederman15e47302012-09-07 20:12:54 +00001174 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001175 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 return -ENOBUFS;
1177
Johannes Berg86e8cf92013-06-19 10:57:22 +02001178 if (WARN_ON(!state))
1179 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001180
David S. Miller9360ffd2012-03-29 04:41:26 -04001181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001182 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1183 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001184 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001185 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001186 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001187
Johannes Berg86e8cf92013-06-19 10:57:22 +02001188 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001189 case 0:
1190 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1191 dev->wiphy.retry_short) ||
1192 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1193 dev->wiphy.retry_long) ||
1194 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1195 dev->wiphy.frag_threshold) ||
1196 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1197 dev->wiphy.rts_threshold) ||
1198 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1199 dev->wiphy.coverage_class) ||
1200 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1201 dev->wiphy.max_scan_ssids) ||
1202 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1203 dev->wiphy.max_sched_scan_ssids) ||
1204 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1205 dev->wiphy.max_scan_ie_len) ||
1206 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1207 dev->wiphy.max_sched_scan_ie_len) ||
1208 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1209 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001210 goto nla_put_failure;
1211
Johannes Berg3713b4e2013-02-14 16:19:38 +01001212 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1213 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1216 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1219 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1220 goto nla_put_failure;
1221 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1222 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1223 goto nla_put_failure;
1224 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1225 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1226 goto nla_put_failure;
1227 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1228 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001229 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001230 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1231 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1232 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001233
Johannes Berg86e8cf92013-06-19 10:57:22 +02001234 state->split_start++;
1235 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001236 break;
1237 case 1:
1238 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1239 sizeof(u32) * dev->wiphy.n_cipher_suites,
1240 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001241 goto nla_put_failure;
1242
Johannes Berg3713b4e2013-02-14 16:19:38 +01001243 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1244 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001245 goto nla_put_failure;
1246
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1248 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1249 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001250
Johannes Berg3713b4e2013-02-14 16:19:38 +01001251 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1252 dev->wiphy.available_antennas_tx) ||
1253 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1254 dev->wiphy.available_antennas_rx))
1255 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001256
Johannes Berg3713b4e2013-02-14 16:19:38 +01001257 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1258 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1259 dev->wiphy.probe_resp_offload))
1260 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001261
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 if ((dev->wiphy.available_antennas_tx ||
1263 dev->wiphy.available_antennas_rx) &&
1264 dev->ops->get_antenna) {
1265 u32 tx_ant = 0, rx_ant = 0;
1266 int res;
1267 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1268 if (!res) {
1269 if (nla_put_u32(msg,
1270 NL80211_ATTR_WIPHY_ANTENNA_TX,
1271 tx_ant) ||
1272 nla_put_u32(msg,
1273 NL80211_ATTR_WIPHY_ANTENNA_RX,
1274 rx_ant))
1275 goto nla_put_failure;
1276 }
Johannes Bergee688b002008-01-24 19:38:39 +01001277 }
1278
Johannes Berg86e8cf92013-06-19 10:57:22 +02001279 state->split_start++;
1280 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 break;
1282 case 2:
1283 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1284 dev->wiphy.interface_modes))
1285 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001286 state->split_start++;
1287 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 break;
1289 case 3:
1290 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1291 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001292 goto nla_put_failure;
1293
Johannes Berg86e8cf92013-06-19 10:57:22 +02001294 for (band = state->band_start;
1295 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 struct ieee80211_supported_band *sband;
1297
1298 sband = dev->wiphy.bands[band];
1299
1300 if (!sband)
1301 continue;
1302
1303 nl_band = nla_nest_start(msg, band);
1304 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001305 goto nla_put_failure;
1306
Johannes Berg86e8cf92013-06-19 10:57:22 +02001307 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 case 0:
1309 if (nl80211_send_band_rateinfo(msg, sband))
1310 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001311 state->chan_start++;
1312 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 break;
1314 default:
1315 /* add frequencies */
1316 nl_freqs = nla_nest_start(
1317 msg, NL80211_BAND_ATTR_FREQS);
1318 if (!nl_freqs)
1319 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001320
Johannes Berg86e8cf92013-06-19 10:57:22 +02001321 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 i < sband->n_channels;
1323 i++) {
1324 nl_freq = nla_nest_start(msg, i);
1325 if (!nl_freq)
1326 goto nla_put_failure;
1327
1328 chan = &sband->channels[i];
1329
Johannes Berg86e8cf92013-06-19 10:57:22 +02001330 if (nl80211_msg_put_channel(
1331 msg, chan,
1332 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 goto nla_put_failure;
1334
1335 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001336 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 break;
1338 }
1339 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001340 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001342 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 nla_nest_end(msg, nl_freqs);
1344 }
1345
1346 nla_nest_end(msg, nl_band);
1347
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001349 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001350 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 band--;
1352 break;
1353 }
Johannes Bergee688b002008-01-24 19:38:39 +01001354 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001356
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001360 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001361
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001363 if (state->band_start == 0 && state->chan_start == 0)
1364 state->split_start++;
1365 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 break;
1367 case 4:
1368 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1369 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001370 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371
1372 i = 0;
1373#define CMD(op, n) \
1374 do { \
1375 if (dev->ops->op) { \
1376 i++; \
1377 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1378 goto nla_put_failure; \
1379 } \
1380 } while (0)
1381
1382 CMD(add_virtual_intf, NEW_INTERFACE);
1383 CMD(change_virtual_intf, SET_INTERFACE);
1384 CMD(add_key, NEW_KEY);
1385 CMD(start_ap, START_AP);
1386 CMD(add_station, NEW_STATION);
1387 CMD(add_mpath, NEW_MPATH);
1388 CMD(update_mesh_config, SET_MESH_CONFIG);
1389 CMD(change_bss, SET_BSS);
1390 CMD(auth, AUTHENTICATE);
1391 CMD(assoc, ASSOCIATE);
1392 CMD(deauth, DEAUTHENTICATE);
1393 CMD(disassoc, DISASSOCIATE);
1394 CMD(join_ibss, JOIN_IBSS);
1395 CMD(join_mesh, JOIN_MESH);
1396 CMD(set_pmksa, SET_PMKSA);
1397 CMD(del_pmksa, DEL_PMKSA);
1398 CMD(flush_pmksa, FLUSH_PMKSA);
1399 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1400 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1401 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1402 CMD(mgmt_tx, FRAME);
1403 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1404 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1407 goto nla_put_failure;
1408 }
1409 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1410 dev->ops->join_mesh) {
1411 i++;
1412 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1413 goto nla_put_failure;
1414 }
1415 CMD(set_wds_peer, SET_WDS_PEER);
1416 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1417 CMD(tdls_mgmt, TDLS_MGMT);
1418 CMD(tdls_oper, TDLS_OPER);
1419 }
1420 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1421 CMD(sched_scan_start, START_SCHED_SCAN);
1422 CMD(probe_client, PROBE_CLIENT);
1423 CMD(set_noack_map, SET_NOACK_MAP);
1424 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1425 i++;
1426 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1427 goto nla_put_failure;
1428 }
1429 CMD(start_p2p_device, START_P2P_DEVICE);
1430 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001432 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1433 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001434 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1435 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001436 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001437
Kalle Valo4745fc02011-11-17 19:06:10 +02001438#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001440#endif
1441
Johannes Berg8fdc6212009-03-14 09:34:01 +01001442#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001443
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 if (dev->ops->connect || dev->ops->auth) {
1445 i++;
1446 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001447 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001448 }
1449
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 if (dev->ops->disconnect || dev->ops->deauth) {
1451 i++;
1452 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1453 goto nla_put_failure;
1454 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001455
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 state->split_start++;
1458 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 break;
1460 case 5:
1461 if (dev->ops->remain_on_channel &&
1462 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1463 nla_put_u32(msg,
1464 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1465 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001466 goto nla_put_failure;
1467
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1469 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1470 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001471
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1473 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001474 state->split_start++;
1475 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 break;
1477 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001478#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001479 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 state->split_start++;
1482 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 break;
1484#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486#endif
1487 case 7:
1488 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1489 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001490 goto nla_put_failure;
1491
Johannes Berg86e8cf92013-06-19 10:57:22 +02001492 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1493 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001495
Johannes Berg86e8cf92013-06-19 10:57:22 +02001496 state->split_start++;
1497 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 break;
1499 case 8:
1500 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1501 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1502 dev->wiphy.ap_sme_capa))
1503 goto nla_put_failure;
1504
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001505 features = dev->wiphy.features;
1506 /*
1507 * We can only add the per-channel limit information if the
1508 * dump is split, otherwise it makes it too big. Therefore
1509 * only advertise it in that case.
1510 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001511 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001512 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1513 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 goto nla_put_failure;
1515
1516 if (dev->wiphy.ht_capa_mod_mask &&
1517 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1518 sizeof(*dev->wiphy.ht_capa_mod_mask),
1519 dev->wiphy.ht_capa_mod_mask))
1520 goto nla_put_failure;
1521
1522 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1523 dev->wiphy.max_acl_mac_addrs &&
1524 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1525 dev->wiphy.max_acl_mac_addrs))
1526 goto nla_put_failure;
1527
1528 /*
1529 * Any information below this point is only available to
1530 * applications that can deal with it being split. This
1531 * helps ensure that newly added capabilities don't break
1532 * older tools by overrunning their buffers.
1533 *
1534 * We still increment split_start so that in the split
1535 * case we'll continue with more data in the next round,
1536 * but break unconditionally so unsplit data stops here.
1537 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001538 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 break;
1540 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001541 if (dev->wiphy.extended_capabilities &&
1542 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1543 dev->wiphy.extended_capabilities_len,
1544 dev->wiphy.extended_capabilities) ||
1545 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1546 dev->wiphy.extended_capabilities_len,
1547 dev->wiphy.extended_capabilities_mask)))
1548 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549
Johannes Bergee2aca32013-02-21 17:36:01 +01001550 if (dev->wiphy.vht_capa_mod_mask &&
1551 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1552 sizeof(*dev->wiphy.vht_capa_mod_mask),
1553 dev->wiphy.vht_capa_mod_mask))
1554 goto nla_put_failure;
1555
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001556 state->split_start++;
1557 break;
1558 case 10:
1559 if (nl80211_send_coalesce(msg, dev))
1560 goto nla_put_failure;
1561
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001565 }
Johannes Berg55682962007-09-20 13:09:35 -04001566 return genlmsg_end(msg, hdr);
1567
1568 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001569 genlmsg_cancel(msg, hdr);
1570 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001571}
1572
Johannes Berg86e8cf92013-06-19 10:57:22 +02001573static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1574 struct netlink_callback *cb,
1575 struct nl80211_dump_wiphy_state *state)
1576{
1577 struct nlattr **tb = nl80211_fam.attrbuf;
1578 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1579 tb, nl80211_fam.maxattr, nl80211_policy);
1580 /* ignore parse errors for backward compatibility */
1581 if (ret)
1582 return 0;
1583
1584 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1585 if (tb[NL80211_ATTR_WIPHY])
1586 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1587 if (tb[NL80211_ATTR_WDEV])
1588 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1589 if (tb[NL80211_ATTR_IFINDEX]) {
1590 struct net_device *netdev;
1591 struct cfg80211_registered_device *rdev;
1592 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1593
1594 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1595 if (!netdev)
1596 return -ENODEV;
1597 if (netdev->ieee80211_ptr) {
1598 rdev = wiphy_to_dev(
1599 netdev->ieee80211_ptr->wiphy);
1600 state->filter_wiphy = rdev->wiphy_idx;
1601 }
1602 dev_put(netdev);
1603 }
1604
1605 return 0;
1606}
1607
Johannes Berg55682962007-09-20 13:09:35 -04001608static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1609{
Johannes Berg645e77d2013-03-01 14:03:49 +01001610 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001611 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001612 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001613
Johannes Berg5fe231e2013-05-08 21:45:15 +02001614 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001615 if (!state) {
1616 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001617 if (!state) {
1618 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001619 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001621 state->filter_wiphy = -1;
1622 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1623 if (ret) {
1624 kfree(state);
1625 rtnl_unlock();
1626 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 }
1630
Johannes Berg79c97e92009-07-07 03:56:12 +02001631 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001632 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1633 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001635 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001636 if (state->filter_wiphy != -1 &&
1637 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638 continue;
1639 /* attempt to fit multiple wiphy data chunks into the skb */
1640 do {
1641 ret = nl80211_send_wiphy(dev, skb,
1642 NETLINK_CB(cb->skb).portid,
1643 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001644 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645 if (ret < 0) {
1646 /*
1647 * If sending the wiphy data didn't fit (ENOBUFS
1648 * or EMSGSIZE returned), this SKB is still
1649 * empty (so it's not too big because another
1650 * wiphy dataset is already in the skb) and
1651 * we've not tried to adjust the dump allocation
1652 * yet ... then adjust the alloc size to be
1653 * bigger, and return 1 but with the empty skb.
1654 * This results in an empty message being RX'ed
1655 * in userspace, but that is ignored.
1656 *
1657 * We can then retry with the larger buffer.
1658 */
1659 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1660 !skb->len &&
1661 cb->min_dump_alloc < 4096) {
1662 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001663 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001664 return 1;
1665 }
1666 idx--;
1667 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001668 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001669 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001670 break;
Johannes Berg55682962007-09-20 13:09:35 -04001671 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001672 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001673
Johannes Berg86e8cf92013-06-19 10:57:22 +02001674 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001675
1676 return skb->len;
1677}
1678
Johannes Berg86e8cf92013-06-19 10:57:22 +02001679static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1680{
1681 kfree((void *)cb->args[0]);
1682 return 0;
1683}
1684
Johannes Berg55682962007-09-20 13:09:35 -04001685static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1686{
1687 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001688 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001689 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001690
Johannes Berg645e77d2013-03-01 14:03:49 +01001691 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001692 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001693 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001694
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001696 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001697 nlmsg_free(msg);
1698 return -ENOBUFS;
1699 }
Johannes Berg55682962007-09-20 13:09:35 -04001700
Johannes Berg134e6372009-07-10 09:51:34 +00001701 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001702}
1703
Jouni Malinen31888482008-10-30 16:59:24 +02001704static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1705 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1706 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1707 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1708 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1709 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1710};
1711
1712static int parse_txq_params(struct nlattr *tb[],
1713 struct ieee80211_txq_params *txq_params)
1714{
Johannes Berga3304b02012-03-28 11:04:24 +02001715 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001716 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1717 !tb[NL80211_TXQ_ATTR_AIFS])
1718 return -EINVAL;
1719
Johannes Berga3304b02012-03-28 11:04:24 +02001720 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001721 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1722 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1723 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1724 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1725
Johannes Berga3304b02012-03-28 11:04:24 +02001726 if (txq_params->ac >= NL80211_NUM_ACS)
1727 return -EINVAL;
1728
Jouni Malinen31888482008-10-30 16:59:24 +02001729 return 0;
1730}
1731
Johannes Bergf444de02010-05-05 15:25:02 +02001732static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1733{
1734 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001735 * You can only set the channel explicitly for WDS interfaces,
1736 * all others have their channel managed via their respective
1737 * "establish a connection" command (connect, join, ...)
1738 *
1739 * For AP/GO and mesh mode, the channel can be set with the
1740 * channel userspace API, but is only stored and passed to the
1741 * low-level driver when the AP starts or the mesh is joined.
1742 * This is for backward compatibility, userspace can also give
1743 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001744 *
1745 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001746 * whatever else is going on, so they have their own special
1747 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001748 */
1749 return !wdev ||
1750 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001751 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001752 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1753 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001754}
1755
Johannes Berg683b6d32012-11-08 21:25:48 +01001756static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1757 struct genl_info *info,
1758 struct cfg80211_chan_def *chandef)
1759{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301760 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001761
1762 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1763 return -EINVAL;
1764
1765 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1766
1767 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001768 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1769 chandef->center_freq1 = control_freq;
1770 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001771
1772 /* Primary channel not allowed */
1773 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1774 return -EINVAL;
1775
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001776 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1777 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001778
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001779 chantype = nla_get_u32(
1780 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1781
1782 switch (chantype) {
1783 case NL80211_CHAN_NO_HT:
1784 case NL80211_CHAN_HT20:
1785 case NL80211_CHAN_HT40PLUS:
1786 case NL80211_CHAN_HT40MINUS:
1787 cfg80211_chandef_create(chandef, chandef->chan,
1788 chantype);
1789 break;
1790 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001791 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001792 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001793 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1794 chandef->width =
1795 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1796 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1797 chandef->center_freq1 =
1798 nla_get_u32(
1799 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1800 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1801 chandef->center_freq2 =
1802 nla_get_u32(
1803 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1804 }
1805
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001806 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001807 return -EINVAL;
1808
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001809 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1810 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001811 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001812
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001813 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1814 chandef->width == NL80211_CHAN_WIDTH_10) &&
1815 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1816 return -EINVAL;
1817
Johannes Berg683b6d32012-11-08 21:25:48 +01001818 return 0;
1819}
1820
Johannes Bergf444de02010-05-05 15:25:02 +02001821static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1822 struct wireless_dev *wdev,
1823 struct genl_info *info)
1824{
Johannes Berg683b6d32012-11-08 21:25:48 +01001825 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001826 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001827 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1828
1829 if (wdev)
1830 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001831
Johannes Bergf444de02010-05-05 15:25:02 +02001832 if (!nl80211_can_set_dev_channel(wdev))
1833 return -EOPNOTSUPP;
1834
Johannes Berg683b6d32012-11-08 21:25:48 +01001835 result = nl80211_parse_chandef(rdev, info, &chandef);
1836 if (result)
1837 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001838
Johannes Berge8c9bd52012-06-06 08:18:22 +02001839 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001840 case NL80211_IFTYPE_AP:
1841 case NL80211_IFTYPE_P2P_GO:
1842 if (wdev->beacon_interval) {
1843 result = -EBUSY;
1844 break;
1845 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001846 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001847 result = -EINVAL;
1848 break;
1849 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001850 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001851 result = 0;
1852 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001853 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001854 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001855 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001856 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001857 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001858 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001859 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001860 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001861 }
Johannes Bergf444de02010-05-05 15:25:02 +02001862
1863 return result;
1864}
1865
1866static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1867{
Johannes Berg4c476992010-10-04 21:36:35 +02001868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1869 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001870
Johannes Berg4c476992010-10-04 21:36:35 +02001871 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001872}
1873
Bill Jordane8347eb2010-10-01 13:54:28 -04001874static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1875{
Johannes Berg43b19952010-10-07 13:10:30 +02001876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1877 struct net_device *dev = info->user_ptr[1];
1878 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001879 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001880
1881 if (!info->attrs[NL80211_ATTR_MAC])
1882 return -EINVAL;
1883
Johannes Berg43b19952010-10-07 13:10:30 +02001884 if (netif_running(dev))
1885 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001886
Johannes Berg43b19952010-10-07 13:10:30 +02001887 if (!rdev->ops->set_wds_peer)
1888 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001889
Johannes Berg43b19952010-10-07 13:10:30 +02001890 if (wdev->iftype != NL80211_IFTYPE_WDS)
1891 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001892
1893 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001894 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001895}
1896
1897
Johannes Berg55682962007-09-20 13:09:35 -04001898static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1899{
1900 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001901 struct net_device *netdev = NULL;
1902 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001903 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001904 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001905 u32 changed;
1906 u8 retry_short = 0, retry_long = 0;
1907 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001908 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001909
Johannes Berg5fe231e2013-05-08 21:45:15 +02001910 ASSERT_RTNL();
1911
Johannes Bergf444de02010-05-05 15:25:02 +02001912 /*
1913 * Try to find the wiphy and netdev. Normally this
1914 * function shouldn't need the netdev, but this is
1915 * done for backward compatibility -- previously
1916 * setting the channel was done per wiphy, but now
1917 * it is per netdev. Previous userland like hostapd
1918 * also passed a netdev to set_wiphy, so that it is
1919 * possible to let that go to the right netdev!
1920 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001921
Johannes Bergf444de02010-05-05 15:25:02 +02001922 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1923 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1924
1925 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001926 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001927 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001928 else
Johannes Bergf444de02010-05-05 15:25:02 +02001929 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001930 }
1931
Johannes Bergf444de02010-05-05 15:25:02 +02001932 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001933 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1934 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001935 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001936 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001937 wdev = NULL;
1938 netdev = NULL;
1939 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001940 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001941 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001942
1943 /*
1944 * end workaround code, by now the rdev is available
1945 * and locked, and wdev may or may not be NULL.
1946 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001947
1948 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001949 result = cfg80211_dev_rename(
1950 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001951
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001952 if (result)
1953 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001954
Jouni Malinen31888482008-10-30 16:59:24 +02001955 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1956 struct ieee80211_txq_params txq_params;
1957 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1958
1959 if (!rdev->ops->set_txq_params) {
1960 result = -EOPNOTSUPP;
1961 goto bad_res;
1962 }
1963
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001964 if (!netdev) {
1965 result = -EINVAL;
1966 goto bad_res;
1967 }
1968
Johannes Berg133a3ff2011-11-03 14:50:13 +01001969 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1970 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1971 result = -EINVAL;
1972 goto bad_res;
1973 }
1974
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001975 if (!netif_running(netdev)) {
1976 result = -ENETDOWN;
1977 goto bad_res;
1978 }
1979
Jouni Malinen31888482008-10-30 16:59:24 +02001980 nla_for_each_nested(nl_txq_params,
1981 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1982 rem_txq_params) {
1983 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1984 nla_data(nl_txq_params),
1985 nla_len(nl_txq_params),
1986 txq_params_policy);
1987 result = parse_txq_params(tb, &txq_params);
1988 if (result)
1989 goto bad_res;
1990
Hila Gonene35e4d22012-06-27 17:19:42 +03001991 result = rdev_set_txq_params(rdev, netdev,
1992 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001993 if (result)
1994 goto bad_res;
1995 }
1996 }
1997
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001998 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001999 result = __nl80211_set_channel(rdev,
2000 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2001 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002002 if (result)
2003 goto bad_res;
2004 }
2005
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002006 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002007 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002008 enum nl80211_tx_power_setting type;
2009 int idx, mbm = 0;
2010
Johannes Bergc8442112012-10-24 10:17:18 +02002011 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2012 txp_wdev = NULL;
2013
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002014 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002015 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002016 goto bad_res;
2017 }
2018
2019 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2020 type = nla_get_u32(info->attrs[idx]);
2021
2022 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2023 (type != NL80211_TX_POWER_AUTOMATIC)) {
2024 result = -EINVAL;
2025 goto bad_res;
2026 }
2027
2028 if (type != NL80211_TX_POWER_AUTOMATIC) {
2029 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2030 mbm = nla_get_u32(info->attrs[idx]);
2031 }
2032
Johannes Bergc8442112012-10-24 10:17:18 +02002033 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002034 if (result)
2035 goto bad_res;
2036 }
2037
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002038 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2039 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2040 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002041 if ((!rdev->wiphy.available_antennas_tx &&
2042 !rdev->wiphy.available_antennas_rx) ||
2043 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002044 result = -EOPNOTSUPP;
2045 goto bad_res;
2046 }
2047
2048 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2049 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2050
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002051 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002052 * available antenna masks, except for the "all" mask */
2053 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2054 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002055 result = -EINVAL;
2056 goto bad_res;
2057 }
2058
Bruno Randolf7f531e02010-12-16 11:30:22 +09002059 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2060 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002061
Hila Gonene35e4d22012-06-27 17:19:42 +03002062 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002063 if (result)
2064 goto bad_res;
2065 }
2066
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002067 changed = 0;
2068
2069 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2070 retry_short = nla_get_u8(
2071 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2072 if (retry_short == 0) {
2073 result = -EINVAL;
2074 goto bad_res;
2075 }
2076 changed |= WIPHY_PARAM_RETRY_SHORT;
2077 }
2078
2079 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2080 retry_long = nla_get_u8(
2081 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2082 if (retry_long == 0) {
2083 result = -EINVAL;
2084 goto bad_res;
2085 }
2086 changed |= WIPHY_PARAM_RETRY_LONG;
2087 }
2088
2089 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2090 frag_threshold = nla_get_u32(
2091 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2092 if (frag_threshold < 256) {
2093 result = -EINVAL;
2094 goto bad_res;
2095 }
2096 if (frag_threshold != (u32) -1) {
2097 /*
2098 * Fragments (apart from the last one) are required to
2099 * have even length. Make the fragmentation code
2100 * simpler by stripping LSB should someone try to use
2101 * odd threshold value.
2102 */
2103 frag_threshold &= ~0x1;
2104 }
2105 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2106 }
2107
2108 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2109 rts_threshold = nla_get_u32(
2110 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2111 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2112 }
2113
Lukáš Turek81077e82009-12-21 22:50:47 +01002114 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2115 coverage_class = nla_get_u8(
2116 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2117 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2118 }
2119
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002120 if (changed) {
2121 u8 old_retry_short, old_retry_long;
2122 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002123 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002124
2125 if (!rdev->ops->set_wiphy_params) {
2126 result = -EOPNOTSUPP;
2127 goto bad_res;
2128 }
2129
2130 old_retry_short = rdev->wiphy.retry_short;
2131 old_retry_long = rdev->wiphy.retry_long;
2132 old_frag_threshold = rdev->wiphy.frag_threshold;
2133 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002134 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002135
2136 if (changed & WIPHY_PARAM_RETRY_SHORT)
2137 rdev->wiphy.retry_short = retry_short;
2138 if (changed & WIPHY_PARAM_RETRY_LONG)
2139 rdev->wiphy.retry_long = retry_long;
2140 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2141 rdev->wiphy.frag_threshold = frag_threshold;
2142 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2143 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002144 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2145 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002146
Hila Gonene35e4d22012-06-27 17:19:42 +03002147 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002148 if (result) {
2149 rdev->wiphy.retry_short = old_retry_short;
2150 rdev->wiphy.retry_long = old_retry_long;
2151 rdev->wiphy.frag_threshold = old_frag_threshold;
2152 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002153 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002154 }
2155 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002156
Johannes Berg306d6112008-12-08 12:39:04 +01002157 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002158 if (netdev)
2159 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002160 return result;
2161}
2162
Johannes Berg71bbc992012-06-15 15:30:18 +02002163static inline u64 wdev_id(struct wireless_dev *wdev)
2164{
2165 return (u64)wdev->identifier |
2166 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2167}
Johannes Berg55682962007-09-20 13:09:35 -04002168
Johannes Berg683b6d32012-11-08 21:25:48 +01002169static int nl80211_send_chandef(struct sk_buff *msg,
2170 struct cfg80211_chan_def *chandef)
2171{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002172 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002173
Johannes Berg683b6d32012-11-08 21:25:48 +01002174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2175 chandef->chan->center_freq))
2176 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002177 switch (chandef->width) {
2178 case NL80211_CHAN_WIDTH_20_NOHT:
2179 case NL80211_CHAN_WIDTH_20:
2180 case NL80211_CHAN_WIDTH_40:
2181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2182 cfg80211_get_chandef_type(chandef)))
2183 return -ENOBUFS;
2184 break;
2185 default:
2186 break;
2187 }
2188 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2189 return -ENOBUFS;
2190 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2191 return -ENOBUFS;
2192 if (chandef->center_freq2 &&
2193 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002194 return -ENOBUFS;
2195 return 0;
2196}
2197
Eric W. Biederman15e47302012-09-07 20:12:54 +00002198static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002199 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002200 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002201{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002202 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002203 void *hdr;
2204
Eric W. Biederman15e47302012-09-07 20:12:54 +00002205 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002206 if (!hdr)
2207 return -1;
2208
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002209 if (dev &&
2210 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002211 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002212 goto nla_put_failure;
2213
2214 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2215 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002216 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002217 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002218 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2219 rdev->devlist_generation ^
2220 (cfg80211_rdev_list_generation << 2)))
2221 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002222
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002223 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002224 int ret;
2225 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002226
Johannes Berg683b6d32012-11-08 21:25:48 +01002227 ret = rdev_get_channel(rdev, wdev, &chandef);
2228 if (ret == 0) {
2229 if (nl80211_send_chandef(msg, &chandef))
2230 goto nla_put_failure;
2231 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002232 }
2233
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002234 if (wdev->ssid_len) {
2235 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2236 goto nla_put_failure;
2237 }
2238
Johannes Berg55682962007-09-20 13:09:35 -04002239 return genlmsg_end(msg, hdr);
2240
2241 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002242 genlmsg_cancel(msg, hdr);
2243 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002244}
2245
2246static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2247{
2248 int wp_idx = 0;
2249 int if_idx = 0;
2250 int wp_start = cb->args[0];
2251 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002252 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002253 struct wireless_dev *wdev;
2254
Johannes Berg5fe231e2013-05-08 21:45:15 +02002255 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002256 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2257 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002258 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002259 if (wp_idx < wp_start) {
2260 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002261 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 }
Johannes Berg55682962007-09-20 13:09:35 -04002263 if_idx = 0;
2264
Johannes Berg89a54e42012-06-15 14:33:17 +02002265 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002266 if (if_idx < if_start) {
2267 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002268 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002270 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002271 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002272 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002273 goto out;
2274 }
2275 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002276 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002277
2278 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002279 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002280 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002281 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002282
2283 cb->args[0] = wp_idx;
2284 cb->args[1] = if_idx;
2285
2286 return skb->len;
2287}
2288
2289static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2290{
2291 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002292 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002293 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002294
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002296 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002297 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002298
Eric W. Biederman15e47302012-09-07 20:12:54 +00002299 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002300 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002301 nlmsg_free(msg);
2302 return -ENOBUFS;
2303 }
Johannes Berg55682962007-09-20 13:09:35 -04002304
Johannes Berg134e6372009-07-10 09:51:34 +00002305 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002306}
2307
Michael Wu66f7ac52008-01-31 19:48:22 +01002308static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2309 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2310 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2311 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2312 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2313 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002314 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002315};
2316
2317static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2318{
2319 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2320 int flag;
2321
2322 *mntrflags = 0;
2323
2324 if (!nla)
2325 return -EINVAL;
2326
2327 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2328 nla, mntr_flags_policy))
2329 return -EINVAL;
2330
2331 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2332 if (flags[flag])
2333 *mntrflags |= (1<<flag);
2334
2335 return 0;
2336}
2337
Johannes Berg9bc383d2009-11-19 11:55:19 +01002338static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002339 struct net_device *netdev, u8 use_4addr,
2340 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002341{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002342 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002343 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002344 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002345 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002346 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002347
2348 switch (iftype) {
2349 case NL80211_IFTYPE_AP_VLAN:
2350 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2351 return 0;
2352 break;
2353 case NL80211_IFTYPE_STATION:
2354 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2355 return 0;
2356 break;
2357 default:
2358 break;
2359 }
2360
2361 return -EOPNOTSUPP;
2362}
2363
Johannes Berg55682962007-09-20 13:09:35 -04002364static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2365{
Johannes Berg4c476992010-10-04 21:36:35 +02002366 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002367 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002368 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002369 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002370 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002371 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002372 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002373
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002374 memset(&params, 0, sizeof(params));
2375
Johannes Berg04a773a2009-04-19 21:24:32 +02002376 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002377
Johannes Berg723b0382008-09-16 20:22:09 +02002378 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002379 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002380 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002381 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002382 if (ntype > NL80211_IFTYPE_MAX)
2383 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002384 }
2385
Johannes Berg92ffe052008-09-16 20:39:36 +02002386 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002387 struct wireless_dev *wdev = dev->ieee80211_ptr;
2388
Johannes Berg4c476992010-10-04 21:36:35 +02002389 if (ntype != NL80211_IFTYPE_MESH_POINT)
2390 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002391 if (netif_running(dev))
2392 return -EBUSY;
2393
2394 wdev_lock(wdev);
2395 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2396 IEEE80211_MAX_MESH_ID_LEN);
2397 wdev->mesh_id_up_len =
2398 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2399 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2400 wdev->mesh_id_up_len);
2401 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002402 }
2403
Felix Fietkau8b787642009-11-10 18:53:10 +01002404 if (info->attrs[NL80211_ATTR_4ADDR]) {
2405 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2406 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002407 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002408 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002409 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002410 } else {
2411 params.use_4addr = -1;
2412 }
2413
Johannes Berg92ffe052008-09-16 20:39:36 +02002414 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002415 if (ntype != NL80211_IFTYPE_MONITOR)
2416 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002417 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2418 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002419 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002420 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002421
2422 flags = &_flags;
2423 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002424 }
Johannes Berg3b858752009-03-12 09:55:09 +01002425
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002426 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2427 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2428 return -EOPNOTSUPP;
2429
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002430 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002431 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002432 else
2433 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002434
Johannes Berg9bc383d2009-11-19 11:55:19 +01002435 if (!err && params.use_4addr != -1)
2436 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2437
Johannes Berg55682962007-09-20 13:09:35 -04002438 return err;
2439}
2440
2441static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2442{
Johannes Berg4c476992010-10-04 21:36:35 +02002443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002444 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002445 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002446 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002447 int err;
2448 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002449 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002450
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002451 memset(&params, 0, sizeof(params));
2452
Johannes Berg55682962007-09-20 13:09:35 -04002453 if (!info->attrs[NL80211_ATTR_IFNAME])
2454 return -EINVAL;
2455
2456 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2457 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2458 if (type > NL80211_IFTYPE_MAX)
2459 return -EINVAL;
2460 }
2461
Johannes Berg79c97e92009-07-07 03:56:12 +02002462 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002463 !(rdev->wiphy.interface_modes & (1 << type)))
2464 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002465
Arend van Spriel1c18f142013-01-08 10:17:27 +01002466 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2467 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2468 ETH_ALEN);
2469 if (!is_valid_ether_addr(params.macaddr))
2470 return -EADDRNOTAVAIL;
2471 }
2472
Johannes Berg9bc383d2009-11-19 11:55:19 +01002473 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002474 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002475 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002476 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002477 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002478 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002479
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002480 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2481 if (!msg)
2482 return -ENOMEM;
2483
Michael Wu66f7ac52008-01-31 19:48:22 +01002484 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2485 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2486 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002487
2488 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2489 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2490 return -EOPNOTSUPP;
2491
Hila Gonene35e4d22012-06-27 17:19:42 +03002492 wdev = rdev_add_virtual_intf(rdev,
2493 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2494 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002495 if (IS_ERR(wdev)) {
2496 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002497 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002498 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002499
Johannes Berg98104fde2012-06-16 00:19:54 +02002500 switch (type) {
2501 case NL80211_IFTYPE_MESH_POINT:
2502 if (!info->attrs[NL80211_ATTR_MESH_ID])
2503 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002504 wdev_lock(wdev);
2505 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2506 IEEE80211_MAX_MESH_ID_LEN);
2507 wdev->mesh_id_up_len =
2508 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2509 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2510 wdev->mesh_id_up_len);
2511 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002512 break;
2513 case NL80211_IFTYPE_P2P_DEVICE:
2514 /*
2515 * P2P Device doesn't have a netdev, so doesn't go
2516 * through the netdev notifier and must be added here
2517 */
2518 mutex_init(&wdev->mtx);
2519 INIT_LIST_HEAD(&wdev->event_list);
2520 spin_lock_init(&wdev->event_lock);
2521 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2522 spin_lock_init(&wdev->mgmt_registrations_lock);
2523
Johannes Berg98104fde2012-06-16 00:19:54 +02002524 wdev->identifier = ++rdev->wdev_id;
2525 list_add_rcu(&wdev->list, &rdev->wdev_list);
2526 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002527 break;
2528 default:
2529 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002530 }
2531
Eric W. Biederman15e47302012-09-07 20:12:54 +00002532 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002533 rdev, wdev) < 0) {
2534 nlmsg_free(msg);
2535 return -ENOBUFS;
2536 }
2537
2538 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002539}
2540
2541static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2542{
Johannes Berg4c476992010-10-04 21:36:35 +02002543 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002544 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002545
Johannes Berg4c476992010-10-04 21:36:35 +02002546 if (!rdev->ops->del_virtual_intf)
2547 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002548
Johannes Berg84efbb82012-06-16 00:00:26 +02002549 /*
2550 * If we remove a wireless device without a netdev then clear
2551 * user_ptr[1] so that nl80211_post_doit won't dereference it
2552 * to check if it needs to do dev_put(). Otherwise it crashes
2553 * since the wdev has been freed, unlike with a netdev where
2554 * we need the dev_put() for the netdev to really be freed.
2555 */
2556 if (!wdev->netdev)
2557 info->user_ptr[1] = NULL;
2558
Hila Gonene35e4d22012-06-27 17:19:42 +03002559 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002560}
2561
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002562static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2563{
2564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2565 struct net_device *dev = info->user_ptr[1];
2566 u16 noack_map;
2567
2568 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2569 return -EINVAL;
2570
2571 if (!rdev->ops->set_noack_map)
2572 return -EOPNOTSUPP;
2573
2574 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2575
Hila Gonene35e4d22012-06-27 17:19:42 +03002576 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002577}
2578
Johannes Berg41ade002007-12-19 02:03:29 +01002579struct get_key_cookie {
2580 struct sk_buff *msg;
2581 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002582 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002583};
2584
2585static void get_key_callback(void *c, struct key_params *params)
2586{
Johannes Bergb9454e82009-07-08 13:29:08 +02002587 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002588 struct get_key_cookie *cookie = c;
2589
David S. Miller9360ffd2012-03-29 04:41:26 -04002590 if ((params->key &&
2591 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2592 params->key_len, params->key)) ||
2593 (params->seq &&
2594 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2595 params->seq_len, params->seq)) ||
2596 (params->cipher &&
2597 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2598 params->cipher)))
2599 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002600
Johannes Bergb9454e82009-07-08 13:29:08 +02002601 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2602 if (!key)
2603 goto nla_put_failure;
2604
David S. Miller9360ffd2012-03-29 04:41:26 -04002605 if ((params->key &&
2606 nla_put(cookie->msg, NL80211_KEY_DATA,
2607 params->key_len, params->key)) ||
2608 (params->seq &&
2609 nla_put(cookie->msg, NL80211_KEY_SEQ,
2610 params->seq_len, params->seq)) ||
2611 (params->cipher &&
2612 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2613 params->cipher)))
2614 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002615
David S. Miller9360ffd2012-03-29 04:41:26 -04002616 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2617 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002618
2619 nla_nest_end(cookie->msg, key);
2620
Johannes Berg41ade002007-12-19 02:03:29 +01002621 return;
2622 nla_put_failure:
2623 cookie->error = 1;
2624}
2625
2626static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2627{
Johannes Berg4c476992010-10-04 21:36:35 +02002628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002629 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002630 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002631 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002632 const u8 *mac_addr = NULL;
2633 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002634 struct get_key_cookie cookie = {
2635 .error = 0,
2636 };
2637 void *hdr;
2638 struct sk_buff *msg;
2639
2640 if (info->attrs[NL80211_ATTR_KEY_IDX])
2641 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2642
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002643 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002644 return -EINVAL;
2645
2646 if (info->attrs[NL80211_ATTR_MAC])
2647 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2648
Johannes Berge31b8212010-10-05 19:39:30 +02002649 pairwise = !!mac_addr;
2650 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2651 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2652 if (kt >= NUM_NL80211_KEYTYPES)
2653 return -EINVAL;
2654 if (kt != NL80211_KEYTYPE_GROUP &&
2655 kt != NL80211_KEYTYPE_PAIRWISE)
2656 return -EINVAL;
2657 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2658 }
2659
Johannes Berg4c476992010-10-04 21:36:35 +02002660 if (!rdev->ops->get_key)
2661 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002662
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002663 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002664 if (!msg)
2665 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002666
Eric W. Biederman15e47302012-09-07 20:12:54 +00002667 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002668 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002669 if (!hdr)
2670 return -ENOBUFS;
Johannes Berg41ade002007-12-19 02:03:29 +01002671
2672 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002673 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002674
David S. Miller9360ffd2012-03-29 04:41:26 -04002675 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2676 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2677 goto nla_put_failure;
2678 if (mac_addr &&
2679 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2680 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002681
Johannes Berge31b8212010-10-05 19:39:30 +02002682 if (pairwise && mac_addr &&
2683 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2684 return -ENOENT;
2685
Hila Gonene35e4d22012-06-27 17:19:42 +03002686 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2687 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002688
2689 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002690 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002691
2692 if (cookie.error)
2693 goto nla_put_failure;
2694
2695 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002696 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002697
2698 nla_put_failure:
2699 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002700 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002701 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002702 return err;
2703}
2704
2705static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2706{
Johannes Berg4c476992010-10-04 21:36:35 +02002707 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002708 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002709 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002710 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002711
Johannes Bergb9454e82009-07-08 13:29:08 +02002712 err = nl80211_parse_key(info, &key);
2713 if (err)
2714 return err;
2715
2716 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002717 return -EINVAL;
2718
Johannes Bergb9454e82009-07-08 13:29:08 +02002719 /* only support setting default key */
2720 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002721 return -EINVAL;
2722
Johannes Bergfffd0932009-07-08 14:22:54 +02002723 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002724
2725 if (key.def) {
2726 if (!rdev->ops->set_default_key) {
2727 err = -EOPNOTSUPP;
2728 goto out;
2729 }
2730
2731 err = nl80211_key_allowed(dev->ieee80211_ptr);
2732 if (err)
2733 goto out;
2734
Hila Gonene35e4d22012-06-27 17:19:42 +03002735 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002736 key.def_uni, key.def_multi);
2737
2738 if (err)
2739 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002740
Johannes Berg3d23e342009-09-29 23:27:28 +02002741#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002742 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002743#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002744 } else {
2745 if (key.def_uni || !key.def_multi) {
2746 err = -EINVAL;
2747 goto out;
2748 }
2749
2750 if (!rdev->ops->set_default_mgmt_key) {
2751 err = -EOPNOTSUPP;
2752 goto out;
2753 }
2754
2755 err = nl80211_key_allowed(dev->ieee80211_ptr);
2756 if (err)
2757 goto out;
2758
Hila Gonene35e4d22012-06-27 17:19:42 +03002759 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002760 if (err)
2761 goto out;
2762
2763#ifdef CONFIG_CFG80211_WEXT
2764 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2765#endif
2766 }
2767
2768 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002769 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Johannes Berg41ade002007-12-19 02:03:29 +01002771 return err;
2772}
2773
2774static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2775{
Johannes Berg4c476992010-10-04 21:36:35 +02002776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002777 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002778 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002779 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002780 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002781
Johannes Bergb9454e82009-07-08 13:29:08 +02002782 err = nl80211_parse_key(info, &key);
2783 if (err)
2784 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002785
Johannes Bergb9454e82009-07-08 13:29:08 +02002786 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002787 return -EINVAL;
2788
Johannes Berg41ade002007-12-19 02:03:29 +01002789 if (info->attrs[NL80211_ATTR_MAC])
2790 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2791
Johannes Berge31b8212010-10-05 19:39:30 +02002792 if (key.type == -1) {
2793 if (mac_addr)
2794 key.type = NL80211_KEYTYPE_PAIRWISE;
2795 else
2796 key.type = NL80211_KEYTYPE_GROUP;
2797 }
2798
2799 /* for now */
2800 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2801 key.type != NL80211_KEYTYPE_GROUP)
2802 return -EINVAL;
2803
Johannes Berg4c476992010-10-04 21:36:35 +02002804 if (!rdev->ops->add_key)
2805 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002806
Johannes Berge31b8212010-10-05 19:39:30 +02002807 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2808 key.type == NL80211_KEYTYPE_PAIRWISE,
2809 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002810 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002811
2812 wdev_lock(dev->ieee80211_ptr);
2813 err = nl80211_key_allowed(dev->ieee80211_ptr);
2814 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002815 err = rdev_add_key(rdev, dev, key.idx,
2816 key.type == NL80211_KEYTYPE_PAIRWISE,
2817 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002818 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002819
Johannes Berg41ade002007-12-19 02:03:29 +01002820 return err;
2821}
2822
2823static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2824{
Johannes Berg4c476992010-10-04 21:36:35 +02002825 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002826 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002827 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002828 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002829 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002830
Johannes Bergb9454e82009-07-08 13:29:08 +02002831 err = nl80211_parse_key(info, &key);
2832 if (err)
2833 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002834
2835 if (info->attrs[NL80211_ATTR_MAC])
2836 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2837
Johannes Berge31b8212010-10-05 19:39:30 +02002838 if (key.type == -1) {
2839 if (mac_addr)
2840 key.type = NL80211_KEYTYPE_PAIRWISE;
2841 else
2842 key.type = NL80211_KEYTYPE_GROUP;
2843 }
2844
2845 /* for now */
2846 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2847 key.type != NL80211_KEYTYPE_GROUP)
2848 return -EINVAL;
2849
Johannes Berg4c476992010-10-04 21:36:35 +02002850 if (!rdev->ops->del_key)
2851 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002852
Johannes Bergfffd0932009-07-08 14:22:54 +02002853 wdev_lock(dev->ieee80211_ptr);
2854 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002855
2856 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2857 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2858 err = -ENOENT;
2859
Johannes Bergfffd0932009-07-08 14:22:54 +02002860 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002861 err = rdev_del_key(rdev, dev, key.idx,
2862 key.type == NL80211_KEYTYPE_PAIRWISE,
2863 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002864
Johannes Berg3d23e342009-09-29 23:27:28 +02002865#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002866 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002867 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002868 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002869 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002870 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2871 }
2872#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002873 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002874
Johannes Berg41ade002007-12-19 02:03:29 +01002875 return err;
2876}
2877
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302878/* This function returns an error or the number of nested attributes */
2879static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2880{
2881 struct nlattr *attr;
2882 int n_entries = 0, tmp;
2883
2884 nla_for_each_nested(attr, nl_attr, tmp) {
2885 if (nla_len(attr) != ETH_ALEN)
2886 return -EINVAL;
2887
2888 n_entries++;
2889 }
2890
2891 return n_entries;
2892}
2893
2894/*
2895 * This function parses ACL information and allocates memory for ACL data.
2896 * On successful return, the calling function is responsible to free the
2897 * ACL buffer returned by this function.
2898 */
2899static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2900 struct genl_info *info)
2901{
2902 enum nl80211_acl_policy acl_policy;
2903 struct nlattr *attr;
2904 struct cfg80211_acl_data *acl;
2905 int i = 0, n_entries, tmp;
2906
2907 if (!wiphy->max_acl_mac_addrs)
2908 return ERR_PTR(-EOPNOTSUPP);
2909
2910 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2911 return ERR_PTR(-EINVAL);
2912
2913 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2914 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2915 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2916 return ERR_PTR(-EINVAL);
2917
2918 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2919 return ERR_PTR(-EINVAL);
2920
2921 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2922 if (n_entries < 0)
2923 return ERR_PTR(n_entries);
2924
2925 if (n_entries > wiphy->max_acl_mac_addrs)
2926 return ERR_PTR(-ENOTSUPP);
2927
2928 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2929 GFP_KERNEL);
2930 if (!acl)
2931 return ERR_PTR(-ENOMEM);
2932
2933 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2934 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2935 i++;
2936 }
2937
2938 acl->n_acl_entries = n_entries;
2939 acl->acl_policy = acl_policy;
2940
2941 return acl;
2942}
2943
2944static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2945{
2946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2947 struct net_device *dev = info->user_ptr[1];
2948 struct cfg80211_acl_data *acl;
2949 int err;
2950
2951 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2952 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2953 return -EOPNOTSUPP;
2954
2955 if (!dev->ieee80211_ptr->beacon_interval)
2956 return -EINVAL;
2957
2958 acl = parse_acl_data(&rdev->wiphy, info);
2959 if (IS_ERR(acl))
2960 return PTR_ERR(acl);
2961
2962 err = rdev_set_mac_acl(rdev, dev, acl);
2963
2964 kfree(acl);
2965
2966 return err;
2967}
2968
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002969static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002970 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002971{
Johannes Berg88600202012-02-13 15:17:18 +01002972 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002973
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002974 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2975 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2976 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2977 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002978 return -EINVAL;
2979
Johannes Berg88600202012-02-13 15:17:18 +01002980 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002981
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002982 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2983 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2984 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002985 if (!bcn->head_len)
2986 return -EINVAL;
2987 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002988 }
2989
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002990 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2991 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2992 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002993 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002994 }
2995
Johannes Berg4c476992010-10-04 21:36:35 +02002996 if (!haveinfo)
2997 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002998
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002999 if (attrs[NL80211_ATTR_IE]) {
3000 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3001 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003002 }
3003
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003004 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003005 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003006 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003007 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003008 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003009 }
3010
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003011 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003012 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003013 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003014 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003015 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003016 }
3017
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003018 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3019 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3020 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003021 }
3022
Johannes Berg88600202012-02-13 15:17:18 +01003023 return 0;
3024}
3025
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003026static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3027 struct cfg80211_ap_settings *params)
3028{
3029 struct wireless_dev *wdev;
3030 bool ret = false;
3031
Johannes Berg89a54e42012-06-15 14:33:17 +02003032 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003033 if (wdev->iftype != NL80211_IFTYPE_AP &&
3034 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3035 continue;
3036
Johannes Berg683b6d32012-11-08 21:25:48 +01003037 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003038 continue;
3039
Johannes Berg683b6d32012-11-08 21:25:48 +01003040 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003041 ret = true;
3042 break;
3043 }
3044
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003045 return ret;
3046}
3047
Jouni Malinene39e5b52012-09-30 19:29:39 +03003048static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3049 enum nl80211_auth_type auth_type,
3050 enum nl80211_commands cmd)
3051{
3052 if (auth_type > NL80211_AUTHTYPE_MAX)
3053 return false;
3054
3055 switch (cmd) {
3056 case NL80211_CMD_AUTHENTICATE:
3057 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3058 auth_type == NL80211_AUTHTYPE_SAE)
3059 return false;
3060 return true;
3061 case NL80211_CMD_CONNECT:
3062 case NL80211_CMD_START_AP:
3063 /* SAE not supported yet */
3064 if (auth_type == NL80211_AUTHTYPE_SAE)
3065 return false;
3066 return true;
3067 default:
3068 return false;
3069 }
3070}
3071
Johannes Berg88600202012-02-13 15:17:18 +01003072static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3073{
3074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3075 struct net_device *dev = info->user_ptr[1];
3076 struct wireless_dev *wdev = dev->ieee80211_ptr;
3077 struct cfg80211_ap_settings params;
3078 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003079 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003080
3081 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3082 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3083 return -EOPNOTSUPP;
3084
3085 if (!rdev->ops->start_ap)
3086 return -EOPNOTSUPP;
3087
3088 if (wdev->beacon_interval)
3089 return -EALREADY;
3090
3091 memset(&params, 0, sizeof(params));
3092
3093 /* these are required for START_AP */
3094 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3095 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3096 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3097 return -EINVAL;
3098
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003099 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003100 if (err)
3101 return err;
3102
3103 params.beacon_interval =
3104 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3105 params.dtim_period =
3106 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3107
3108 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3109 if (err)
3110 return err;
3111
3112 /*
3113 * In theory, some of these attributes should be required here
3114 * but since they were not used when the command was originally
3115 * added, keep them optional for old user space programs to let
3116 * them continue to work with drivers that do not need the
3117 * additional information -- drivers must check!
3118 */
3119 if (info->attrs[NL80211_ATTR_SSID]) {
3120 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3121 params.ssid_len =
3122 nla_len(info->attrs[NL80211_ATTR_SSID]);
3123 if (params.ssid_len == 0 ||
3124 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3125 return -EINVAL;
3126 }
3127
3128 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3129 params.hidden_ssid = nla_get_u32(
3130 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3131 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3132 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3133 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3134 return -EINVAL;
3135 }
3136
3137 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3138
3139 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3140 params.auth_type = nla_get_u32(
3141 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003142 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3143 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003144 return -EINVAL;
3145 } else
3146 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3147
3148 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3149 NL80211_MAX_NR_CIPHER_SUITES);
3150 if (err)
3151 return err;
3152
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303153 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3154 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3155 return -EOPNOTSUPP;
3156 params.inactivity_timeout = nla_get_u16(
3157 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3158 }
3159
Johannes Berg53cabad2012-11-14 15:17:28 +01003160 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3161 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3162 return -EINVAL;
3163 params.p2p_ctwindow =
3164 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3165 if (params.p2p_ctwindow > 127)
3166 return -EINVAL;
3167 if (params.p2p_ctwindow != 0 &&
3168 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3169 return -EINVAL;
3170 }
3171
3172 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3173 u8 tmp;
3174
3175 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3176 return -EINVAL;
3177 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3178 if (tmp > 1)
3179 return -EINVAL;
3180 params.p2p_opp_ps = tmp;
3181 if (params.p2p_opp_ps != 0 &&
3182 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3183 return -EINVAL;
3184 }
3185
Johannes Bergaa430da2012-05-16 23:50:18 +02003186 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003187 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3188 if (err)
3189 return err;
3190 } else if (wdev->preset_chandef.chan) {
3191 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003192 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003193 return -EINVAL;
3194
Johannes Berg683b6d32012-11-08 21:25:48 +01003195 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003196 return -EINVAL;
3197
Simon Wunderlich04f39042013-02-08 18:16:19 +01003198 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3199 if (err < 0)
3200 return err;
3201 if (err) {
3202 radar_detect_width = BIT(params.chandef.width);
3203 params.radar_required = true;
3204 }
3205
Simon Wunderlich04f39042013-02-08 18:16:19 +01003206 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3207 params.chandef.chan,
3208 CHAN_MODE_SHARED,
3209 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003210 if (err)
3211 return err;
3212
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303213 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3214 params.acl = parse_acl_data(&rdev->wiphy, info);
3215 if (IS_ERR(params.acl))
3216 return PTR_ERR(params.acl);
3217 }
3218
Hila Gonene35e4d22012-06-27 17:19:42 +03003219 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003220 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003221 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003222 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003223 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003224 wdev->ssid_len = params.ssid_len;
3225 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003226 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303227
3228 kfree(params.acl);
3229
Johannes Berg56d18932011-05-09 18:41:15 +02003230 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003231}
3232
Johannes Berg88600202012-02-13 15:17:18 +01003233static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3234{
3235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3236 struct net_device *dev = info->user_ptr[1];
3237 struct wireless_dev *wdev = dev->ieee80211_ptr;
3238 struct cfg80211_beacon_data params;
3239 int err;
3240
3241 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3242 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3243 return -EOPNOTSUPP;
3244
3245 if (!rdev->ops->change_beacon)
3246 return -EOPNOTSUPP;
3247
3248 if (!wdev->beacon_interval)
3249 return -EINVAL;
3250
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003251 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003252 if (err)
3253 return err;
3254
Hila Gonene35e4d22012-06-27 17:19:42 +03003255 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003256}
3257
3258static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003259{
Johannes Berg4c476992010-10-04 21:36:35 +02003260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3261 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003262
Michal Kazior60771782012-06-29 12:46:56 +02003263 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003264}
3265
Johannes Berg5727ef12007-12-19 02:03:34 +01003266static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3267 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3268 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3269 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003270 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003271 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003272 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003273};
3274
Johannes Bergeccb8e82009-05-11 21:57:56 +03003275static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003276 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003277 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003278{
3279 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003280 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003281 int flag;
3282
Johannes Bergeccb8e82009-05-11 21:57:56 +03003283 /*
3284 * Try parsing the new attribute first so userspace
3285 * can specify both for older kernels.
3286 */
3287 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3288 if (nla) {
3289 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003290
Johannes Bergeccb8e82009-05-11 21:57:56 +03003291 sta_flags = nla_data(nla);
3292 params->sta_flags_mask = sta_flags->mask;
3293 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003294 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003295 if ((params->sta_flags_mask |
3296 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3297 return -EINVAL;
3298 return 0;
3299 }
3300
3301 /* if present, parse the old attribute */
3302
3303 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003304 if (!nla)
3305 return 0;
3306
3307 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3308 nla, sta_flags_policy))
3309 return -EINVAL;
3310
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003311 /*
3312 * Only allow certain flags for interface types so that
3313 * other attributes are silently ignored. Remember that
3314 * this is backward compatibility code with old userspace
3315 * and shouldn't be hit in other cases anyway.
3316 */
3317 switch (iftype) {
3318 case NL80211_IFTYPE_AP:
3319 case NL80211_IFTYPE_AP_VLAN:
3320 case NL80211_IFTYPE_P2P_GO:
3321 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3322 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3323 BIT(NL80211_STA_FLAG_WME) |
3324 BIT(NL80211_STA_FLAG_MFP);
3325 break;
3326 case NL80211_IFTYPE_P2P_CLIENT:
3327 case NL80211_IFTYPE_STATION:
3328 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3329 BIT(NL80211_STA_FLAG_TDLS_PEER);
3330 break;
3331 case NL80211_IFTYPE_MESH_POINT:
3332 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3333 BIT(NL80211_STA_FLAG_MFP) |
3334 BIT(NL80211_STA_FLAG_AUTHORIZED);
3335 default:
3336 return -EINVAL;
3337 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003338
Johannes Berg3383b5a2012-05-10 20:14:43 +02003339 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3340 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003341 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003342
Johannes Berg3383b5a2012-05-10 20:14:43 +02003343 /* no longer support new API additions in old API */
3344 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3345 return -EINVAL;
3346 }
3347 }
3348
Johannes Berg5727ef12007-12-19 02:03:34 +01003349 return 0;
3350}
3351
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003352static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3353 int attr)
3354{
3355 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003356 u32 bitrate;
3357 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003358
3359 rate = nla_nest_start(msg, attr);
3360 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003361 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003362
3363 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3364 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003365 /* report 16-bit bitrate only if we can */
3366 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003367 if (bitrate > 0 &&
3368 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3369 return false;
3370 if (bitrate_compat > 0 &&
3371 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3372 return false;
3373
3374 if (info->flags & RATE_INFO_FLAGS_MCS) {
3375 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
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_SHORT_GI &&
3381 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3382 return false;
3383 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3384 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3385 return false;
3386 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3387 return false;
3388 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3389 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3390 return false;
3391 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3392 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3393 return false;
3394 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3395 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3396 return false;
3397 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3398 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3399 return false;
3400 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3401 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3402 return false;
3403 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003404
3405 nla_nest_end(msg, rate);
3406 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003407}
3408
Felix Fietkau119363c2013-04-22 16:29:30 +02003409static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3410 int id)
3411{
3412 void *attr;
3413 int i = 0;
3414
3415 if (!mask)
3416 return true;
3417
3418 attr = nla_nest_start(msg, id);
3419 if (!attr)
3420 return false;
3421
3422 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3423 if (!(mask & BIT(i)))
3424 continue;
3425
3426 if (nla_put_u8(msg, i, signal[i]))
3427 return false;
3428 }
3429
3430 nla_nest_end(msg, attr);
3431
3432 return true;
3433}
3434
Eric W. Biederman15e47302012-09-07 20:12:54 +00003435static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003436 int flags,
3437 struct cfg80211_registered_device *rdev,
3438 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003439 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003440{
3441 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003442 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003443
Eric W. Biederman15e47302012-09-07 20:12:54 +00003444 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003445 if (!hdr)
3446 return -1;
3447
David S. Miller9360ffd2012-03-29 04:41:26 -04003448 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3449 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3450 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3451 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003452
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003453 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3454 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003455 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003456 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3458 sinfo->connected_time))
3459 goto nla_put_failure;
3460 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3461 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3462 sinfo->inactive_time))
3463 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003464 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3465 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003466 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003467 (u32)sinfo->rx_bytes))
3468 goto nla_put_failure;
3469 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003470 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003471 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3472 (u32)sinfo->tx_bytes))
3473 goto nla_put_failure;
3474 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3475 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003476 sinfo->rx_bytes))
3477 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003478 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3479 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003480 sinfo->tx_bytes))
3481 goto nla_put_failure;
3482 if ((sinfo->filled & STATION_INFO_LLID) &&
3483 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3484 goto nla_put_failure;
3485 if ((sinfo->filled & STATION_INFO_PLID) &&
3486 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3487 goto nla_put_failure;
3488 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3489 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3490 sinfo->plink_state))
3491 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003492 switch (rdev->wiphy.signal_type) {
3493 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003494 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3495 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3496 sinfo->signal))
3497 goto nla_put_failure;
3498 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3499 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3500 sinfo->signal_avg))
3501 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003502 break;
3503 default:
3504 break;
3505 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003506 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3507 if (!nl80211_put_signal(msg, sinfo->chains,
3508 sinfo->chain_signal,
3509 NL80211_STA_INFO_CHAIN_SIGNAL))
3510 goto nla_put_failure;
3511 }
3512 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3513 if (!nl80211_put_signal(msg, sinfo->chains,
3514 sinfo->chain_signal_avg,
3515 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3516 goto nla_put_failure;
3517 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003518 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003519 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3520 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003521 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003522 }
3523 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3524 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3525 NL80211_STA_INFO_RX_BITRATE))
3526 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003527 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003528 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3529 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3530 sinfo->rx_packets))
3531 goto nla_put_failure;
3532 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3533 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3534 sinfo->tx_packets))
3535 goto nla_put_failure;
3536 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3537 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3538 sinfo->tx_retries))
3539 goto nla_put_failure;
3540 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3541 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3542 sinfo->tx_failed))
3543 goto nla_put_failure;
3544 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3545 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3546 sinfo->beacon_loss_count))
3547 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003548 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3549 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3550 sinfo->local_pm))
3551 goto nla_put_failure;
3552 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3553 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3554 sinfo->peer_pm))
3555 goto nla_put_failure;
3556 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3557 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3558 sinfo->nonpeer_pm))
3559 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003560 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3561 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3562 if (!bss_param)
3563 goto nla_put_failure;
3564
David S. Miller9360ffd2012-03-29 04:41:26 -04003565 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3566 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3567 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3568 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3569 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3570 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3571 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3572 sinfo->bss_param.dtim_period) ||
3573 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3574 sinfo->bss_param.beacon_interval))
3575 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003576
3577 nla_nest_end(msg, bss_param);
3578 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003579 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3580 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3581 sizeof(struct nl80211_sta_flag_update),
3582 &sinfo->sta_flags))
3583 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003584 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3585 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3586 sinfo->t_offset))
3587 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003588 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
David S. Miller9360ffd2012-03-29 04:41:26 -04003590 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3591 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3592 sinfo->assoc_req_ies))
3593 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003594
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 return genlmsg_end(msg, hdr);
3596
3597 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003598 genlmsg_cancel(msg, hdr);
3599 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003600}
3601
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003602static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003603 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003604{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003605 struct station_info sinfo;
3606 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003607 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003608 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003609 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003610 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003611
Johannes Berg97990a02013-04-19 01:02:55 +02003612 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003613 if (err)
3614 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003615
Johannes Berg97990a02013-04-19 01:02:55 +02003616 if (!wdev->netdev) {
3617 err = -EINVAL;
3618 goto out_err;
3619 }
3620
Johannes Bergbba95fe2008-07-29 13:22:51 +02003621 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003622 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003623 goto out_err;
3624 }
3625
Johannes Bergbba95fe2008-07-29 13:22:51 +02003626 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003627 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003628 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003629 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003630 if (err == -ENOENT)
3631 break;
3632 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003633 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003634
3635 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003636 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003637 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003638 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003639 &sinfo) < 0)
3640 goto out;
3641
3642 sta_idx++;
3643 }
3644
3645
3646 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003647 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003648 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003649 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003650 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003651
3652 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003653}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003654
Johannes Berg5727ef12007-12-19 02:03:34 +01003655static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3656{
Johannes Berg4c476992010-10-04 21:36:35 +02003657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3658 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003659 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003660 struct sk_buff *msg;
3661 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003662 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003663
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003664 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003665
3666 if (!info->attrs[NL80211_ATTR_MAC])
3667 return -EINVAL;
3668
3669 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3670
Johannes Berg4c476992010-10-04 21:36:35 +02003671 if (!rdev->ops->get_station)
3672 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003673
Hila Gonene35e4d22012-06-27 17:19:42 +03003674 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003675 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003676 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003677
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003678 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003679 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003680 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003681
Eric W. Biederman15e47302012-09-07 20:12:54 +00003682 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003683 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003684 nlmsg_free(msg);
3685 return -ENOBUFS;
3686 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003687
Johannes Berg4c476992010-10-04 21:36:35 +02003688 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003689}
3690
Johannes Berg77ee7c82013-02-15 00:48:33 +01003691int cfg80211_check_station_change(struct wiphy *wiphy,
3692 struct station_parameters *params,
3693 enum cfg80211_station_type statype)
3694{
3695 if (params->listen_interval != -1)
3696 return -EINVAL;
3697 if (params->aid)
3698 return -EINVAL;
3699
3700 /* When you run into this, adjust the code below for the new flag */
3701 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3702
3703 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003704 case CFG80211_STA_MESH_PEER_KERNEL:
3705 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003706 /*
3707 * No ignoring the TDLS flag here -- the userspace mesh
3708 * code doesn't have the bug of including TDLS in the
3709 * mask everywhere.
3710 */
3711 if (params->sta_flags_mask &
3712 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3713 BIT(NL80211_STA_FLAG_MFP) |
3714 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3715 return -EINVAL;
3716 break;
3717 case CFG80211_STA_TDLS_PEER_SETUP:
3718 case CFG80211_STA_TDLS_PEER_ACTIVE:
3719 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3720 return -EINVAL;
3721 /* ignore since it can't change */
3722 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3723 break;
3724 default:
3725 /* disallow mesh-specific things */
3726 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3727 return -EINVAL;
3728 if (params->local_pm)
3729 return -EINVAL;
3730 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3731 return -EINVAL;
3732 }
3733
3734 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3735 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3736 /* TDLS can't be set, ... */
3737 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3738 return -EINVAL;
3739 /*
3740 * ... but don't bother the driver with it. This works around
3741 * a hostapd/wpa_supplicant issue -- it always includes the
3742 * TLDS_PEER flag in the mask even for AP mode.
3743 */
3744 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3745 }
3746
3747 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3748 /* reject other things that can't change */
3749 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3750 return -EINVAL;
3751 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3752 return -EINVAL;
3753 if (params->supported_rates)
3754 return -EINVAL;
3755 if (params->ext_capab || params->ht_capa || params->vht_capa)
3756 return -EINVAL;
3757 }
3758
3759 if (statype != CFG80211_STA_AP_CLIENT) {
3760 if (params->vlan)
3761 return -EINVAL;
3762 }
3763
3764 switch (statype) {
3765 case CFG80211_STA_AP_MLME_CLIENT:
3766 /* Use this only for authorizing/unauthorizing a station */
3767 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3768 return -EOPNOTSUPP;
3769 break;
3770 case CFG80211_STA_AP_CLIENT:
3771 /* accept only the listed bits */
3772 if (params->sta_flags_mask &
3773 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3774 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3775 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3776 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3777 BIT(NL80211_STA_FLAG_WME) |
3778 BIT(NL80211_STA_FLAG_MFP)))
3779 return -EINVAL;
3780
3781 /* but authenticated/associated only if driver handles it */
3782 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3783 params->sta_flags_mask &
3784 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3785 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3786 return -EINVAL;
3787 break;
3788 case CFG80211_STA_IBSS:
3789 case CFG80211_STA_AP_STA:
3790 /* reject any changes other than AUTHORIZED */
3791 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3792 return -EINVAL;
3793 break;
3794 case CFG80211_STA_TDLS_PEER_SETUP:
3795 /* reject any changes other than AUTHORIZED or WME */
3796 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3797 BIT(NL80211_STA_FLAG_WME)))
3798 return -EINVAL;
3799 /* force (at least) rates when authorizing */
3800 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3801 !params->supported_rates)
3802 return -EINVAL;
3803 break;
3804 case CFG80211_STA_TDLS_PEER_ACTIVE:
3805 /* reject any changes */
3806 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003807 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003808 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3809 return -EINVAL;
3810 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003811 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003812 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3813 return -EINVAL;
3814 break;
3815 }
3816
3817 return 0;
3818}
3819EXPORT_SYMBOL(cfg80211_check_station_change);
3820
Johannes Berg5727ef12007-12-19 02:03:34 +01003821/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003822 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003823 */
Johannes Berg80b99892011-11-18 16:23:01 +01003824static struct net_device *get_vlan(struct genl_info *info,
3825 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003826{
Johannes Berg463d0182009-07-14 00:33:35 +02003827 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003828 struct net_device *v;
3829 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003830
Johannes Berg80b99892011-11-18 16:23:01 +01003831 if (!vlanattr)
3832 return NULL;
3833
3834 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3835 if (!v)
3836 return ERR_PTR(-ENODEV);
3837
3838 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3839 ret = -EINVAL;
3840 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003841 }
Johannes Berg80b99892011-11-18 16:23:01 +01003842
Johannes Berg77ee7c82013-02-15 00:48:33 +01003843 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3844 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3845 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3846 ret = -EINVAL;
3847 goto error;
3848 }
3849
Johannes Berg80b99892011-11-18 16:23:01 +01003850 if (!netif_running(v)) {
3851 ret = -ENETDOWN;
3852 goto error;
3853 }
3854
3855 return v;
3856 error:
3857 dev_put(v);
3858 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003859}
3860
Jouni Malinendf881292013-02-14 21:10:54 +02003861static struct nla_policy
3862nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3863 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3864 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3865};
3866
Johannes Bergff276692013-02-15 00:09:01 +01003867static int nl80211_parse_sta_wme(struct genl_info *info,
3868 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003869{
Jouni Malinendf881292013-02-14 21:10:54 +02003870 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3871 struct nlattr *nla;
3872 int err;
3873
Jouni Malinendf881292013-02-14 21:10:54 +02003874 /* parse WME attributes if present */
3875 if (!info->attrs[NL80211_ATTR_STA_WME])
3876 return 0;
3877
3878 nla = info->attrs[NL80211_ATTR_STA_WME];
3879 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3880 nl80211_sta_wme_policy);
3881 if (err)
3882 return err;
3883
3884 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3885 params->uapsd_queues = nla_get_u8(
3886 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3887 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3888 return -EINVAL;
3889
3890 if (tb[NL80211_STA_WME_MAX_SP])
3891 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3892
3893 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3894 return -EINVAL;
3895
3896 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3897
3898 return 0;
3899}
3900
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303901static int nl80211_parse_sta_channel_info(struct genl_info *info,
3902 struct station_parameters *params)
3903{
3904 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3905 params->supported_channels =
3906 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3907 params->supported_channels_len =
3908 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3909 /*
3910 * Need to include at least one (first channel, number of
3911 * channels) tuple for each subband, and must have proper
3912 * tuples for the rest of the data as well.
3913 */
3914 if (params->supported_channels_len < 2)
3915 return -EINVAL;
3916 if (params->supported_channels_len % 2)
3917 return -EINVAL;
3918 }
3919
3920 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3921 params->supported_oper_classes =
3922 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3923 params->supported_oper_classes_len =
3924 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3925 /*
3926 * The value of the Length field of the Supported Operating
3927 * Classes element is between 2 and 253.
3928 */
3929 if (params->supported_oper_classes_len < 2 ||
3930 params->supported_oper_classes_len > 253)
3931 return -EINVAL;
3932 }
3933 return 0;
3934}
3935
Johannes Bergff276692013-02-15 00:09:01 +01003936static int nl80211_set_station_tdls(struct genl_info *info,
3937 struct station_parameters *params)
3938{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303939 int err;
Johannes Bergff276692013-02-15 00:09:01 +01003940 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003941 if (info->attrs[NL80211_ATTR_PEER_AID])
3942 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003943 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3944 params->ht_capa =
3945 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3946 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3947 params->vht_capa =
3948 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3949
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303950 err = nl80211_parse_sta_channel_info(info, params);
3951 if (err)
3952 return err;
3953
Johannes Bergff276692013-02-15 00:09:01 +01003954 return nl80211_parse_sta_wme(info, params);
3955}
3956
Johannes Berg5727ef12007-12-19 02:03:34 +01003957static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3958{
Johannes Berg4c476992010-10-04 21:36:35 +02003959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003960 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003961 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003962 u8 *mac_addr;
3963 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003964
3965 memset(&params, 0, sizeof(params));
3966
3967 params.listen_interval = -1;
3968
Johannes Berg77ee7c82013-02-15 00:48:33 +01003969 if (!rdev->ops->change_station)
3970 return -EOPNOTSUPP;
3971
Johannes Berg5727ef12007-12-19 02:03:34 +01003972 if (info->attrs[NL80211_ATTR_STA_AID])
3973 return -EINVAL;
3974
3975 if (!info->attrs[NL80211_ATTR_MAC])
3976 return -EINVAL;
3977
3978 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3979
3980 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3981 params.supported_rates =
3982 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3983 params.supported_rates_len =
3984 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3985 }
3986
Jouni Malinen9d62a982013-02-14 21:10:13 +02003987 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3988 params.capability =
3989 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3990 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3991 }
3992
3993 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3994 params.ext_capab =
3995 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3996 params.ext_capab_len =
3997 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3998 }
3999
Jouni Malinendf881292013-02-14 21:10:54 +02004000 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004001 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004002
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004003 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004004 return -EINVAL;
4005
Johannes Bergf8bacc22013-02-14 23:27:01 +01004006 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004007 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004008 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4009 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4010 return -EINVAL;
4011 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004012
Johannes Bergf8bacc22013-02-14 23:27:01 +01004013 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004014 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004015 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4016 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4017 return -EINVAL;
4018 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4019 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004020
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004021 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4022 enum nl80211_mesh_power_mode pm = nla_get_u32(
4023 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4024
4025 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4026 pm > NL80211_MESH_POWER_MAX)
4027 return -EINVAL;
4028
4029 params.local_pm = pm;
4030 }
4031
Johannes Berg77ee7c82013-02-15 00:48:33 +01004032 /* Include parameters for TDLS peer (will check later) */
4033 err = nl80211_set_station_tdls(info, &params);
4034 if (err)
4035 return err;
4036
4037 params.vlan = get_vlan(info, rdev);
4038 if (IS_ERR(params.vlan))
4039 return PTR_ERR(params.vlan);
4040
Johannes Berga97f4422009-06-18 17:23:43 +02004041 switch (dev->ieee80211_ptr->iftype) {
4042 case NL80211_IFTYPE_AP:
4043 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004044 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004045 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004046 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004047 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004048 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004049 break;
4050 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004051 err = -EOPNOTSUPP;
4052 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004053 }
4054
Johannes Berg77ee7c82013-02-15 00:48:33 +01004055 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004056 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004057
Johannes Berg77ee7c82013-02-15 00:48:33 +01004058 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004059 if (params.vlan)
4060 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004061
Johannes Berg5727ef12007-12-19 02:03:34 +01004062 return err;
4063}
4064
4065static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4066{
Johannes Berg4c476992010-10-04 21:36:35 +02004067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004068 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004069 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004070 struct station_parameters params;
4071 u8 *mac_addr = NULL;
4072
4073 memset(&params, 0, sizeof(params));
4074
Johannes Berg984c3112013-02-14 23:43:25 +01004075 if (!rdev->ops->add_station)
4076 return -EOPNOTSUPP;
4077
Johannes Berg5727ef12007-12-19 02:03:34 +01004078 if (!info->attrs[NL80211_ATTR_MAC])
4079 return -EINVAL;
4080
Johannes Berg5727ef12007-12-19 02:03:34 +01004081 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4082 return -EINVAL;
4083
4084 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4085 return -EINVAL;
4086
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004087 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4088 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004089 return -EINVAL;
4090
Johannes Berg5727ef12007-12-19 02:03:34 +01004091 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4092 params.supported_rates =
4093 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4094 params.supported_rates_len =
4095 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4096 params.listen_interval =
4097 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004098
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004099 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004100 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004101 else
4102 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004103 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4104 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004105
Jouni Malinen9d62a982013-02-14 21:10:13 +02004106 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4107 params.capability =
4108 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4109 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4110 }
4111
4112 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4113 params.ext_capab =
4114 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4115 params.ext_capab_len =
4116 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4117 }
4118
Jouni Malinen36aedc92008-08-25 11:58:58 +03004119 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4120 params.ht_capa =
4121 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004122
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004123 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4124 params.vht_capa =
4125 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4126
Johannes Bergf8bacc22013-02-14 23:27:01 +01004127 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004128 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004129 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4130 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4131 return -EINVAL;
4132 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004133
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304134 err = nl80211_parse_sta_channel_info(info, &params);
4135 if (err)
4136 return err;
4137
Johannes Bergff276692013-02-15 00:09:01 +01004138 err = nl80211_parse_sta_wme(info, &params);
4139 if (err)
4140 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004141
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004142 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004143 return -EINVAL;
4144
Johannes Berg77ee7c82013-02-15 00:48:33 +01004145 /* When you run into this, adjust the code below for the new flag */
4146 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4147
Johannes Bergbdd90d52011-12-14 12:20:27 +01004148 switch (dev->ieee80211_ptr->iftype) {
4149 case NL80211_IFTYPE_AP:
4150 case NL80211_IFTYPE_AP_VLAN:
4151 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004152 /* ignore WME attributes if iface/sta is not capable */
4153 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4154 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4155 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004156
Johannes Bergbdd90d52011-12-14 12:20:27 +01004157 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004158 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4159 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004160 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004161 /* but don't bother the driver with it */
4162 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004163
Johannes Bergd582cff2012-10-26 17:53:44 +02004164 /* allow authenticated/associated only if driver handles it */
4165 if (!(rdev->wiphy.features &
4166 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4167 params.sta_flags_mask &
4168 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4169 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4170 return -EINVAL;
4171
Johannes Bergbdd90d52011-12-14 12:20:27 +01004172 /* must be last in here for error handling */
4173 params.vlan = get_vlan(info, rdev);
4174 if (IS_ERR(params.vlan))
4175 return PTR_ERR(params.vlan);
4176 break;
4177 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004178 /* ignore uAPSD data */
4179 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4180
Johannes Bergd582cff2012-10-26 17:53:44 +02004181 /* associated is disallowed */
4182 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4183 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004184 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004185 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4186 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004187 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004188 break;
4189 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004190 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004191 /* ignore uAPSD data */
4192 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4193
Johannes Berg77ee7c82013-02-15 00:48:33 +01004194 /* these are disallowed */
4195 if (params.sta_flags_mask &
4196 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4197 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004198 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004199 /* Only TDLS peers can be added */
4200 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4201 return -EINVAL;
4202 /* Can only add if TDLS ... */
4203 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4204 return -EOPNOTSUPP;
4205 /* ... with external setup is supported */
4206 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4207 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004208 /*
4209 * Older wpa_supplicant versions always mark the TDLS peer
4210 * as authorized, but it shouldn't yet be.
4211 */
4212 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004213 break;
4214 default:
4215 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004216 }
4217
Johannes Bergbdd90d52011-12-14 12:20:27 +01004218 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004219
Hila Gonene35e4d22012-06-27 17:19:42 +03004220 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004221
Johannes Berg5727ef12007-12-19 02:03:34 +01004222 if (params.vlan)
4223 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004224 return err;
4225}
4226
4227static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4228{
Johannes Berg4c476992010-10-04 21:36:35 +02004229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4230 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004231 u8 *mac_addr = NULL;
4232
4233 if (info->attrs[NL80211_ATTR_MAC])
4234 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4235
Johannes Berge80cf852009-05-11 14:43:13 +02004236 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004237 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004238 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004239 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4240 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004241
Johannes Berg4c476992010-10-04 21:36:35 +02004242 if (!rdev->ops->del_station)
4243 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004244
Hila Gonene35e4d22012-06-27 17:19:42 +03004245 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004246}
4247
Eric W. Biederman15e47302012-09-07 20:12:54 +00004248static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004249 int flags, struct net_device *dev,
4250 u8 *dst, u8 *next_hop,
4251 struct mpath_info *pinfo)
4252{
4253 void *hdr;
4254 struct nlattr *pinfoattr;
4255
Eric W. Biederman15e47302012-09-07 20:12:54 +00004256 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004257 if (!hdr)
4258 return -1;
4259
David S. Miller9360ffd2012-03-29 04:41:26 -04004260 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4261 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4262 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4263 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4264 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004265
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004266 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4267 if (!pinfoattr)
4268 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004269 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4270 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4271 pinfo->frame_qlen))
4272 goto nla_put_failure;
4273 if (((pinfo->filled & MPATH_INFO_SN) &&
4274 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4275 ((pinfo->filled & MPATH_INFO_METRIC) &&
4276 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4277 pinfo->metric)) ||
4278 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4279 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4280 pinfo->exptime)) ||
4281 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4282 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4283 pinfo->flags)) ||
4284 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4285 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4286 pinfo->discovery_timeout)) ||
4287 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4288 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4289 pinfo->discovery_retries)))
4290 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004291
4292 nla_nest_end(msg, pinfoattr);
4293
4294 return genlmsg_end(msg, hdr);
4295
4296 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004297 genlmsg_cancel(msg, hdr);
4298 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004299}
4300
4301static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004302 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004303{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004304 struct mpath_info pinfo;
4305 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004306 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004307 u8 dst[ETH_ALEN];
4308 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004309 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004310 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004311
Johannes Berg97990a02013-04-19 01:02:55 +02004312 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004313 if (err)
4314 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004315
4316 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004317 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004318 goto out_err;
4319 }
4320
Johannes Berg97990a02013-04-19 01:02:55 +02004321 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004322 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004323 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004324 }
4325
Johannes Bergbba95fe2008-07-29 13:22:51 +02004326 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004327 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4328 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004329 if (err == -ENOENT)
4330 break;
4331 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004332 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004333
Eric W. Biederman15e47302012-09-07 20:12:54 +00004334 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004335 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004336 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004337 &pinfo) < 0)
4338 goto out;
4339
4340 path_idx++;
4341 }
4342
4343
4344 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004345 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004346 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004347 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004348 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004349 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004350}
4351
4352static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4353{
Johannes Berg4c476992010-10-04 21:36:35 +02004354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004355 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004356 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004357 struct mpath_info pinfo;
4358 struct sk_buff *msg;
4359 u8 *dst = NULL;
4360 u8 next_hop[ETH_ALEN];
4361
4362 memset(&pinfo, 0, sizeof(pinfo));
4363
4364 if (!info->attrs[NL80211_ATTR_MAC])
4365 return -EINVAL;
4366
4367 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4368
Johannes Berg4c476992010-10-04 21:36:35 +02004369 if (!rdev->ops->get_mpath)
4370 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004371
Johannes Berg4c476992010-10-04 21:36:35 +02004372 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4373 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004374
Hila Gonene35e4d22012-06-27 17:19:42 +03004375 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004376 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004377 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004378
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004380 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004381 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004382
Eric W. Biederman15e47302012-09-07 20:12:54 +00004383 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004384 dev, dst, next_hop, &pinfo) < 0) {
4385 nlmsg_free(msg);
4386 return -ENOBUFS;
4387 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004388
Johannes Berg4c476992010-10-04 21:36:35 +02004389 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004390}
4391
4392static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4393{
Johannes Berg4c476992010-10-04 21:36:35 +02004394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4395 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004396 u8 *dst = NULL;
4397 u8 *next_hop = NULL;
4398
4399 if (!info->attrs[NL80211_ATTR_MAC])
4400 return -EINVAL;
4401
4402 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4403 return -EINVAL;
4404
4405 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4406 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4407
Johannes Berg4c476992010-10-04 21:36:35 +02004408 if (!rdev->ops->change_mpath)
4409 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004410
Johannes Berg4c476992010-10-04 21:36:35 +02004411 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4412 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004413
Hila Gonene35e4d22012-06-27 17:19:42 +03004414 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004415}
Johannes Berg4c476992010-10-04 21:36:35 +02004416
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004417static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4418{
Johannes Berg4c476992010-10-04 21:36:35 +02004419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4420 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004421 u8 *dst = NULL;
4422 u8 *next_hop = NULL;
4423
4424 if (!info->attrs[NL80211_ATTR_MAC])
4425 return -EINVAL;
4426
4427 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4428 return -EINVAL;
4429
4430 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4431 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4432
Johannes Berg4c476992010-10-04 21:36:35 +02004433 if (!rdev->ops->add_mpath)
4434 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004435
Johannes Berg4c476992010-10-04 21:36:35 +02004436 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4437 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004438
Hila Gonene35e4d22012-06-27 17:19:42 +03004439 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004440}
4441
4442static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4443{
Johannes Berg4c476992010-10-04 21:36:35 +02004444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4445 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004446 u8 *dst = NULL;
4447
4448 if (info->attrs[NL80211_ATTR_MAC])
4449 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4450
Johannes Berg4c476992010-10-04 21:36:35 +02004451 if (!rdev->ops->del_mpath)
4452 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004453
Hila Gonene35e4d22012-06-27 17:19:42 +03004454 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004455}
4456
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004457static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4458{
Johannes Berg4c476992010-10-04 21:36:35 +02004459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4460 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004461 struct bss_parameters params;
4462
4463 memset(&params, 0, sizeof(params));
4464 /* default to not changing parameters */
4465 params.use_cts_prot = -1;
4466 params.use_short_preamble = -1;
4467 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004468 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004469 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004470 params.p2p_ctwindow = -1;
4471 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004472
4473 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4474 params.use_cts_prot =
4475 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4476 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4477 params.use_short_preamble =
4478 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4479 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4480 params.use_short_slot_time =
4481 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004482 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4483 params.basic_rates =
4484 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4485 params.basic_rates_len =
4486 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4487 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004488 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4489 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004490 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4491 params.ht_opmode =
4492 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004493
Johannes Berg53cabad2012-11-14 15:17:28 +01004494 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4495 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4496 return -EINVAL;
4497 params.p2p_ctwindow =
4498 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4499 if (params.p2p_ctwindow < 0)
4500 return -EINVAL;
4501 if (params.p2p_ctwindow != 0 &&
4502 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4503 return -EINVAL;
4504 }
4505
4506 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4507 u8 tmp;
4508
4509 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4510 return -EINVAL;
4511 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4512 if (tmp > 1)
4513 return -EINVAL;
4514 params.p2p_opp_ps = tmp;
4515 if (params.p2p_opp_ps &&
4516 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4517 return -EINVAL;
4518 }
4519
Johannes Berg4c476992010-10-04 21:36:35 +02004520 if (!rdev->ops->change_bss)
4521 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004522
Johannes Berg074ac8d2010-09-16 14:58:22 +02004523 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004524 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4525 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004526
Hila Gonene35e4d22012-06-27 17:19:42 +03004527 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004528}
4529
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004530static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004531 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4532 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4533 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4534 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4535 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4536 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4537};
4538
4539static int parse_reg_rule(struct nlattr *tb[],
4540 struct ieee80211_reg_rule *reg_rule)
4541{
4542 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4543 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4544
4545 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4546 return -EINVAL;
4547 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4548 return -EINVAL;
4549 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4550 return -EINVAL;
4551 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4552 return -EINVAL;
4553 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4554 return -EINVAL;
4555
4556 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4557
4558 freq_range->start_freq_khz =
4559 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4560 freq_range->end_freq_khz =
4561 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4562 freq_range->max_bandwidth_khz =
4563 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4564
4565 power_rule->max_eirp =
4566 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4567
4568 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4569 power_rule->max_antenna_gain =
4570 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4571
4572 return 0;
4573}
4574
4575static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4576{
4577 int r;
4578 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004579 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004580
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004581 /*
4582 * You should only get this when cfg80211 hasn't yet initialized
4583 * completely when built-in to the kernel right between the time
4584 * window between nl80211_init() and regulatory_init(), if that is
4585 * even possible.
4586 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004587 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004588 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004589
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004590 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4591 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004592
4593 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4594
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004595 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4596 user_reg_hint_type =
4597 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4598 else
4599 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4600
4601 switch (user_reg_hint_type) {
4602 case NL80211_USER_REG_HINT_USER:
4603 case NL80211_USER_REG_HINT_CELL_BASE:
4604 break;
4605 default:
4606 return -EINVAL;
4607 }
4608
4609 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004610
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004611 return r;
4612}
4613
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004614static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004615 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004616{
Johannes Berg4c476992010-10-04 21:36:35 +02004617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004618 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004619 struct wireless_dev *wdev = dev->ieee80211_ptr;
4620 struct mesh_config cur_params;
4621 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004622 void *hdr;
4623 struct nlattr *pinfoattr;
4624 struct sk_buff *msg;
4625
Johannes Berg29cbe682010-12-03 09:20:44 +01004626 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4627 return -EOPNOTSUPP;
4628
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004629 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004630 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004631
Johannes Berg29cbe682010-12-03 09:20:44 +01004632 wdev_lock(wdev);
4633 /* If not connected, get default parameters */
4634 if (!wdev->mesh_id_len)
4635 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4636 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004637 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004638 wdev_unlock(wdev);
4639
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004640 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004641 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004642
4643 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004644 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004645 if (!msg)
4646 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004647 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004648 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004649 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004650 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004651 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004652 if (!pinfoattr)
4653 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004654 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4655 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4656 cur_params.dot11MeshRetryTimeout) ||
4657 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4658 cur_params.dot11MeshConfirmTimeout) ||
4659 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4660 cur_params.dot11MeshHoldingTimeout) ||
4661 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4662 cur_params.dot11MeshMaxPeerLinks) ||
4663 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4664 cur_params.dot11MeshMaxRetries) ||
4665 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4666 cur_params.dot11MeshTTL) ||
4667 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4668 cur_params.element_ttl) ||
4669 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4670 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004671 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4672 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004673 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4674 cur_params.dot11MeshHWMPmaxPREQretries) ||
4675 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4676 cur_params.path_refresh_time) ||
4677 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4678 cur_params.min_discovery_timeout) ||
4679 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4680 cur_params.dot11MeshHWMPactivePathTimeout) ||
4681 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4682 cur_params.dot11MeshHWMPpreqMinInterval) ||
4683 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4684 cur_params.dot11MeshHWMPperrMinInterval) ||
4685 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4686 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4687 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4688 cur_params.dot11MeshHWMPRootMode) ||
4689 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4690 cur_params.dot11MeshHWMPRannInterval) ||
4691 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4692 cur_params.dot11MeshGateAnnouncementProtocol) ||
4693 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4694 cur_params.dot11MeshForwarding) ||
4695 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004696 cur_params.rssi_threshold) ||
4697 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004698 cur_params.ht_opmode) ||
4699 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4700 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4701 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004702 cur_params.dot11MeshHWMProotInterval) ||
4703 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004704 cur_params.dot11MeshHWMPconfirmationInterval) ||
4705 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4706 cur_params.power_mode) ||
4707 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004708 cur_params.dot11MeshAwakeWindowDuration) ||
4709 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4710 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004711 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004712 nla_nest_end(msg, pinfoattr);
4713 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004714 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004715
Johannes Berg3b858752009-03-12 09:55:09 +01004716 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004717 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004718 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004719 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004720 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004721}
4722
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004723static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004724 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4725 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4726 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4727 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4728 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4729 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004730 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004731 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004732 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004733 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4734 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4735 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4736 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4737 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004738 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004739 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004740 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004741 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004742 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004743 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004744 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4745 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004746 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4747 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004748 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004749 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4750 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004751 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004752};
4753
Javier Cardonac80d5452010-12-16 17:37:49 -08004754static const struct nla_policy
4755 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004756 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004757 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4758 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004759 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004760 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004761 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004762 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004763 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004764 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004765};
4766
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004767static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004768 struct mesh_config *cfg,
4769 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004770{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004771 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004772 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004773
Marco Porschea54fba2013-01-07 16:04:48 +01004774#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4775do { \
4776 if (tb[attr]) { \
4777 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4778 return -EINVAL; \
4779 cfg->param = fn(tb[attr]); \
4780 mask |= (1 << (attr - 1)); \
4781 } \
4782} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004783
4784
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004785 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004786 return -EINVAL;
4787 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004788 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004789 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 return -EINVAL;
4791
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004792 /* This makes sure that there aren't more than 32 mesh config
4793 * parameters (otherwise our bitfield scheme would not work.) */
4794 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4795
4796 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004797 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004798 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4799 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004800 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004801 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4802 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004803 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004804 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4805 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004806 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004807 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4808 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004809 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004810 mask, NL80211_MESHCONF_MAX_RETRIES,
4811 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004812 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004813 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004814 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004815 mask, NL80211_MESHCONF_ELEMENT_TTL,
4816 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004817 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004818 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4819 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004820 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4821 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004822 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4823 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004824 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004825 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4826 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004827 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004828 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4829 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004830 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004831 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4832 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004833 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4834 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004835 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4836 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004837 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004838 1, 65535, mask,
4839 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004840 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004841 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004842 1, 65535, mask,
4843 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004844 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004845 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004846 dot11MeshHWMPnetDiameterTraversalTime,
4847 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004848 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4849 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004850 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4851 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4852 nla_get_u8);
4853 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4854 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004855 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004856 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004857 dot11MeshGateAnnouncementProtocol, 0, 1,
4858 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004859 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004860 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004861 mask, NL80211_MESHCONF_FORWARDING,
4862 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004863 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004864 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004865 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004866 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004867 mask, NL80211_MESHCONF_HT_OPMODE,
4868 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004869 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004870 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004871 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4872 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004873 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004874 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4875 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004876 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004877 dot11MeshHWMPconfirmationInterval,
4878 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004879 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4880 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4882 NL80211_MESH_POWER_ACTIVE,
4883 NL80211_MESH_POWER_MAX,
4884 mask, NL80211_MESHCONF_POWER_MODE,
4885 nla_get_u32);
4886 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4887 0, 65535, mask,
4888 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004889 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4890 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4891 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004892 if (mask_out)
4893 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004894
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004895 return 0;
4896
4897#undef FILL_IN_MESH_PARAM_IF_SET
4898}
4899
Javier Cardonac80d5452010-12-16 17:37:49 -08004900static int nl80211_parse_mesh_setup(struct genl_info *info,
4901 struct mesh_setup *setup)
4902{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004904 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4905
4906 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4907 return -EINVAL;
4908 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4909 info->attrs[NL80211_ATTR_MESH_SETUP],
4910 nl80211_mesh_setup_params_policy))
4911 return -EINVAL;
4912
Javier Cardonad299a1f2012-03-31 11:31:33 -07004913 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4914 setup->sync_method =
4915 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4916 IEEE80211_SYNC_METHOD_VENDOR :
4917 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4918
Javier Cardonac80d5452010-12-16 17:37:49 -08004919 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4920 setup->path_sel_proto =
4921 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4922 IEEE80211_PATH_PROTOCOL_VENDOR :
4923 IEEE80211_PATH_PROTOCOL_HWMP;
4924
4925 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4926 setup->path_metric =
4927 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4928 IEEE80211_PATH_METRIC_VENDOR :
4929 IEEE80211_PATH_METRIC_AIRTIME;
4930
Javier Cardona581a8b02011-04-07 15:08:27 -07004931
4932 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004933 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004934 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004935 if (!is_valid_ie_attr(ieattr))
4936 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004937 setup->ie = nla_data(ieattr);
4938 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004939 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004940 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4941 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4942 return -EINVAL;
4943 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004944 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4945 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004946 if (setup->is_secure)
4947 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004948
Colleen Twitty6e16d902013-05-08 11:45:59 -07004949 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4950 if (!setup->user_mpm)
4951 return -EINVAL;
4952 setup->auth_id =
4953 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4954 }
4955
Javier Cardonac80d5452010-12-16 17:37:49 -08004956 return 0;
4957}
4958
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004959static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004960 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004961{
4962 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4963 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004964 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004965 struct mesh_config cfg;
4966 u32 mask;
4967 int err;
4968
Johannes Berg29cbe682010-12-03 09:20:44 +01004969 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4970 return -EOPNOTSUPP;
4971
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004972 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004973 return -EOPNOTSUPP;
4974
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004975 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004976 if (err)
4977 return err;
4978
Johannes Berg29cbe682010-12-03 09:20:44 +01004979 wdev_lock(wdev);
4980 if (!wdev->mesh_id_len)
4981 err = -ENOLINK;
4982
4983 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004984 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004985
4986 wdev_unlock(wdev);
4987
4988 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004989}
4990
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004991static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4992{
Johannes Berg458f4f92012-12-06 15:47:38 +01004993 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004994 struct sk_buff *msg;
4995 void *hdr = NULL;
4996 struct nlattr *nl_reg_rules;
4997 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004998
4999 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005000 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005001
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005003 if (!msg)
5004 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005005
Eric W. Biederman15e47302012-09-07 20:12:54 +00005006 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005007 NL80211_CMD_GET_REG);
5008 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005009 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005010
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005011 if (reg_last_request_cell_base() &&
5012 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5013 NL80211_USER_REG_HINT_CELL_BASE))
5014 goto nla_put_failure;
5015
Johannes Berg458f4f92012-12-06 15:47:38 +01005016 rcu_read_lock();
5017 regdom = rcu_dereference(cfg80211_regdomain);
5018
5019 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5020 (regdom->dfs_region &&
5021 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5022 goto nla_put_failure_rcu;
5023
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005024 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5025 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005026 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005027
Johannes Berg458f4f92012-12-06 15:47:38 +01005028 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005029 struct nlattr *nl_reg_rule;
5030 const struct ieee80211_reg_rule *reg_rule;
5031 const struct ieee80211_freq_range *freq_range;
5032 const struct ieee80211_power_rule *power_rule;
5033
Johannes Berg458f4f92012-12-06 15:47:38 +01005034 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005035 freq_range = &reg_rule->freq_range;
5036 power_rule = &reg_rule->power_rule;
5037
5038 nl_reg_rule = nla_nest_start(msg, i);
5039 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005040 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005041
David S. Miller9360ffd2012-03-29 04:41:26 -04005042 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5043 reg_rule->flags) ||
5044 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5045 freq_range->start_freq_khz) ||
5046 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5047 freq_range->end_freq_khz) ||
5048 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5049 freq_range->max_bandwidth_khz) ||
5050 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5051 power_rule->max_antenna_gain) ||
5052 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5053 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005054 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005055
5056 nla_nest_end(msg, nl_reg_rule);
5057 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005058 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005059
5060 nla_nest_end(msg, nl_reg_rules);
5061
5062 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005063 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005064
Johannes Berg458f4f92012-12-06 15:47:38 +01005065nla_put_failure_rcu:
5066 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005067nla_put_failure:
5068 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005069put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005070 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005071 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005072}
5073
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005074static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5075{
5076 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5077 struct nlattr *nl_reg_rule;
5078 char *alpha2 = NULL;
5079 int rem_reg_rules = 0, r = 0;
5080 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005081 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005082 struct ieee80211_regdomain *rd = NULL;
5083
5084 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5085 return -EINVAL;
5086
5087 if (!info->attrs[NL80211_ATTR_REG_RULES])
5088 return -EINVAL;
5089
5090 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5091
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005092 if (info->attrs[NL80211_ATTR_DFS_REGION])
5093 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5094
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005095 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005096 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005097 num_rules++;
5098 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005099 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005100 }
5101
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005102 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005103 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005104
5105 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005106 if (!rd)
5107 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005108
5109 rd->n_reg_rules = num_rules;
5110 rd->alpha2[0] = alpha2[0];
5111 rd->alpha2[1] = alpha2[1];
5112
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005113 /*
5114 * Disable DFS master mode if the DFS region was
5115 * not supported or known on this kernel.
5116 */
5117 if (reg_supported_dfs_region(dfs_region))
5118 rd->dfs_region = dfs_region;
5119
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005120 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005121 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005122 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005123 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5124 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005125 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5126 if (r)
5127 goto bad_reg;
5128
5129 rule_idx++;
5130
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005131 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5132 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005133 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005134 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005135 }
5136
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005137 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005138 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005139 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005140
Johannes Bergd2372b32008-10-24 20:32:20 +02005141 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005142 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005143 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005144}
5145
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005146static int validate_scan_freqs(struct nlattr *freqs)
5147{
5148 struct nlattr *attr1, *attr2;
5149 int n_channels = 0, tmp1, tmp2;
5150
5151 nla_for_each_nested(attr1, freqs, tmp1) {
5152 n_channels++;
5153 /*
5154 * Some hardware has a limited channel list for
5155 * scanning, and it is pretty much nonsensical
5156 * to scan for a channel twice, so disallow that
5157 * and don't require drivers to check that the
5158 * channel list they get isn't longer than what
5159 * they can scan, as long as they can scan all
5160 * the channels they registered at once.
5161 */
5162 nla_for_each_nested(attr2, freqs, tmp2)
5163 if (attr1 != attr2 &&
5164 nla_get_u32(attr1) == nla_get_u32(attr2))
5165 return 0;
5166 }
5167
5168 return n_channels;
5169}
5170
Johannes Berg2a519312009-02-10 21:25:55 +01005171static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5172{
Johannes Berg4c476992010-10-04 21:36:35 +02005173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005174 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005175 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005176 struct nlattr *attr;
5177 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005178 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005179 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005180
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005181 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5182 return -EINVAL;
5183
Johannes Berg79c97e92009-07-07 03:56:12 +02005184 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005185
Johannes Berg4c476992010-10-04 21:36:35 +02005186 if (!rdev->ops->scan)
5187 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005188
Johannes Bergf9f47522013-03-19 15:04:07 +01005189 if (rdev->scan_req) {
5190 err = -EBUSY;
5191 goto unlock;
5192 }
Johannes Berg2a519312009-02-10 21:25:55 +01005193
5194 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005195 n_channels = validate_scan_freqs(
5196 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005197 if (!n_channels) {
5198 err = -EINVAL;
5199 goto unlock;
5200 }
Johannes Berg2a519312009-02-10 21:25:55 +01005201 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005202 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005203 n_channels = 0;
5204
Johannes Berg2a519312009-02-10 21:25:55 +01005205 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5206 if (wiphy->bands[band])
5207 n_channels += wiphy->bands[band]->n_channels;
5208 }
5209
5210 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5211 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5212 n_ssids++;
5213
Johannes Bergf9f47522013-03-19 15:04:07 +01005214 if (n_ssids > wiphy->max_scan_ssids) {
5215 err = -EINVAL;
5216 goto unlock;
5217 }
Johannes Berg2a519312009-02-10 21:25:55 +01005218
Jouni Malinen70692ad2009-02-16 19:39:13 +02005219 if (info->attrs[NL80211_ATTR_IE])
5220 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5221 else
5222 ie_len = 0;
5223
Johannes Bergf9f47522013-03-19 15:04:07 +01005224 if (ie_len > wiphy->max_scan_ie_len) {
5225 err = -EINVAL;
5226 goto unlock;
5227 }
Johannes Berg18a83652009-03-31 12:12:05 +02005228
Johannes Berg2a519312009-02-10 21:25:55 +01005229 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005230 + sizeof(*request->ssids) * n_ssids
5231 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005232 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005233 if (!request) {
5234 err = -ENOMEM;
5235 goto unlock;
5236 }
Johannes Berg2a519312009-02-10 21:25:55 +01005237
Johannes Berg2a519312009-02-10 21:25:55 +01005238 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005239 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005240 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005241 if (ie_len) {
5242 if (request->ssids)
5243 request->ie = (void *)(request->ssids + n_ssids);
5244 else
5245 request->ie = (void *)(request->channels + n_channels);
5246 }
Johannes Berg2a519312009-02-10 21:25:55 +01005247
Johannes Berg584991d2009-11-02 13:32:03 +01005248 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005249 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5250 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005251 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005252 struct ieee80211_channel *chan;
5253
5254 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5255
5256 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005257 err = -EINVAL;
5258 goto out_free;
5259 }
Johannes Berg584991d2009-11-02 13:32:03 +01005260
5261 /* ignore disabled channels */
5262 if (chan->flags & IEEE80211_CHAN_DISABLED)
5263 continue;
5264
5265 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005266 i++;
5267 }
5268 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005269 enum ieee80211_band band;
5270
Johannes Berg2a519312009-02-10 21:25:55 +01005271 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005272 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5273 int j;
5274 if (!wiphy->bands[band])
5275 continue;
5276 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005277 struct ieee80211_channel *chan;
5278
5279 chan = &wiphy->bands[band]->channels[j];
5280
5281 if (chan->flags & IEEE80211_CHAN_DISABLED)
5282 continue;
5283
5284 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005285 i++;
5286 }
5287 }
5288 }
5289
Johannes Berg584991d2009-11-02 13:32:03 +01005290 if (!i) {
5291 err = -EINVAL;
5292 goto out_free;
5293 }
5294
5295 request->n_channels = i;
5296
Johannes Berg2a519312009-02-10 21:25:55 +01005297 i = 0;
5298 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5299 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005300 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005301 err = -EINVAL;
5302 goto out_free;
5303 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005304 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005305 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005306 i++;
5307 }
5308 }
5309
Jouni Malinen70692ad2009-02-16 19:39:13 +02005310 if (info->attrs[NL80211_ATTR_IE]) {
5311 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005312 memcpy((void *)request->ie,
5313 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005314 request->ie_len);
5315 }
5316
Johannes Berg34850ab2011-07-18 18:08:35 +02005317 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005318 if (wiphy->bands[i])
5319 request->rates[i] =
5320 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005321
5322 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5323 nla_for_each_nested(attr,
5324 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5325 tmp) {
5326 enum ieee80211_band band = nla_type(attr);
5327
Dan Carpenter84404622011-07-29 11:52:18 +03005328 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005329 err = -EINVAL;
5330 goto out_free;
5331 }
5332 err = ieee80211_get_ratemask(wiphy->bands[band],
5333 nla_data(attr),
5334 nla_len(attr),
5335 &request->rates[band]);
5336 if (err)
5337 goto out_free;
5338 }
5339 }
5340
Sam Leffler46856bb2012-10-11 21:03:32 -07005341 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005342 request->flags = nla_get_u32(
5343 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005344 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5345 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5346 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5347 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005348 err = -EOPNOTSUPP;
5349 goto out_free;
5350 }
5351 }
Sam Lefflered4737712012-10-11 21:03:31 -07005352
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305353 request->no_cck =
5354 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5355
Johannes Bergfd014282012-06-18 19:17:03 +02005356 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005357 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005358 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005359
Johannes Berg79c97e92009-07-07 03:56:12 +02005360 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005361 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005362
Johannes Berg463d0182009-07-14 00:33:35 +02005363 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005364 nl80211_send_scan_start(rdev, wdev);
5365 if (wdev->netdev)
5366 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005367 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005368 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005369 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005370 kfree(request);
5371 }
Johannes Berg3b858752009-03-12 09:55:09 +01005372
Johannes Bergf9f47522013-03-19 15:04:07 +01005373 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005374 return err;
5375}
5376
Luciano Coelho807f8a82011-05-11 17:09:35 +03005377static int nl80211_start_sched_scan(struct sk_buff *skb,
5378 struct genl_info *info)
5379{
5380 struct cfg80211_sched_scan_request *request;
5381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5382 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005383 struct nlattr *attr;
5384 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005385 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005386 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005387 enum ieee80211_band band;
5388 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005389 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005390
5391 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5392 !rdev->ops->sched_scan_start)
5393 return -EOPNOTSUPP;
5394
5395 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5396 return -EINVAL;
5397
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005398 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5399 return -EINVAL;
5400
5401 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5402 if (interval == 0)
5403 return -EINVAL;
5404
Luciano Coelho807f8a82011-05-11 17:09:35 +03005405 wiphy = &rdev->wiphy;
5406
5407 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5408 n_channels = validate_scan_freqs(
5409 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5410 if (!n_channels)
5411 return -EINVAL;
5412 } else {
5413 n_channels = 0;
5414
5415 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5416 if (wiphy->bands[band])
5417 n_channels += wiphy->bands[band]->n_channels;
5418 }
5419
5420 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5421 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5422 tmp)
5423 n_ssids++;
5424
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005425 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005426 return -EINVAL;
5427
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005428 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5429 nla_for_each_nested(attr,
5430 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5431 tmp)
5432 n_match_sets++;
5433
5434 if (n_match_sets > wiphy->max_match_sets)
5435 return -EINVAL;
5436
Luciano Coelho807f8a82011-05-11 17:09:35 +03005437 if (info->attrs[NL80211_ATTR_IE])
5438 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5439 else
5440 ie_len = 0;
5441
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005442 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005443 return -EINVAL;
5444
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005445 if (rdev->sched_scan_req) {
5446 err = -EINPROGRESS;
5447 goto out;
5448 }
5449
Luciano Coelho807f8a82011-05-11 17:09:35 +03005450 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005451 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005452 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005453 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005454 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005455 if (!request) {
5456 err = -ENOMEM;
5457 goto out;
5458 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005459
5460 if (n_ssids)
5461 request->ssids = (void *)&request->channels[n_channels];
5462 request->n_ssids = n_ssids;
5463 if (ie_len) {
5464 if (request->ssids)
5465 request->ie = (void *)(request->ssids + n_ssids);
5466 else
5467 request->ie = (void *)(request->channels + n_channels);
5468 }
5469
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005470 if (n_match_sets) {
5471 if (request->ie)
5472 request->match_sets = (void *)(request->ie + ie_len);
5473 else if (request->ssids)
5474 request->match_sets =
5475 (void *)(request->ssids + n_ssids);
5476 else
5477 request->match_sets =
5478 (void *)(request->channels + n_channels);
5479 }
5480 request->n_match_sets = n_match_sets;
5481
Luciano Coelho807f8a82011-05-11 17:09:35 +03005482 i = 0;
5483 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5484 /* user specified, bail out if channel not found */
5485 nla_for_each_nested(attr,
5486 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5487 tmp) {
5488 struct ieee80211_channel *chan;
5489
5490 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5491
5492 if (!chan) {
5493 err = -EINVAL;
5494 goto out_free;
5495 }
5496
5497 /* ignore disabled channels */
5498 if (chan->flags & IEEE80211_CHAN_DISABLED)
5499 continue;
5500
5501 request->channels[i] = chan;
5502 i++;
5503 }
5504 } else {
5505 /* all channels */
5506 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5507 int j;
5508 if (!wiphy->bands[band])
5509 continue;
5510 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5511 struct ieee80211_channel *chan;
5512
5513 chan = &wiphy->bands[band]->channels[j];
5514
5515 if (chan->flags & IEEE80211_CHAN_DISABLED)
5516 continue;
5517
5518 request->channels[i] = chan;
5519 i++;
5520 }
5521 }
5522 }
5523
5524 if (!i) {
5525 err = -EINVAL;
5526 goto out_free;
5527 }
5528
5529 request->n_channels = i;
5530
5531 i = 0;
5532 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5533 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5534 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005535 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005536 err = -EINVAL;
5537 goto out_free;
5538 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005539 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005540 memcpy(request->ssids[i].ssid, nla_data(attr),
5541 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005542 i++;
5543 }
5544 }
5545
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005546 i = 0;
5547 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5548 nla_for_each_nested(attr,
5549 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5550 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005551 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005552
5553 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5554 nla_data(attr), nla_len(attr),
5555 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005556 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005557 if (ssid) {
5558 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5559 err = -EINVAL;
5560 goto out_free;
5561 }
5562 memcpy(request->match_sets[i].ssid.ssid,
5563 nla_data(ssid), nla_len(ssid));
5564 request->match_sets[i].ssid.ssid_len =
5565 nla_len(ssid);
5566 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005567 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5568 if (rssi)
5569 request->rssi_thold = nla_get_u32(rssi);
5570 else
5571 request->rssi_thold =
5572 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005573 i++;
5574 }
5575 }
5576
Luciano Coelho807f8a82011-05-11 17:09:35 +03005577 if (info->attrs[NL80211_ATTR_IE]) {
5578 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5579 memcpy((void *)request->ie,
5580 nla_data(info->attrs[NL80211_ATTR_IE]),
5581 request->ie_len);
5582 }
5583
Sam Leffler46856bb2012-10-11 21:03:32 -07005584 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005585 request->flags = nla_get_u32(
5586 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005587 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5588 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5589 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5590 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005591 err = -EOPNOTSUPP;
5592 goto out_free;
5593 }
5594 }
Sam Lefflered4737712012-10-11 21:03:31 -07005595
Luciano Coelho807f8a82011-05-11 17:09:35 +03005596 request->dev = dev;
5597 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005598 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005599 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005600
Hila Gonene35e4d22012-06-27 17:19:42 +03005601 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005602 if (!err) {
5603 rdev->sched_scan_req = request;
5604 nl80211_send_sched_scan(rdev, dev,
5605 NL80211_CMD_START_SCHED_SCAN);
5606 goto out;
5607 }
5608
5609out_free:
5610 kfree(request);
5611out:
5612 return err;
5613}
5614
5615static int nl80211_stop_sched_scan(struct sk_buff *skb,
5616 struct genl_info *info)
5617{
5618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5619
5620 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5621 !rdev->ops->sched_scan_stop)
5622 return -EOPNOTSUPP;
5623
Johannes Berg5fe231e2013-05-08 21:45:15 +02005624 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005625}
5626
Simon Wunderlich04f39042013-02-08 18:16:19 +01005627static int nl80211_start_radar_detection(struct sk_buff *skb,
5628 struct genl_info *info)
5629{
5630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5631 struct net_device *dev = info->user_ptr[1];
5632 struct wireless_dev *wdev = dev->ieee80211_ptr;
5633 struct cfg80211_chan_def chandef;
5634 int err;
5635
5636 err = nl80211_parse_chandef(rdev, info, &chandef);
5637 if (err)
5638 return err;
5639
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005640 if (netif_carrier_ok(dev))
5641 return -EBUSY;
5642
Simon Wunderlich04f39042013-02-08 18:16:19 +01005643 if (wdev->cac_started)
5644 return -EBUSY;
5645
5646 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5647 if (err < 0)
5648 return err;
5649
5650 if (err == 0)
5651 return -EINVAL;
5652
5653 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5654 return -EINVAL;
5655
5656 if (!rdev->ops->start_radar_detection)
5657 return -EOPNOTSUPP;
5658
Simon Wunderlich04f39042013-02-08 18:16:19 +01005659 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5660 chandef.chan, CHAN_MODE_SHARED,
5661 BIT(chandef.width));
5662 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005663 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005664
5665 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5666 if (!err) {
5667 wdev->channel = chandef.chan;
5668 wdev->cac_started = true;
5669 wdev->cac_start_time = jiffies;
5670 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005671 return err;
5672}
5673
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005674static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5675{
5676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5677 struct net_device *dev = info->user_ptr[1];
5678 struct wireless_dev *wdev = dev->ieee80211_ptr;
5679 struct cfg80211_csa_settings params;
5680 /* csa_attrs is defined static to avoid waste of stack size - this
5681 * function is called under RTNL lock, so this should not be a problem.
5682 */
5683 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5684 u8 radar_detect_width = 0;
5685 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005686 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005687
5688 if (!rdev->ops->channel_switch ||
5689 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5690 return -EOPNOTSUPP;
5691
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005692 switch (dev->ieee80211_ptr->iftype) {
5693 case NL80211_IFTYPE_AP:
5694 case NL80211_IFTYPE_P2P_GO:
5695 need_new_beacon = true;
5696
5697 /* useless if AP is not running */
5698 if (!wdev->beacon_interval)
5699 return -EINVAL;
5700 break;
5701 case NL80211_IFTYPE_ADHOC:
5702 break;
5703 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005704 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005705 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005706
5707 memset(&params, 0, sizeof(params));
5708
5709 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5710 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5711 return -EINVAL;
5712
5713 /* only important for AP, IBSS and mesh create IEs internally */
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005714 if (need_new_beacon &&
5715 (!info->attrs[NL80211_ATTR_CSA_IES] ||
5716 !info->attrs[NL80211_ATTR_CSA_C_OFF_BEACON]))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005717 return -EINVAL;
5718
5719 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5720
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005721 if (!need_new_beacon)
5722 goto skip_beacons;
5723
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005724 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5725 if (err)
5726 return err;
5727
5728 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5729 info->attrs[NL80211_ATTR_CSA_IES],
5730 nl80211_policy);
5731 if (err)
5732 return err;
5733
5734 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5735 if (err)
5736 return err;
5737
5738 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5739 return -EINVAL;
5740
5741 params.counter_offset_beacon =
5742 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5743 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5744 return -EINVAL;
5745
5746 /* sanity check - counters should be the same */
5747 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5748 params.count)
5749 return -EINVAL;
5750
5751 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5752 params.counter_offset_presp =
5753 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5754 if (params.counter_offset_presp >=
5755 params.beacon_csa.probe_resp_len)
5756 return -EINVAL;
5757
5758 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5759 params.count)
5760 return -EINVAL;
5761 }
5762
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005763skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005764 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5765 if (err)
5766 return err;
5767
5768 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5769 return -EINVAL;
5770
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005771 /* DFS channels are only supported for AP/P2P GO ... for now. */
5772 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
5773 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO) {
5774 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5775 &params.chandef);
5776 if (err < 0) {
5777 return err;
5778 } else if (err) {
5779 radar_detect_width = BIT(params.chandef.width);
5780 params.radar_required = true;
5781 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005782 }
5783
5784 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5785 params.chandef.chan,
5786 CHAN_MODE_SHARED,
5787 radar_detect_width);
5788 if (err)
5789 return err;
5790
5791 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5792 params.block_tx = true;
5793
5794 return rdev_channel_switch(rdev, dev, &params);
5795}
5796
Johannes Berg9720bb32011-06-21 09:45:33 +02005797static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5798 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005799 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005800 struct wireless_dev *wdev,
5801 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005802{
Johannes Berg48ab9052009-07-10 18:42:31 +02005803 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005804 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005805 void *hdr;
5806 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005807 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005808
5809 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005810
Eric W. Biederman15e47302012-09-07 20:12:54 +00005811 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005812 NL80211_CMD_NEW_SCAN_RESULTS);
5813 if (!hdr)
5814 return -1;
5815
Johannes Berg9720bb32011-06-21 09:45:33 +02005816 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5817
Johannes Berg97990a02013-04-19 01:02:55 +02005818 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5819 goto nla_put_failure;
5820 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005821 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5822 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005823 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5824 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005825
5826 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5827 if (!bss)
5828 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005829 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005830 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005831 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005832
5833 rcu_read_lock();
5834 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005835 if (ies) {
5836 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5837 goto fail_unlock_rcu;
5838 tsf = true;
5839 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5840 ies->len, ies->data))
5841 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005842 }
5843 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005844 if (ies) {
5845 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5846 goto fail_unlock_rcu;
5847 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5848 ies->len, ies->data))
5849 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005850 }
5851 rcu_read_unlock();
5852
David S. Miller9360ffd2012-03-29 04:41:26 -04005853 if (res->beacon_interval &&
5854 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5855 goto nla_put_failure;
5856 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5857 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005858 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005859 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5860 jiffies_to_msecs(jiffies - intbss->ts)))
5861 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005862
Johannes Berg77965c92009-02-18 18:45:06 +01005863 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005864 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005865 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5866 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005867 break;
5868 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005869 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5870 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005871 break;
5872 default:
5873 break;
5874 }
5875
Johannes Berg48ab9052009-07-10 18:42:31 +02005876 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005877 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005878 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005879 if (intbss == wdev->current_bss &&
5880 nla_put_u32(msg, NL80211_BSS_STATUS,
5881 NL80211_BSS_STATUS_ASSOCIATED))
5882 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005883 break;
5884 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005885 if (intbss == wdev->current_bss &&
5886 nla_put_u32(msg, NL80211_BSS_STATUS,
5887 NL80211_BSS_STATUS_IBSS_JOINED))
5888 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005889 break;
5890 default:
5891 break;
5892 }
5893
Johannes Berg2a519312009-02-10 21:25:55 +01005894 nla_nest_end(msg, bss);
5895
5896 return genlmsg_end(msg, hdr);
5897
Johannes Berg8cef2c92013-02-05 16:54:31 +01005898 fail_unlock_rcu:
5899 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005900 nla_put_failure:
5901 genlmsg_cancel(msg, hdr);
5902 return -EMSGSIZE;
5903}
5904
Johannes Berg97990a02013-04-19 01:02:55 +02005905static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005906{
Johannes Berg48ab9052009-07-10 18:42:31 +02005907 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005908 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005909 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005910 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005911 int err;
5912
Johannes Berg97990a02013-04-19 01:02:55 +02005913 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005914 if (err)
5915 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005916
Johannes Berg48ab9052009-07-10 18:42:31 +02005917 wdev_lock(wdev);
5918 spin_lock_bh(&rdev->bss_lock);
5919 cfg80211_bss_expire(rdev);
5920
Johannes Berg9720bb32011-06-21 09:45:33 +02005921 cb->seq = rdev->bss_generation;
5922
Johannes Berg48ab9052009-07-10 18:42:31 +02005923 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005924 if (++idx <= start)
5925 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005926 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005927 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005928 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005929 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005930 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005931 }
5932 }
5933
Johannes Berg48ab9052009-07-10 18:42:31 +02005934 spin_unlock_bh(&rdev->bss_lock);
5935 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005936
Johannes Berg97990a02013-04-19 01:02:55 +02005937 cb->args[2] = idx;
5938 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005939
Johannes Berg67748892010-10-04 21:14:06 +02005940 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005941}
5942
Eric W. Biederman15e47302012-09-07 20:12:54 +00005943static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005944 int flags, struct net_device *dev,
5945 struct survey_info *survey)
5946{
5947 void *hdr;
5948 struct nlattr *infoattr;
5949
Eric W. Biederman15e47302012-09-07 20:12:54 +00005950 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005951 NL80211_CMD_NEW_SURVEY_RESULTS);
5952 if (!hdr)
5953 return -ENOMEM;
5954
David S. Miller9360ffd2012-03-29 04:41:26 -04005955 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5956 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005957
5958 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5959 if (!infoattr)
5960 goto nla_put_failure;
5961
David S. Miller9360ffd2012-03-29 04:41:26 -04005962 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5963 survey->channel->center_freq))
5964 goto nla_put_failure;
5965
5966 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5967 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5968 goto nla_put_failure;
5969 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5970 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5971 goto nla_put_failure;
5972 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5973 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5974 survey->channel_time))
5975 goto nla_put_failure;
5976 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5977 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5978 survey->channel_time_busy))
5979 goto nla_put_failure;
5980 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5981 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5982 survey->channel_time_ext_busy))
5983 goto nla_put_failure;
5984 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5985 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5986 survey->channel_time_rx))
5987 goto nla_put_failure;
5988 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5989 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5990 survey->channel_time_tx))
5991 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005992
5993 nla_nest_end(msg, infoattr);
5994
5995 return genlmsg_end(msg, hdr);
5996
5997 nla_put_failure:
5998 genlmsg_cancel(msg, hdr);
5999 return -EMSGSIZE;
6000}
6001
6002static int nl80211_dump_survey(struct sk_buff *skb,
6003 struct netlink_callback *cb)
6004{
6005 struct survey_info survey;
6006 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006007 struct wireless_dev *wdev;
6008 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006009 int res;
6010
Johannes Berg97990a02013-04-19 01:02:55 +02006011 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006012 if (res)
6013 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006014
Johannes Berg97990a02013-04-19 01:02:55 +02006015 if (!wdev->netdev) {
6016 res = -EINVAL;
6017 goto out_err;
6018 }
6019
Holger Schurig61fa7132009-11-11 12:25:40 +01006020 if (!dev->ops->dump_survey) {
6021 res = -EOPNOTSUPP;
6022 goto out_err;
6023 }
6024
6025 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006026 struct ieee80211_channel *chan;
6027
Johannes Berg97990a02013-04-19 01:02:55 +02006028 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006029 if (res == -ENOENT)
6030 break;
6031 if (res)
6032 goto out_err;
6033
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006034 /* Survey without a channel doesn't make sense */
6035 if (!survey.channel) {
6036 res = -EINVAL;
6037 goto out;
6038 }
6039
6040 chan = ieee80211_get_channel(&dev->wiphy,
6041 survey.channel->center_freq);
6042 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6043 survey_idx++;
6044 continue;
6045 }
6046
Holger Schurig61fa7132009-11-11 12:25:40 +01006047 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006048 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006049 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006050 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006051 goto out;
6052 survey_idx++;
6053 }
6054
6055 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006056 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006057 res = skb->len;
6058 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006059 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006060 return res;
6061}
6062
Samuel Ortizb23aa672009-07-01 21:26:54 +02006063static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6064{
6065 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6066 NL80211_WPA_VERSION_2));
6067}
6068
Jouni Malinen636a5d32009-03-19 13:39:22 +02006069static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6070{
Johannes Berg4c476992010-10-04 21:36:35 +02006071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6072 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006073 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006074 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6075 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006076 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006077 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006078 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006079
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006080 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6081 return -EINVAL;
6082
6083 if (!info->attrs[NL80211_ATTR_MAC])
6084 return -EINVAL;
6085
Jouni Malinen17780922009-03-27 20:52:47 +02006086 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6087 return -EINVAL;
6088
Johannes Berg19957bb2009-07-02 17:20:43 +02006089 if (!info->attrs[NL80211_ATTR_SSID])
6090 return -EINVAL;
6091
6092 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6093 return -EINVAL;
6094
Johannes Bergfffd0932009-07-08 14:22:54 +02006095 err = nl80211_parse_key(info, &key);
6096 if (err)
6097 return err;
6098
6099 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006100 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6101 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006102 if (!key.p.key || !key.p.key_len)
6103 return -EINVAL;
6104 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6105 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6106 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6107 key.p.key_len != WLAN_KEY_LEN_WEP104))
6108 return -EINVAL;
6109 if (key.idx > 4)
6110 return -EINVAL;
6111 } else {
6112 key.p.key_len = 0;
6113 key.p.key = NULL;
6114 }
6115
Johannes Bergafea0b72010-08-10 09:46:42 +02006116 if (key.idx >= 0) {
6117 int i;
6118 bool ok = false;
6119 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6120 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6121 ok = true;
6122 break;
6123 }
6124 }
Johannes Berg4c476992010-10-04 21:36:35 +02006125 if (!ok)
6126 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006127 }
6128
Johannes Berg4c476992010-10-04 21:36:35 +02006129 if (!rdev->ops->auth)
6130 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006131
Johannes Berg074ac8d2010-09-16 14:58:22 +02006132 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006133 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6134 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006135
Johannes Berg19957bb2009-07-02 17:20:43 +02006136 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006137 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006138 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006139 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6140 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006141
Johannes Berg19957bb2009-07-02 17:20:43 +02006142 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6143 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6144
6145 if (info->attrs[NL80211_ATTR_IE]) {
6146 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6147 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6148 }
6149
6150 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006151 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006152 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006153
Jouni Malinene39e5b52012-09-30 19:29:39 +03006154 if (auth_type == NL80211_AUTHTYPE_SAE &&
6155 !info->attrs[NL80211_ATTR_SAE_DATA])
6156 return -EINVAL;
6157
6158 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6159 if (auth_type != NL80211_AUTHTYPE_SAE)
6160 return -EINVAL;
6161 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6162 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6163 /* need to include at least Auth Transaction and Status Code */
6164 if (sae_data_len < 4)
6165 return -EINVAL;
6166 }
6167
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006168 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6169
Johannes Berg95de8172012-01-20 13:55:25 +01006170 /*
6171 * Since we no longer track auth state, ignore
6172 * requests to only change local state.
6173 */
6174 if (local_state_change)
6175 return 0;
6176
Johannes Berg91bf9b22013-05-15 17:44:01 +02006177 wdev_lock(dev->ieee80211_ptr);
6178 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6179 ssid, ssid_len, ie, ie_len,
6180 key.p.key, key.p.key_len, key.idx,
6181 sae_data, sae_data_len);
6182 wdev_unlock(dev->ieee80211_ptr);
6183 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006184}
6185
Johannes Bergc0692b82010-08-27 14:26:53 +03006186static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6187 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006188 struct cfg80211_crypto_settings *settings,
6189 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006190{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006191 memset(settings, 0, sizeof(*settings));
6192
Samuel Ortizb23aa672009-07-01 21:26:54 +02006193 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6194
Johannes Bergc0692b82010-08-27 14:26:53 +03006195 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6196 u16 proto;
6197 proto = nla_get_u16(
6198 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6199 settings->control_port_ethertype = cpu_to_be16(proto);
6200 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6201 proto != ETH_P_PAE)
6202 return -EINVAL;
6203 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6204 settings->control_port_no_encrypt = true;
6205 } else
6206 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6207
Samuel Ortizb23aa672009-07-01 21:26:54 +02006208 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6209 void *data;
6210 int len, i;
6211
6212 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6213 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6214 settings->n_ciphers_pairwise = len / sizeof(u32);
6215
6216 if (len % sizeof(u32))
6217 return -EINVAL;
6218
Johannes Berg3dc27d22009-07-02 21:36:37 +02006219 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006220 return -EINVAL;
6221
6222 memcpy(settings->ciphers_pairwise, data, len);
6223
6224 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006225 if (!cfg80211_supported_cipher_suite(
6226 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006227 settings->ciphers_pairwise[i]))
6228 return -EINVAL;
6229 }
6230
6231 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6232 settings->cipher_group =
6233 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006234 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6235 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006236 return -EINVAL;
6237 }
6238
6239 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6240 settings->wpa_versions =
6241 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6242 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6243 return -EINVAL;
6244 }
6245
6246 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6247 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006248 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006249
6250 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6251 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6252 settings->n_akm_suites = len / sizeof(u32);
6253
6254 if (len % sizeof(u32))
6255 return -EINVAL;
6256
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006257 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6258 return -EINVAL;
6259
Samuel Ortizb23aa672009-07-01 21:26:54 +02006260 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006261 }
6262
6263 return 0;
6264}
6265
Jouni Malinen636a5d32009-03-19 13:39:22 +02006266static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6267{
Johannes Berg4c476992010-10-04 21:36:35 +02006268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6269 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006270 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006271 struct cfg80211_assoc_request req = {};
6272 const u8 *bssid, *ssid;
6273 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006274
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006275 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6276 return -EINVAL;
6277
6278 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006279 !info->attrs[NL80211_ATTR_SSID] ||
6280 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006281 return -EINVAL;
6282
Johannes Berg4c476992010-10-04 21:36:35 +02006283 if (!rdev->ops->assoc)
6284 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006285
Johannes Berg074ac8d2010-09-16 14:58:22 +02006286 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006287 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6288 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006289
Johannes Berg19957bb2009-07-02 17:20:43 +02006290 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006291
Johannes Berg19957bb2009-07-02 17:20:43 +02006292 chan = ieee80211_get_channel(&rdev->wiphy,
6293 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006294 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6295 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006296
Johannes Berg19957bb2009-07-02 17:20:43 +02006297 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6298 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006299
6300 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006301 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6302 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006303 }
6304
Jouni Malinendc6382c2009-05-06 22:09:37 +03006305 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006306 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006307 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006308 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006309 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006310 else if (mfp != NL80211_MFP_NO)
6311 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006312 }
6313
Johannes Berg3e5d7642009-07-07 14:37:26 +02006314 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006315 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006316
Ben Greear7e7c8922011-11-18 11:31:59 -08006317 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006318 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006319
6320 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006321 memcpy(&req.ht_capa_mask,
6322 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6323 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006324
6325 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006326 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006327 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006328 memcpy(&req.ht_capa,
6329 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6330 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006331 }
6332
Johannes Bergee2aca32013-02-21 17:36:01 +01006333 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006334 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006335
6336 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006337 memcpy(&req.vht_capa_mask,
6338 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6339 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006340
6341 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006342 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006343 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006344 memcpy(&req.vht_capa,
6345 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6346 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006347 }
6348
Johannes Bergf62fab72013-02-21 20:09:09 +01006349 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006350 if (!err) {
6351 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006352 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6353 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006354 wdev_unlock(dev->ieee80211_ptr);
6355 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006356
Jouni Malinen636a5d32009-03-19 13:39:22 +02006357 return err;
6358}
6359
6360static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6361{
Johannes Berg4c476992010-10-04 21:36:35 +02006362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6363 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006364 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006365 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006366 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006367 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006368
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006369 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6370 return -EINVAL;
6371
6372 if (!info->attrs[NL80211_ATTR_MAC])
6373 return -EINVAL;
6374
6375 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6376 return -EINVAL;
6377
Johannes Berg4c476992010-10-04 21:36:35 +02006378 if (!rdev->ops->deauth)
6379 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006380
Johannes Berg074ac8d2010-09-16 14:58:22 +02006381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006382 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6383 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006384
Johannes Berg19957bb2009-07-02 17:20:43 +02006385 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006386
Johannes Berg19957bb2009-07-02 17:20:43 +02006387 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6388 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006389 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006390 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006391 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006392
6393 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006394 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6395 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006396 }
6397
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006398 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6399
Johannes Berg91bf9b22013-05-15 17:44:01 +02006400 wdev_lock(dev->ieee80211_ptr);
6401 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6402 local_state_change);
6403 wdev_unlock(dev->ieee80211_ptr);
6404 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006405}
6406
6407static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6408{
Johannes Berg4c476992010-10-04 21:36:35 +02006409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6410 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006411 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006412 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006413 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006414 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006415
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006416 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6417 return -EINVAL;
6418
6419 if (!info->attrs[NL80211_ATTR_MAC])
6420 return -EINVAL;
6421
6422 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6423 return -EINVAL;
6424
Johannes Berg4c476992010-10-04 21:36:35 +02006425 if (!rdev->ops->disassoc)
6426 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006427
Johannes Berg074ac8d2010-09-16 14:58:22 +02006428 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006429 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6430 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006431
Johannes Berg19957bb2009-07-02 17:20:43 +02006432 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006433
Johannes Berg19957bb2009-07-02 17:20:43 +02006434 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6435 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006436 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006437 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006438 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006439
6440 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006441 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6442 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006443 }
6444
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006445 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6446
Johannes Berg91bf9b22013-05-15 17:44:01 +02006447 wdev_lock(dev->ieee80211_ptr);
6448 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6449 local_state_change);
6450 wdev_unlock(dev->ieee80211_ptr);
6451 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006452}
6453
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006454static bool
6455nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6456 int mcast_rate[IEEE80211_NUM_BANDS],
6457 int rateval)
6458{
6459 struct wiphy *wiphy = &rdev->wiphy;
6460 bool found = false;
6461 int band, i;
6462
6463 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6464 struct ieee80211_supported_band *sband;
6465
6466 sband = wiphy->bands[band];
6467 if (!sband)
6468 continue;
6469
6470 for (i = 0; i < sband->n_bitrates; i++) {
6471 if (sband->bitrates[i].bitrate == rateval) {
6472 mcast_rate[band] = i + 1;
6473 found = true;
6474 break;
6475 }
6476 }
6477 }
6478
6479 return found;
6480}
6481
Johannes Berg04a773a2009-04-19 21:24:32 +02006482static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6483{
Johannes Berg4c476992010-10-04 21:36:35 +02006484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6485 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006486 struct cfg80211_ibss_params ibss;
6487 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006488 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006489 int err;
6490
Johannes Berg8e30bc52009-04-22 17:45:38 +02006491 memset(&ibss, 0, sizeof(ibss));
6492
Johannes Berg04a773a2009-04-19 21:24:32 +02006493 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6494 return -EINVAL;
6495
Johannes Berg683b6d32012-11-08 21:25:48 +01006496 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006497 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6498 return -EINVAL;
6499
Johannes Berg8e30bc52009-04-22 17:45:38 +02006500 ibss.beacon_interval = 100;
6501
6502 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6503 ibss.beacon_interval =
6504 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6505 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6506 return -EINVAL;
6507 }
6508
Johannes Berg4c476992010-10-04 21:36:35 +02006509 if (!rdev->ops->join_ibss)
6510 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006511
Johannes Berg4c476992010-10-04 21:36:35 +02006512 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6513 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006514
Johannes Berg79c97e92009-07-07 03:56:12 +02006515 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006516
Johannes Berg39193492011-09-16 13:45:25 +02006517 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006518 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006519
6520 if (!is_valid_ether_addr(ibss.bssid))
6521 return -EINVAL;
6522 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006523 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6524 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6525
6526 if (info->attrs[NL80211_ATTR_IE]) {
6527 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6528 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6529 }
6530
Johannes Berg683b6d32012-11-08 21:25:48 +01006531 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6532 if (err)
6533 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01006534
Johannes Berg683b6d32012-11-08 21:25:48 +01006535 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01006536 return -EINVAL;
6537
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006538 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006539 case NL80211_CHAN_WIDTH_5:
6540 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006541 case NL80211_CHAN_WIDTH_20_NOHT:
6542 break;
6543 case NL80211_CHAN_WIDTH_20:
6544 case NL80211_CHAN_WIDTH_40:
6545 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6546 break;
6547 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006548 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006549 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006550
Johannes Berg04a773a2009-04-19 21:24:32 +02006551 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006552 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006553
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006554 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6555 u8 *rates =
6556 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6557 int n_rates =
6558 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6559 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006560 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006561
Johannes Berg34850ab2011-07-18 18:08:35 +02006562 err = ieee80211_get_ratemask(sband, rates, n_rates,
6563 &ibss.basic_rates);
6564 if (err)
6565 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006566 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006567
Simon Wunderlich803768f2013-06-28 10:39:58 +02006568 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6569 memcpy(&ibss.ht_capa_mask,
6570 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6571 sizeof(ibss.ht_capa_mask));
6572
6573 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6574 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6575 return -EINVAL;
6576 memcpy(&ibss.ht_capa,
6577 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6578 sizeof(ibss.ht_capa));
6579 }
6580
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006581 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6582 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6583 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6584 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006585
Johannes Berg4c476992010-10-04 21:36:35 +02006586 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306587 bool no_ht = false;
6588
Johannes Berg4c476992010-10-04 21:36:35 +02006589 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306590 info->attrs[NL80211_ATTR_KEYS],
6591 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006592 if (IS_ERR(connkeys))
6593 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306594
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006595 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6596 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306597 kfree(connkeys);
6598 return -EINVAL;
6599 }
Johannes Berg4c476992010-10-04 21:36:35 +02006600 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006601
Antonio Quartulli267335d2012-01-31 20:25:47 +01006602 ibss.control_port =
6603 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6604
Johannes Berg4c476992010-10-04 21:36:35 +02006605 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006606 if (err)
6607 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006608 return err;
6609}
6610
6611static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6612{
Johannes Berg4c476992010-10-04 21:36:35 +02006613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6614 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006615
Johannes Berg4c476992010-10-04 21:36:35 +02006616 if (!rdev->ops->leave_ibss)
6617 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006618
Johannes Berg4c476992010-10-04 21:36:35 +02006619 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6620 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006621
Johannes Berg4c476992010-10-04 21:36:35 +02006622 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006623}
6624
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006625static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6626{
6627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6628 struct net_device *dev = info->user_ptr[1];
6629 int mcast_rate[IEEE80211_NUM_BANDS];
6630 u32 nla_rate;
6631 int err;
6632
6633 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6634 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6635 return -EOPNOTSUPP;
6636
6637 if (!rdev->ops->set_mcast_rate)
6638 return -EOPNOTSUPP;
6639
6640 memset(mcast_rate, 0, sizeof(mcast_rate));
6641
6642 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6643 return -EINVAL;
6644
6645 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6646 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6647 return -EINVAL;
6648
6649 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6650
6651 return err;
6652}
6653
6654
Johannes Bergaff89a92009-07-01 21:26:51 +02006655#ifdef CONFIG_NL80211_TESTMODE
6656static struct genl_multicast_group nl80211_testmode_mcgrp = {
6657 .name = "testmode",
6658};
6659
6660static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6661{
Johannes Berg4c476992010-10-04 21:36:35 +02006662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006663 struct wireless_dev *wdev =
6664 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006665 int err;
6666
David Spinadelfc73f112013-07-31 18:04:15 +03006667 if (!rdev->ops->testmode_cmd)
6668 return -EOPNOTSUPP;
6669
6670 if (IS_ERR(wdev)) {
6671 err = PTR_ERR(wdev);
6672 if (err != -EINVAL)
6673 return err;
6674 wdev = NULL;
6675 } else if (wdev->wiphy != &rdev->wiphy) {
6676 return -EINVAL;
6677 }
6678
Johannes Bergaff89a92009-07-01 21:26:51 +02006679 if (!info->attrs[NL80211_ATTR_TESTDATA])
6680 return -EINVAL;
6681
David Spinadelfc73f112013-07-31 18:04:15 +03006682 rdev->testmode_info = info;
6683 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006684 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6685 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
David Spinadelfc73f112013-07-31 18:04:15 +03006686 rdev->testmode_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006687
Johannes Bergaff89a92009-07-01 21:26:51 +02006688 return err;
6689}
6690
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006691static int nl80211_testmode_dump(struct sk_buff *skb,
6692 struct netlink_callback *cb)
6693{
Johannes Berg00918d32011-12-13 17:22:05 +01006694 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006695 int err;
6696 long phy_idx;
6697 void *data = NULL;
6698 int data_len = 0;
6699
Johannes Berg5fe231e2013-05-08 21:45:15 +02006700 rtnl_lock();
6701
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006702 if (cb->args[0]) {
6703 /*
6704 * 0 is a valid index, but not valid for args[0],
6705 * so we need to offset by 1.
6706 */
6707 phy_idx = cb->args[0] - 1;
6708 } else {
6709 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6710 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6711 nl80211_policy);
6712 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006713 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006714
Johannes Berg2bd7e352012-06-15 14:23:16 +02006715 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6716 nl80211_fam.attrbuf);
6717 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006718 err = PTR_ERR(rdev);
6719 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006720 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006721 phy_idx = rdev->wiphy_idx;
6722 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006723
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006724 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6725 cb->args[1] =
6726 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6727 }
6728
6729 if (cb->args[1]) {
6730 data = nla_data((void *)cb->args[1]);
6731 data_len = nla_len((void *)cb->args[1]);
6732 }
6733
Johannes Berg00918d32011-12-13 17:22:05 +01006734 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6735 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006736 err = -ENOENT;
6737 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006738 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006739
Johannes Berg00918d32011-12-13 17:22:05 +01006740 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006741 err = -EOPNOTSUPP;
6742 goto out_err;
6743 }
6744
6745 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006746 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006747 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6748 NL80211_CMD_TESTMODE);
6749 struct nlattr *tmdata;
6750
Dan Carpentercb35fba2013-08-14 14:50:01 +03006751 if (!hdr)
6752 break;
6753
David S. Miller9360ffd2012-03-29 04:41:26 -04006754 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006755 genlmsg_cancel(skb, hdr);
6756 break;
6757 }
6758
6759 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6760 if (!tmdata) {
6761 genlmsg_cancel(skb, hdr);
6762 break;
6763 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006764 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006765 nla_nest_end(skb, tmdata);
6766
6767 if (err == -ENOBUFS || err == -ENOENT) {
6768 genlmsg_cancel(skb, hdr);
6769 break;
6770 } else if (err) {
6771 genlmsg_cancel(skb, hdr);
6772 goto out_err;
6773 }
6774
6775 genlmsg_end(skb, hdr);
6776 }
6777
6778 err = skb->len;
6779 /* see above */
6780 cb->args[0] = phy_idx + 1;
6781 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006782 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006783 return err;
6784}
6785
Johannes Bergaff89a92009-07-01 21:26:51 +02006786static struct sk_buff *
6787__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006788 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006789{
6790 struct sk_buff *skb;
6791 void *hdr;
6792 struct nlattr *data;
6793
6794 skb = nlmsg_new(approxlen + 100, gfp);
6795 if (!skb)
6796 return NULL;
6797
Eric W. Biederman15e47302012-09-07 20:12:54 +00006798 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006799 if (!hdr) {
6800 kfree_skb(skb);
6801 return NULL;
6802 }
6803
David S. Miller9360ffd2012-03-29 04:41:26 -04006804 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6805 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006806 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6807
6808 ((void **)skb->cb)[0] = rdev;
6809 ((void **)skb->cb)[1] = hdr;
6810 ((void **)skb->cb)[2] = data;
6811
6812 return skb;
6813
6814 nla_put_failure:
6815 kfree_skb(skb);
6816 return NULL;
6817}
6818
6819struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6820 int approxlen)
6821{
6822 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6823
6824 if (WARN_ON(!rdev->testmode_info))
6825 return NULL;
6826
6827 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006828 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006829 rdev->testmode_info->snd_seq,
6830 GFP_KERNEL);
6831}
6832EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6833
6834int cfg80211_testmode_reply(struct sk_buff *skb)
6835{
6836 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6837 void *hdr = ((void **)skb->cb)[1];
6838 struct nlattr *data = ((void **)skb->cb)[2];
6839
6840 if (WARN_ON(!rdev->testmode_info)) {
6841 kfree_skb(skb);
6842 return -EINVAL;
6843 }
6844
6845 nla_nest_end(skb, data);
6846 genlmsg_end(skb, hdr);
6847 return genlmsg_reply(skb, rdev->testmode_info);
6848}
6849EXPORT_SYMBOL(cfg80211_testmode_reply);
6850
6851struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6852 int approxlen, gfp_t gfp)
6853{
6854 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6855
6856 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6857}
6858EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6859
6860void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6861{
Michal Kaziora0ec5702013-06-25 09:17:17 +02006862 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006863 void *hdr = ((void **)skb->cb)[1];
6864 struct nlattr *data = ((void **)skb->cb)[2];
6865
6866 nla_nest_end(skb, data);
6867 genlmsg_end(skb, hdr);
Michal Kaziora0ec5702013-06-25 09:17:17 +02006868 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
6869 nl80211_testmode_mcgrp.id, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006870}
6871EXPORT_SYMBOL(cfg80211_testmode_event);
6872#endif
6873
Samuel Ortizb23aa672009-07-01 21:26:54 +02006874static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6875{
Johannes Berg4c476992010-10-04 21:36:35 +02006876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6877 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006878 struct cfg80211_connect_params connect;
6879 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006880 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006881 int err;
6882
6883 memset(&connect, 0, sizeof(connect));
6884
6885 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6886 return -EINVAL;
6887
6888 if (!info->attrs[NL80211_ATTR_SSID] ||
6889 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6890 return -EINVAL;
6891
6892 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6893 connect.auth_type =
6894 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006895 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6896 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006897 return -EINVAL;
6898 } else
6899 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6900
6901 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6902
Johannes Bergc0692b82010-08-27 14:26:53 +03006903 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006904 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006905 if (err)
6906 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006907
Johannes Berg074ac8d2010-09-16 14:58:22 +02006908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006909 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6910 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006911
Johannes Berg79c97e92009-07-07 03:56:12 +02006912 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006913
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306914 connect.bg_scan_period = -1;
6915 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6916 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6917 connect.bg_scan_period =
6918 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6919 }
6920
Samuel Ortizb23aa672009-07-01 21:26:54 +02006921 if (info->attrs[NL80211_ATTR_MAC])
6922 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6923 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6924 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6925
6926 if (info->attrs[NL80211_ATTR_IE]) {
6927 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6928 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6929 }
6930
Jouni Malinencee00a92013-01-15 17:15:57 +02006931 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6932 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6933 if (connect.mfp != NL80211_MFP_REQUIRED &&
6934 connect.mfp != NL80211_MFP_NO)
6935 return -EINVAL;
6936 } else {
6937 connect.mfp = NL80211_MFP_NO;
6938 }
6939
Samuel Ortizb23aa672009-07-01 21:26:54 +02006940 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6941 connect.channel =
6942 ieee80211_get_channel(wiphy,
6943 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6944 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006945 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6946 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006947 }
6948
Johannes Bergfffd0932009-07-08 14:22:54 +02006949 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6950 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306951 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006952 if (IS_ERR(connkeys))
6953 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006954 }
6955
Ben Greear7e7c8922011-11-18 11:31:59 -08006956 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6957 connect.flags |= ASSOC_REQ_DISABLE_HT;
6958
6959 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6960 memcpy(&connect.ht_capa_mask,
6961 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6962 sizeof(connect.ht_capa_mask));
6963
6964 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006965 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6966 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006967 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006968 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006969 memcpy(&connect.ht_capa,
6970 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6971 sizeof(connect.ht_capa));
6972 }
6973
Johannes Bergee2aca32013-02-21 17:36:01 +01006974 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6975 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6976
6977 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6978 memcpy(&connect.vht_capa_mask,
6979 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6980 sizeof(connect.vht_capa_mask));
6981
6982 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6983 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6984 kfree(connkeys);
6985 return -EINVAL;
6986 }
6987 memcpy(&connect.vht_capa,
6988 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6989 sizeof(connect.vht_capa));
6990 }
6991
Johannes Berg83739b02013-05-15 17:44:01 +02006992 wdev_lock(dev->ieee80211_ptr);
6993 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6994 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006995 if (err)
6996 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006997 return err;
6998}
6999
7000static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7001{
Johannes Berg4c476992010-10-04 21:36:35 +02007002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7003 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007004 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007005 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007006
7007 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7008 reason = WLAN_REASON_DEAUTH_LEAVING;
7009 else
7010 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7011
7012 if (reason == 0)
7013 return -EINVAL;
7014
Johannes Berg074ac8d2010-09-16 14:58:22 +02007015 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007016 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7017 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007018
Johannes Berg83739b02013-05-15 17:44:01 +02007019 wdev_lock(dev->ieee80211_ptr);
7020 ret = cfg80211_disconnect(rdev, dev, reason, true);
7021 wdev_unlock(dev->ieee80211_ptr);
7022 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007023}
7024
Johannes Berg463d0182009-07-14 00:33:35 +02007025static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7026{
Johannes Berg4c476992010-10-04 21:36:35 +02007027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007028 struct net *net;
7029 int err;
7030 u32 pid;
7031
7032 if (!info->attrs[NL80211_ATTR_PID])
7033 return -EINVAL;
7034
7035 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7036
Johannes Berg463d0182009-07-14 00:33:35 +02007037 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007038 if (IS_ERR(net))
7039 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007040
7041 err = 0;
7042
7043 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007044 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7045 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007046
Johannes Berg463d0182009-07-14 00:33:35 +02007047 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007048 return err;
7049}
7050
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007051static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7052{
Johannes Berg4c476992010-10-04 21:36:35 +02007053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007054 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7055 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007056 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007057 struct cfg80211_pmksa pmksa;
7058
7059 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7060
7061 if (!info->attrs[NL80211_ATTR_MAC])
7062 return -EINVAL;
7063
7064 if (!info->attrs[NL80211_ATTR_PMKID])
7065 return -EINVAL;
7066
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007067 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7068 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7069
Johannes Berg074ac8d2010-09-16 14:58:22 +02007070 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007071 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7072 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007073
7074 switch (info->genlhdr->cmd) {
7075 case NL80211_CMD_SET_PMKSA:
7076 rdev_ops = rdev->ops->set_pmksa;
7077 break;
7078 case NL80211_CMD_DEL_PMKSA:
7079 rdev_ops = rdev->ops->del_pmksa;
7080 break;
7081 default:
7082 WARN_ON(1);
7083 break;
7084 }
7085
Johannes Berg4c476992010-10-04 21:36:35 +02007086 if (!rdev_ops)
7087 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007088
Johannes Berg4c476992010-10-04 21:36:35 +02007089 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007090}
7091
7092static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7093{
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7095 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007096
Johannes Berg074ac8d2010-09-16 14:58:22 +02007097 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007098 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7099 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007100
Johannes Berg4c476992010-10-04 21:36:35 +02007101 if (!rdev->ops->flush_pmksa)
7102 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007103
Hila Gonene35e4d22012-06-27 17:19:42 +03007104 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007105}
7106
Arik Nemtsov109086c2011-09-28 14:12:50 +03007107static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7108{
7109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7110 struct net_device *dev = info->user_ptr[1];
7111 u8 action_code, dialog_token;
7112 u16 status_code;
7113 u8 *peer;
7114
7115 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7116 !rdev->ops->tdls_mgmt)
7117 return -EOPNOTSUPP;
7118
7119 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7120 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7121 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7122 !info->attrs[NL80211_ATTR_IE] ||
7123 !info->attrs[NL80211_ATTR_MAC])
7124 return -EINVAL;
7125
7126 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7127 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7128 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7129 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7130
Hila Gonene35e4d22012-06-27 17:19:42 +03007131 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7132 dialog_token, status_code,
7133 nla_data(info->attrs[NL80211_ATTR_IE]),
7134 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007135}
7136
7137static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7138{
7139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7140 struct net_device *dev = info->user_ptr[1];
7141 enum nl80211_tdls_operation operation;
7142 u8 *peer;
7143
7144 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7145 !rdev->ops->tdls_oper)
7146 return -EOPNOTSUPP;
7147
7148 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7149 !info->attrs[NL80211_ATTR_MAC])
7150 return -EINVAL;
7151
7152 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7153 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7154
Hila Gonene35e4d22012-06-27 17:19:42 +03007155 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007156}
7157
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007158static int nl80211_remain_on_channel(struct sk_buff *skb,
7159 struct genl_info *info)
7160{
Johannes Berg4c476992010-10-04 21:36:35 +02007161 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007162 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007163 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007164 struct sk_buff *msg;
7165 void *hdr;
7166 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007167 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007168 int err;
7169
7170 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7171 !info->attrs[NL80211_ATTR_DURATION])
7172 return -EINVAL;
7173
7174 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7175
Johannes Berg7c4ef712011-11-18 15:33:48 +01007176 if (!rdev->ops->remain_on_channel ||
7177 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007178 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007179
Johannes Bergebf348f2012-06-01 12:50:54 +02007180 /*
7181 * We should be on that channel for at least a minimum amount of
7182 * time (10ms) but no longer than the driver supports.
7183 */
7184 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7185 duration > rdev->wiphy.max_remain_on_channel_duration)
7186 return -EINVAL;
7187
Johannes Berg683b6d32012-11-08 21:25:48 +01007188 err = nl80211_parse_chandef(rdev, info, &chandef);
7189 if (err)
7190 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007191
7192 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007193 if (!msg)
7194 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007195
Eric W. Biederman15e47302012-09-07 20:12:54 +00007196 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007197 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007198 if (!hdr) {
7199 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007200 goto free_msg;
7201 }
7202
Johannes Berg683b6d32012-11-08 21:25:48 +01007203 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7204 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007205
7206 if (err)
7207 goto free_msg;
7208
David S. Miller9360ffd2012-03-29 04:41:26 -04007209 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7210 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007211
7212 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007213
7214 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007215
7216 nla_put_failure:
7217 err = -ENOBUFS;
7218 free_msg:
7219 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007220 return err;
7221}
7222
7223static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7224 struct genl_info *info)
7225{
Johannes Berg4c476992010-10-04 21:36:35 +02007226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007227 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007228 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007229
7230 if (!info->attrs[NL80211_ATTR_COOKIE])
7231 return -EINVAL;
7232
Johannes Berg4c476992010-10-04 21:36:35 +02007233 if (!rdev->ops->cancel_remain_on_channel)
7234 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007235
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007236 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7237
Hila Gonene35e4d22012-06-27 17:19:42 +03007238 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007239}
7240
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007241static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7242 u8 *rates, u8 rates_len)
7243{
7244 u8 i;
7245 u32 mask = 0;
7246
7247 for (i = 0; i < rates_len; i++) {
7248 int rate = (rates[i] & 0x7f) * 5;
7249 int ridx;
7250 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7251 struct ieee80211_rate *srate =
7252 &sband->bitrates[ridx];
7253 if (rate == srate->bitrate) {
7254 mask |= 1 << ridx;
7255 break;
7256 }
7257 }
7258 if (ridx == sband->n_bitrates)
7259 return 0; /* rate not found */
7260 }
7261
7262 return mask;
7263}
7264
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007265static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7266 u8 *rates, u8 rates_len,
7267 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7268{
7269 u8 i;
7270
7271 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7272
7273 for (i = 0; i < rates_len; i++) {
7274 int ridx, rbit;
7275
7276 ridx = rates[i] / 8;
7277 rbit = BIT(rates[i] % 8);
7278
7279 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007280 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007281 return false;
7282
7283 /* check availability */
7284 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7285 mcs[ridx] |= rbit;
7286 else
7287 return false;
7288 }
7289
7290 return true;
7291}
7292
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007293static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007294 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7295 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007296 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7297 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007298};
7299
7300static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7301 struct genl_info *info)
7302{
7303 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007305 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007306 int rem, i;
7307 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007308 struct nlattr *tx_rates;
7309 struct ieee80211_supported_band *sband;
7310
7311 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7312 return -EINVAL;
7313
Johannes Berg4c476992010-10-04 21:36:35 +02007314 if (!rdev->ops->set_bitrate_mask)
7315 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007316
7317 memset(&mask, 0, sizeof(mask));
7318 /* Default to all rates enabled */
7319 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7320 sband = rdev->wiphy.bands[i];
7321 mask.control[i].legacy =
7322 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007323 if (sband)
7324 memcpy(mask.control[i].mcs,
7325 sband->ht_cap.mcs.rx_mask,
7326 sizeof(mask.control[i].mcs));
7327 else
7328 memset(mask.control[i].mcs, 0,
7329 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007330 }
7331
7332 /*
7333 * The nested attribute uses enum nl80211_band as the index. This maps
7334 * directly to the enum ieee80211_band values used in cfg80211.
7335 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007336 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007337 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7338 {
7339 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007340 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7341 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007342 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007343 if (sband == NULL)
7344 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007345 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7346 nla_len(tx_rates), nl80211_txattr_policy);
7347 if (tb[NL80211_TXRATE_LEGACY]) {
7348 mask.control[band].legacy = rateset_to_mask(
7349 sband,
7350 nla_data(tb[NL80211_TXRATE_LEGACY]),
7351 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307352 if ((mask.control[band].legacy == 0) &&
7353 nla_len(tb[NL80211_TXRATE_LEGACY]))
7354 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007355 }
7356 if (tb[NL80211_TXRATE_MCS]) {
7357 if (!ht_rateset_to_mask(
7358 sband,
7359 nla_data(tb[NL80211_TXRATE_MCS]),
7360 nla_len(tb[NL80211_TXRATE_MCS]),
7361 mask.control[band].mcs))
7362 return -EINVAL;
7363 }
7364
7365 if (mask.control[band].legacy == 0) {
7366 /* don't allow empty legacy rates if HT
7367 * is not even supported. */
7368 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7369 return -EINVAL;
7370
7371 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7372 if (mask.control[band].mcs[i])
7373 break;
7374
7375 /* legacy and mcs rates may not be both empty */
7376 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007377 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007378 }
7379 }
7380
Hila Gonene35e4d22012-06-27 17:19:42 +03007381 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007382}
7383
Johannes Berg2e161f72010-08-12 15:38:38 +02007384static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007385{
Johannes Berg4c476992010-10-04 21:36:35 +02007386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007387 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007388 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007389
7390 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7391 return -EINVAL;
7392
Johannes Berg2e161f72010-08-12 15:38:38 +02007393 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7394 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007395
Johannes Berg71bbc992012-06-15 15:30:18 +02007396 switch (wdev->iftype) {
7397 case NL80211_IFTYPE_STATION:
7398 case NL80211_IFTYPE_ADHOC:
7399 case NL80211_IFTYPE_P2P_CLIENT:
7400 case NL80211_IFTYPE_AP:
7401 case NL80211_IFTYPE_AP_VLAN:
7402 case NL80211_IFTYPE_MESH_POINT:
7403 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007404 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007405 break;
7406 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007407 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007408 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007409
7410 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007411 if (!rdev->ops->mgmt_tx)
7412 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007413
Eric W. Biederman15e47302012-09-07 20:12:54 +00007414 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007415 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7416 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007417}
7418
Johannes Berg2e161f72010-08-12 15:38:38 +02007419static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007420{
Johannes Berg4c476992010-10-04 21:36:35 +02007421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007422 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007423 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007424 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007425 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007426 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007427 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007428 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007429 bool offchan, no_cck, dont_wait_for_ack;
7430
7431 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007432
Johannes Berg683b6d32012-11-08 21:25:48 +01007433 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007434 return -EINVAL;
7435
Johannes Berg4c476992010-10-04 21:36:35 +02007436 if (!rdev->ops->mgmt_tx)
7437 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007438
Johannes Berg71bbc992012-06-15 15:30:18 +02007439 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007440 case NL80211_IFTYPE_P2P_DEVICE:
7441 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7442 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007443 case NL80211_IFTYPE_STATION:
7444 case NL80211_IFTYPE_ADHOC:
7445 case NL80211_IFTYPE_P2P_CLIENT:
7446 case NL80211_IFTYPE_AP:
7447 case NL80211_IFTYPE_AP_VLAN:
7448 case NL80211_IFTYPE_MESH_POINT:
7449 case NL80211_IFTYPE_P2P_GO:
7450 break;
7451 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007452 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007453 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007454
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007455 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007456 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007457 return -EINVAL;
7458 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007459
7460 /*
7461 * We should wait on the channel for at least a minimum amount
7462 * of time (10ms) but no longer than the driver supports.
7463 */
7464 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7465 wait > rdev->wiphy.max_remain_on_channel_duration)
7466 return -EINVAL;
7467
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007468 }
7469
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007470 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7471
Johannes Berg7c4ef712011-11-18 15:33:48 +01007472 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7473 return -EINVAL;
7474
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307475 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7476
Antonio Quartulliea141b752013-06-11 14:20:03 +02007477 /* get the channel if any has been specified, otherwise pass NULL to
7478 * the driver. The latter will use the current one
7479 */
7480 chandef.chan = NULL;
7481 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7482 err = nl80211_parse_chandef(rdev, info, &chandef);
7483 if (err)
7484 return err;
7485 }
7486
7487 if (!chandef.chan && offchan)
7488 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007489
Johannes Berge247bd902011-11-04 11:18:21 +01007490 if (!dont_wait_for_ack) {
7491 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7492 if (!msg)
7493 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007494
Eric W. Biederman15e47302012-09-07 20:12:54 +00007495 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007496 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007497 if (!hdr) {
7498 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007499 goto free_msg;
7500 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007501 }
Johannes Berge247bd902011-11-04 11:18:21 +01007502
Johannes Berg683b6d32012-11-08 21:25:48 +01007503 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007504 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7505 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007506 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007507 if (err)
7508 goto free_msg;
7509
Johannes Berge247bd902011-11-04 11:18:21 +01007510 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007511 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7512 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007513
Johannes Berge247bd902011-11-04 11:18:21 +01007514 genlmsg_end(msg, hdr);
7515 return genlmsg_reply(msg, info);
7516 }
7517
7518 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007519
7520 nla_put_failure:
7521 err = -ENOBUFS;
7522 free_msg:
7523 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007524 return err;
7525}
7526
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007527static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7528{
7529 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007530 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007531 u64 cookie;
7532
7533 if (!info->attrs[NL80211_ATTR_COOKIE])
7534 return -EINVAL;
7535
7536 if (!rdev->ops->mgmt_tx_cancel_wait)
7537 return -EOPNOTSUPP;
7538
Johannes Berg71bbc992012-06-15 15:30:18 +02007539 switch (wdev->iftype) {
7540 case NL80211_IFTYPE_STATION:
7541 case NL80211_IFTYPE_ADHOC:
7542 case NL80211_IFTYPE_P2P_CLIENT:
7543 case NL80211_IFTYPE_AP:
7544 case NL80211_IFTYPE_AP_VLAN:
7545 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007546 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007547 break;
7548 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007549 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007550 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007551
7552 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7553
Hila Gonene35e4d22012-06-27 17:19:42 +03007554 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007555}
7556
Kalle Valoffb9eb32010-02-17 17:58:10 +02007557static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7558{
Johannes Berg4c476992010-10-04 21:36:35 +02007559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007560 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007561 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007562 u8 ps_state;
7563 bool state;
7564 int err;
7565
Johannes Berg4c476992010-10-04 21:36:35 +02007566 if (!info->attrs[NL80211_ATTR_PS_STATE])
7567 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007568
7569 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7570
Johannes Berg4c476992010-10-04 21:36:35 +02007571 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7572 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007573
7574 wdev = dev->ieee80211_ptr;
7575
Johannes Berg4c476992010-10-04 21:36:35 +02007576 if (!rdev->ops->set_power_mgmt)
7577 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007578
7579 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7580
7581 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007582 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007583
Hila Gonene35e4d22012-06-27 17:19:42 +03007584 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007585 if (!err)
7586 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007587 return err;
7588}
7589
7590static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7591{
Johannes Berg4c476992010-10-04 21:36:35 +02007592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007593 enum nl80211_ps_state ps_state;
7594 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007595 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007596 struct sk_buff *msg;
7597 void *hdr;
7598 int err;
7599
Kalle Valoffb9eb32010-02-17 17:58:10 +02007600 wdev = dev->ieee80211_ptr;
7601
Johannes Berg4c476992010-10-04 21:36:35 +02007602 if (!rdev->ops->set_power_mgmt)
7603 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007604
7605 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007606 if (!msg)
7607 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007608
Eric W. Biederman15e47302012-09-07 20:12:54 +00007609 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007610 NL80211_CMD_GET_POWER_SAVE);
7611 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007612 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007613 goto free_msg;
7614 }
7615
7616 if (wdev->ps)
7617 ps_state = NL80211_PS_ENABLED;
7618 else
7619 ps_state = NL80211_PS_DISABLED;
7620
David S. Miller9360ffd2012-03-29 04:41:26 -04007621 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7622 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007623
7624 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007625 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007626
Johannes Berg4c476992010-10-04 21:36:35 +02007627 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007628 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007629 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007630 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007631 return err;
7632}
7633
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007634static struct nla_policy
7635nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7636 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7637 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7638 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007639 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7640 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7641 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007642};
7643
Thomas Pedersen84f10702012-07-12 16:17:33 -07007644static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007645 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007646{
7647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007648 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007649 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007650
Johannes Bergd9d8b012012-11-26 12:51:52 +01007651 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007652 return -EINVAL;
7653
Thomas Pedersen84f10702012-07-12 16:17:33 -07007654 if (!rdev->ops->set_cqm_txe_config)
7655 return -EOPNOTSUPP;
7656
7657 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7658 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7659 return -EOPNOTSUPP;
7660
Hila Gonene35e4d22012-06-27 17:19:42 +03007661 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007662}
7663
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007664static int nl80211_set_cqm_rssi(struct genl_info *info,
7665 s32 threshold, u32 hysteresis)
7666{
Johannes Berg4c476992010-10-04 21:36:35 +02007667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007668 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007669 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007670
7671 if (threshold > 0)
7672 return -EINVAL;
7673
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007674 /* disabling - hysteresis should also be zero then */
7675 if (threshold == 0)
7676 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007677
Johannes Berg4c476992010-10-04 21:36:35 +02007678 if (!rdev->ops->set_cqm_rssi_config)
7679 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007680
Johannes Berg074ac8d2010-09-16 14:58:22 +02007681 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007682 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7683 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007684
Hila Gonene35e4d22012-06-27 17:19:42 +03007685 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007686}
7687
7688static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7689{
7690 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7691 struct nlattr *cqm;
7692 int err;
7693
7694 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007695 if (!cqm)
7696 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007697
7698 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7699 nl80211_attr_cqm_policy);
7700 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007701 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007702
7703 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7704 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007705 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7706 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007707
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007708 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7709 }
7710
7711 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7712 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7713 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7714 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7715 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7716 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7717
7718 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7719 }
7720
7721 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007722}
7723
Johannes Berg29cbe682010-12-03 09:20:44 +01007724static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7725{
7726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7727 struct net_device *dev = info->user_ptr[1];
7728 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007729 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007730 int err;
7731
7732 /* start with default */
7733 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007734 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007735
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007736 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007737 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007738 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007739 if (err)
7740 return err;
7741 }
7742
7743 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7744 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7745 return -EINVAL;
7746
Javier Cardonac80d5452010-12-16 17:37:49 -08007747 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7748 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7749
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007750 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7751 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7752 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7753 return -EINVAL;
7754
Marco Porsch9bdbf042013-01-07 16:04:51 +01007755 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7756 setup.beacon_interval =
7757 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7758 if (setup.beacon_interval < 10 ||
7759 setup.beacon_interval > 10000)
7760 return -EINVAL;
7761 }
7762
7763 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7764 setup.dtim_period =
7765 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7766 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7767 return -EINVAL;
7768 }
7769
Javier Cardonac80d5452010-12-16 17:37:49 -08007770 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7771 /* parse additional setup parameters if given */
7772 err = nl80211_parse_mesh_setup(info, &setup);
7773 if (err)
7774 return err;
7775 }
7776
Thomas Pedersend37bb182013-03-04 13:06:13 -08007777 if (setup.user_mpm)
7778 cfg.auto_open_plinks = false;
7779
Johannes Bergcc1d2802012-05-16 23:50:20 +02007780 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007781 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7782 if (err)
7783 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007784 } else {
7785 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007786 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007787 }
7788
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007789 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7790 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7791 int n_rates =
7792 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7793 struct ieee80211_supported_band *sband;
7794
7795 if (!setup.chandef.chan)
7796 return -EINVAL;
7797
7798 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7799
7800 err = ieee80211_get_ratemask(sband, rates, n_rates,
7801 &setup.basic_rates);
7802 if (err)
7803 return err;
7804 }
7805
Javier Cardonac80d5452010-12-16 17:37:49 -08007806 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007807}
7808
7809static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7810{
7811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7812 struct net_device *dev = info->user_ptr[1];
7813
7814 return cfg80211_leave_mesh(rdev, dev);
7815}
7816
Johannes Bergdfb89c52012-06-27 09:23:48 +02007817#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007818static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7819 struct cfg80211_registered_device *rdev)
7820{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007821 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007822 struct nlattr *nl_pats, *nl_pat;
7823 int i, pat_len;
7824
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007825 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007826 return 0;
7827
7828 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7829 if (!nl_pats)
7830 return -ENOBUFS;
7831
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007832 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007833 nl_pat = nla_nest_start(msg, i + 1);
7834 if (!nl_pat)
7835 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007836 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007837 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007838 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007839 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7840 wowlan->patterns[i].pattern) ||
7841 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007842 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007843 return -ENOBUFS;
7844 nla_nest_end(msg, nl_pat);
7845 }
7846 nla_nest_end(msg, nl_pats);
7847
7848 return 0;
7849}
7850
Johannes Berg2a0e0472013-01-23 22:57:40 +01007851static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7852 struct cfg80211_wowlan_tcp *tcp)
7853{
7854 struct nlattr *nl_tcp;
7855
7856 if (!tcp)
7857 return 0;
7858
7859 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7860 if (!nl_tcp)
7861 return -ENOBUFS;
7862
7863 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7864 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7865 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7866 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7867 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7868 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7869 tcp->payload_len, tcp->payload) ||
7870 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7871 tcp->data_interval) ||
7872 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7873 tcp->wake_len, tcp->wake_data) ||
7874 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7875 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7876 return -ENOBUFS;
7877
7878 if (tcp->payload_seq.len &&
7879 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7880 sizeof(tcp->payload_seq), &tcp->payload_seq))
7881 return -ENOBUFS;
7882
7883 if (tcp->payload_tok.len &&
7884 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7885 sizeof(tcp->payload_tok) + tcp->tokens_size,
7886 &tcp->payload_tok))
7887 return -ENOBUFS;
7888
Johannes Berge248ad32013-05-16 10:24:28 +02007889 nla_nest_end(msg, nl_tcp);
7890
Johannes Berg2a0e0472013-01-23 22:57:40 +01007891 return 0;
7892}
7893
Johannes Bergff1b6e62011-05-04 15:37:28 +02007894static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7895{
7896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7897 struct sk_buff *msg;
7898 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007899 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007900
Johannes Berg964dc9e2013-06-03 17:25:34 +02007901 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007902 return -EOPNOTSUPP;
7903
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007904 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007905 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007906 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7907 rdev->wiphy.wowlan_config->tcp->payload_len +
7908 rdev->wiphy.wowlan_config->tcp->wake_len +
7909 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007910 }
7911
7912 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007913 if (!msg)
7914 return -ENOMEM;
7915
Eric W. Biederman15e47302012-09-07 20:12:54 +00007916 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007917 NL80211_CMD_GET_WOWLAN);
7918 if (!hdr)
7919 goto nla_put_failure;
7920
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007921 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007922 struct nlattr *nl_wowlan;
7923
7924 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7925 if (!nl_wowlan)
7926 goto nla_put_failure;
7927
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007928 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007929 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007930 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007931 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007932 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007933 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007934 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007935 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007936 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007937 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007938 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007939 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007940 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007941 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7942 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007943
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007944 if (nl80211_send_wowlan_patterns(msg, rdev))
7945 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007946
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007947 if (nl80211_send_wowlan_tcp(msg,
7948 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007949 goto nla_put_failure;
7950
Johannes Bergff1b6e62011-05-04 15:37:28 +02007951 nla_nest_end(msg, nl_wowlan);
7952 }
7953
7954 genlmsg_end(msg, hdr);
7955 return genlmsg_reply(msg, info);
7956
7957nla_put_failure:
7958 nlmsg_free(msg);
7959 return -ENOBUFS;
7960}
7961
Johannes Berg2a0e0472013-01-23 22:57:40 +01007962static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7963 struct nlattr *attr,
7964 struct cfg80211_wowlan *trig)
7965{
7966 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7967 struct cfg80211_wowlan_tcp *cfg;
7968 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7969 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7970 u32 size;
7971 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7972 int err, port;
7973
Johannes Berg964dc9e2013-06-03 17:25:34 +02007974 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007975 return -EINVAL;
7976
7977 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7978 nla_data(attr), nla_len(attr),
7979 nl80211_wowlan_tcp_policy);
7980 if (err)
7981 return err;
7982
7983 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7984 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7985 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7986 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7987 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7988 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7989 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7990 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7991 return -EINVAL;
7992
7993 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007994 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007995 return -EINVAL;
7996
7997 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007998 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007999 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008000 return -EINVAL;
8001
8002 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008003 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008004 return -EINVAL;
8005
8006 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8007 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8008 return -EINVAL;
8009
8010 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8011 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8012
8013 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8014 tokens_size = tokln - sizeof(*tok);
8015
8016 if (!tok->len || tokens_size % tok->len)
8017 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008018 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008019 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008020 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008021 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008022 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008023 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008024 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008025 return -EINVAL;
8026 if (tok->offset + tok->len > data_size)
8027 return -EINVAL;
8028 }
8029
8030 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8031 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008032 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008033 return -EINVAL;
8034 if (seq->len == 0 || seq->len > 4)
8035 return -EINVAL;
8036 if (seq->len + seq->offset > data_size)
8037 return -EINVAL;
8038 }
8039
8040 size = sizeof(*cfg);
8041 size += data_size;
8042 size += wake_size + wake_mask_size;
8043 size += tokens_size;
8044
8045 cfg = kzalloc(size, GFP_KERNEL);
8046 if (!cfg)
8047 return -ENOMEM;
8048 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8049 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8050 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8051 ETH_ALEN);
8052 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8053 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8054 else
8055 port = 0;
8056#ifdef CONFIG_INET
8057 /* allocate a socket and port for it and use it */
8058 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8059 IPPROTO_TCP, &cfg->sock, 1);
8060 if (err) {
8061 kfree(cfg);
8062 return err;
8063 }
8064 if (inet_csk_get_port(cfg->sock->sk, port)) {
8065 sock_release(cfg->sock);
8066 kfree(cfg);
8067 return -EADDRINUSE;
8068 }
8069 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8070#else
8071 if (!port) {
8072 kfree(cfg);
8073 return -EINVAL;
8074 }
8075 cfg->src_port = port;
8076#endif
8077
8078 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8079 cfg->payload_len = data_size;
8080 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8081 memcpy((void *)cfg->payload,
8082 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8083 data_size);
8084 if (seq)
8085 cfg->payload_seq = *seq;
8086 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8087 cfg->wake_len = wake_size;
8088 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8089 memcpy((void *)cfg->wake_data,
8090 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8091 wake_size);
8092 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8093 data_size + wake_size;
8094 memcpy((void *)cfg->wake_mask,
8095 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8096 wake_mask_size);
8097 if (tok) {
8098 cfg->tokens_size = tokens_size;
8099 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8100 }
8101
8102 trig->tcp = cfg;
8103
8104 return 0;
8105}
8106
Johannes Bergff1b6e62011-05-04 15:37:28 +02008107static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8108{
8109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8110 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008111 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008112 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008113 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008114 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008115 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008116
Johannes Berg964dc9e2013-06-03 17:25:34 +02008117 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008118 return -EOPNOTSUPP;
8119
Johannes Bergae33bd82012-07-12 16:25:02 +02008120 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8121 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008122 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008123 goto set_wakeup;
8124 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008125
8126 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8127 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8128 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8129 nl80211_wowlan_policy);
8130 if (err)
8131 return err;
8132
8133 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8134 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8135 return -EINVAL;
8136 new_triggers.any = true;
8137 }
8138
8139 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8140 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8141 return -EINVAL;
8142 new_triggers.disconnect = true;
8143 }
8144
8145 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8146 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8147 return -EINVAL;
8148 new_triggers.magic_pkt = true;
8149 }
8150
Johannes Berg77dbbb132011-07-13 10:48:55 +02008151 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8152 return -EINVAL;
8153
8154 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8155 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8156 return -EINVAL;
8157 new_triggers.gtk_rekey_failure = true;
8158 }
8159
8160 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8161 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8162 return -EINVAL;
8163 new_triggers.eap_identity_req = true;
8164 }
8165
8166 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8167 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8168 return -EINVAL;
8169 new_triggers.four_way_handshake = true;
8170 }
8171
8172 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8173 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8174 return -EINVAL;
8175 new_triggers.rfkill_release = true;
8176 }
8177
Johannes Bergff1b6e62011-05-04 15:37:28 +02008178 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8179 struct nlattr *pat;
8180 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008181 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008182 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008183
8184 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8185 rem)
8186 n_patterns++;
8187 if (n_patterns > wowlan->n_patterns)
8188 return -EINVAL;
8189
8190 new_triggers.patterns = kcalloc(n_patterns,
8191 sizeof(new_triggers.patterns[0]),
8192 GFP_KERNEL);
8193 if (!new_triggers.patterns)
8194 return -ENOMEM;
8195
8196 new_triggers.n_patterns = n_patterns;
8197 i = 0;
8198
8199 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8200 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008201 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8202 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008203 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008204 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8205 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008206 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008207 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008208 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008209 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008210 goto error;
8211 if (pat_len > wowlan->pattern_max_len ||
8212 pat_len < wowlan->pattern_min_len)
8213 goto error;
8214
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008215 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008216 pkt_offset = 0;
8217 else
8218 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008219 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008220 if (pkt_offset > wowlan->max_pkt_offset)
8221 goto error;
8222 new_triggers.patterns[i].pkt_offset = pkt_offset;
8223
Johannes Bergff1b6e62011-05-04 15:37:28 +02008224 new_triggers.patterns[i].mask =
8225 kmalloc(mask_len + pat_len, GFP_KERNEL);
8226 if (!new_triggers.patterns[i].mask) {
8227 err = -ENOMEM;
8228 goto error;
8229 }
8230 new_triggers.patterns[i].pattern =
8231 new_triggers.patterns[i].mask + mask_len;
8232 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008233 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008234 mask_len);
8235 new_triggers.patterns[i].pattern_len = pat_len;
8236 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008237 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008238 pat_len);
8239 i++;
8240 }
8241 }
8242
Johannes Berg2a0e0472013-01-23 22:57:40 +01008243 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8244 err = nl80211_parse_wowlan_tcp(
8245 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8246 &new_triggers);
8247 if (err)
8248 goto error;
8249 }
8250
Johannes Bergae33bd82012-07-12 16:25:02 +02008251 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8252 if (!ntrig) {
8253 err = -ENOMEM;
8254 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008255 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008256 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008257 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008258
Johannes Bergae33bd82012-07-12 16:25:02 +02008259 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008260 if (rdev->ops->set_wakeup &&
8261 prev_enabled != !!rdev->wiphy.wowlan_config)
8262 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008263
Johannes Bergff1b6e62011-05-04 15:37:28 +02008264 return 0;
8265 error:
8266 for (i = 0; i < new_triggers.n_patterns; i++)
8267 kfree(new_triggers.patterns[i].mask);
8268 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008269 if (new_triggers.tcp && new_triggers.tcp->sock)
8270 sock_release(new_triggers.tcp->sock);
8271 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008272 return err;
8273}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008274#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008275
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008276static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8277 struct cfg80211_registered_device *rdev)
8278{
8279 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8280 int i, j, pat_len;
8281 struct cfg80211_coalesce_rules *rule;
8282
8283 if (!rdev->coalesce->n_rules)
8284 return 0;
8285
8286 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8287 if (!nl_rules)
8288 return -ENOBUFS;
8289
8290 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8291 nl_rule = nla_nest_start(msg, i + 1);
8292 if (!nl_rule)
8293 return -ENOBUFS;
8294
8295 rule = &rdev->coalesce->rules[i];
8296 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8297 rule->delay))
8298 return -ENOBUFS;
8299
8300 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8301 rule->condition))
8302 return -ENOBUFS;
8303
8304 nl_pats = nla_nest_start(msg,
8305 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8306 if (!nl_pats)
8307 return -ENOBUFS;
8308
8309 for (j = 0; j < rule->n_patterns; j++) {
8310 nl_pat = nla_nest_start(msg, j + 1);
8311 if (!nl_pat)
8312 return -ENOBUFS;
8313 pat_len = rule->patterns[j].pattern_len;
8314 if (nla_put(msg, NL80211_PKTPAT_MASK,
8315 DIV_ROUND_UP(pat_len, 8),
8316 rule->patterns[j].mask) ||
8317 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8318 rule->patterns[j].pattern) ||
8319 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8320 rule->patterns[j].pkt_offset))
8321 return -ENOBUFS;
8322 nla_nest_end(msg, nl_pat);
8323 }
8324 nla_nest_end(msg, nl_pats);
8325 nla_nest_end(msg, nl_rule);
8326 }
8327 nla_nest_end(msg, nl_rules);
8328
8329 return 0;
8330}
8331
8332static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8333{
8334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8335 struct sk_buff *msg;
8336 void *hdr;
8337
8338 if (!rdev->wiphy.coalesce)
8339 return -EOPNOTSUPP;
8340
8341 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8342 if (!msg)
8343 return -ENOMEM;
8344
8345 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8346 NL80211_CMD_GET_COALESCE);
8347 if (!hdr)
8348 goto nla_put_failure;
8349
8350 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8351 goto nla_put_failure;
8352
8353 genlmsg_end(msg, hdr);
8354 return genlmsg_reply(msg, info);
8355
8356nla_put_failure:
8357 nlmsg_free(msg);
8358 return -ENOBUFS;
8359}
8360
8361void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8362{
8363 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8364 int i, j;
8365 struct cfg80211_coalesce_rules *rule;
8366
8367 if (!coalesce)
8368 return;
8369
8370 for (i = 0; i < coalesce->n_rules; i++) {
8371 rule = &coalesce->rules[i];
8372 for (j = 0; j < rule->n_patterns; j++)
8373 kfree(rule->patterns[j].mask);
8374 kfree(rule->patterns);
8375 }
8376 kfree(coalesce->rules);
8377 kfree(coalesce);
8378 rdev->coalesce = NULL;
8379}
8380
8381static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8382 struct nlattr *rule,
8383 struct cfg80211_coalesce_rules *new_rule)
8384{
8385 int err, i;
8386 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8387 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8388 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8389 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8390
8391 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8392 nla_len(rule), nl80211_coalesce_policy);
8393 if (err)
8394 return err;
8395
8396 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8397 new_rule->delay =
8398 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8399 if (new_rule->delay > coalesce->max_delay)
8400 return -EINVAL;
8401
8402 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8403 new_rule->condition =
8404 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8405 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8406 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8407 return -EINVAL;
8408
8409 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8410 return -EINVAL;
8411
8412 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8413 rem)
8414 n_patterns++;
8415 if (n_patterns > coalesce->n_patterns)
8416 return -EINVAL;
8417
8418 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8419 GFP_KERNEL);
8420 if (!new_rule->patterns)
8421 return -ENOMEM;
8422
8423 new_rule->n_patterns = n_patterns;
8424 i = 0;
8425
8426 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8427 rem) {
8428 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8429 nla_len(pat), NULL);
8430 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8431 !pat_tb[NL80211_PKTPAT_PATTERN])
8432 return -EINVAL;
8433 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8434 mask_len = DIV_ROUND_UP(pat_len, 8);
8435 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8436 return -EINVAL;
8437 if (pat_len > coalesce->pattern_max_len ||
8438 pat_len < coalesce->pattern_min_len)
8439 return -EINVAL;
8440
8441 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8442 pkt_offset = 0;
8443 else
8444 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8445 if (pkt_offset > coalesce->max_pkt_offset)
8446 return -EINVAL;
8447 new_rule->patterns[i].pkt_offset = pkt_offset;
8448
8449 new_rule->patterns[i].mask =
8450 kmalloc(mask_len + pat_len, GFP_KERNEL);
8451 if (!new_rule->patterns[i].mask)
8452 return -ENOMEM;
8453 new_rule->patterns[i].pattern =
8454 new_rule->patterns[i].mask + mask_len;
8455 memcpy(new_rule->patterns[i].mask,
8456 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8457 new_rule->patterns[i].pattern_len = pat_len;
8458 memcpy(new_rule->patterns[i].pattern,
8459 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8460 i++;
8461 }
8462
8463 return 0;
8464}
8465
8466static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8467{
8468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8469 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8470 struct cfg80211_coalesce new_coalesce = {};
8471 struct cfg80211_coalesce *n_coalesce;
8472 int err, rem_rule, n_rules = 0, i, j;
8473 struct nlattr *rule;
8474 struct cfg80211_coalesce_rules *tmp_rule;
8475
8476 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8477 return -EOPNOTSUPP;
8478
8479 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8480 cfg80211_rdev_free_coalesce(rdev);
8481 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8482 return 0;
8483 }
8484
8485 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8486 rem_rule)
8487 n_rules++;
8488 if (n_rules > coalesce->n_rules)
8489 return -EINVAL;
8490
8491 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8492 GFP_KERNEL);
8493 if (!new_coalesce.rules)
8494 return -ENOMEM;
8495
8496 new_coalesce.n_rules = n_rules;
8497 i = 0;
8498
8499 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8500 rem_rule) {
8501 err = nl80211_parse_coalesce_rule(rdev, rule,
8502 &new_coalesce.rules[i]);
8503 if (err)
8504 goto error;
8505
8506 i++;
8507 }
8508
8509 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8510 if (err)
8511 goto error;
8512
8513 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8514 if (!n_coalesce) {
8515 err = -ENOMEM;
8516 goto error;
8517 }
8518 cfg80211_rdev_free_coalesce(rdev);
8519 rdev->coalesce = n_coalesce;
8520
8521 return 0;
8522error:
8523 for (i = 0; i < new_coalesce.n_rules; i++) {
8524 tmp_rule = &new_coalesce.rules[i];
8525 for (j = 0; j < tmp_rule->n_patterns; j++)
8526 kfree(tmp_rule->patterns[j].mask);
8527 kfree(tmp_rule->patterns);
8528 }
8529 kfree(new_coalesce.rules);
8530
8531 return err;
8532}
8533
Johannes Berge5497d72011-07-05 16:35:40 +02008534static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8535{
8536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8537 struct net_device *dev = info->user_ptr[1];
8538 struct wireless_dev *wdev = dev->ieee80211_ptr;
8539 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8540 struct cfg80211_gtk_rekey_data rekey_data;
8541 int err;
8542
8543 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8544 return -EINVAL;
8545
8546 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8547 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8548 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8549 nl80211_rekey_policy);
8550 if (err)
8551 return err;
8552
8553 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8554 return -ERANGE;
8555 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8556 return -ERANGE;
8557 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8558 return -ERANGE;
8559
8560 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8561 NL80211_KEK_LEN);
8562 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8563 NL80211_KCK_LEN);
8564 memcpy(rekey_data.replay_ctr,
8565 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8566 NL80211_REPLAY_CTR_LEN);
8567
8568 wdev_lock(wdev);
8569 if (!wdev->current_bss) {
8570 err = -ENOTCONN;
8571 goto out;
8572 }
8573
8574 if (!rdev->ops->set_rekey_data) {
8575 err = -EOPNOTSUPP;
8576 goto out;
8577 }
8578
Hila Gonene35e4d22012-06-27 17:19:42 +03008579 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008580 out:
8581 wdev_unlock(wdev);
8582 return err;
8583}
8584
Johannes Berg28946da2011-11-04 11:18:12 +01008585static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8586 struct genl_info *info)
8587{
8588 struct net_device *dev = info->user_ptr[1];
8589 struct wireless_dev *wdev = dev->ieee80211_ptr;
8590
8591 if (wdev->iftype != NL80211_IFTYPE_AP &&
8592 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8593 return -EINVAL;
8594
Eric W. Biederman15e47302012-09-07 20:12:54 +00008595 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008596 return -EBUSY;
8597
Eric W. Biederman15e47302012-09-07 20:12:54 +00008598 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008599 return 0;
8600}
8601
Johannes Berg7f6cf312011-11-04 11:18:15 +01008602static int nl80211_probe_client(struct sk_buff *skb,
8603 struct genl_info *info)
8604{
8605 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8606 struct net_device *dev = info->user_ptr[1];
8607 struct wireless_dev *wdev = dev->ieee80211_ptr;
8608 struct sk_buff *msg;
8609 void *hdr;
8610 const u8 *addr;
8611 u64 cookie;
8612 int err;
8613
8614 if (wdev->iftype != NL80211_IFTYPE_AP &&
8615 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8616 return -EOPNOTSUPP;
8617
8618 if (!info->attrs[NL80211_ATTR_MAC])
8619 return -EINVAL;
8620
8621 if (!rdev->ops->probe_client)
8622 return -EOPNOTSUPP;
8623
8624 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8625 if (!msg)
8626 return -ENOMEM;
8627
Eric W. Biederman15e47302012-09-07 20:12:54 +00008628 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008629 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008630 if (!hdr) {
8631 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008632 goto free_msg;
8633 }
8634
8635 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8636
Hila Gonene35e4d22012-06-27 17:19:42 +03008637 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008638 if (err)
8639 goto free_msg;
8640
David S. Miller9360ffd2012-03-29 04:41:26 -04008641 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8642 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008643
8644 genlmsg_end(msg, hdr);
8645
8646 return genlmsg_reply(msg, info);
8647
8648 nla_put_failure:
8649 err = -ENOBUFS;
8650 free_msg:
8651 nlmsg_free(msg);
8652 return err;
8653}
8654
Johannes Berg5e760232011-11-04 11:18:17 +01008655static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8656{
8657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008658 struct cfg80211_beacon_registration *reg, *nreg;
8659 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008660
8661 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8662 return -EOPNOTSUPP;
8663
Ben Greear37c73b52012-10-26 14:49:25 -07008664 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8665 if (!nreg)
8666 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008667
Ben Greear37c73b52012-10-26 14:49:25 -07008668 /* First, check if already registered. */
8669 spin_lock_bh(&rdev->beacon_registrations_lock);
8670 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8671 if (reg->nlportid == info->snd_portid) {
8672 rv = -EALREADY;
8673 goto out_err;
8674 }
8675 }
8676 /* Add it to the list */
8677 nreg->nlportid = info->snd_portid;
8678 list_add(&nreg->list, &rdev->beacon_registrations);
8679
8680 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008681
8682 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008683out_err:
8684 spin_unlock_bh(&rdev->beacon_registrations_lock);
8685 kfree(nreg);
8686 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008687}
8688
Johannes Berg98104fde2012-06-16 00:19:54 +02008689static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8690{
8691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8692 struct wireless_dev *wdev = info->user_ptr[1];
8693 int err;
8694
8695 if (!rdev->ops->start_p2p_device)
8696 return -EOPNOTSUPP;
8697
8698 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8699 return -EOPNOTSUPP;
8700
8701 if (wdev->p2p_started)
8702 return 0;
8703
Johannes Berg98104fde2012-06-16 00:19:54 +02008704 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008705 if (err)
8706 return err;
8707
Johannes Bergeeb126e2012-10-23 15:16:50 +02008708 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008709 if (err)
8710 return err;
8711
8712 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008713 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008714
8715 return 0;
8716}
8717
8718static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8719{
8720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8721 struct wireless_dev *wdev = info->user_ptr[1];
8722
8723 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8724 return -EOPNOTSUPP;
8725
8726 if (!rdev->ops->stop_p2p_device)
8727 return -EOPNOTSUPP;
8728
Johannes Bergf9f47522013-03-19 15:04:07 +01008729 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008730
8731 return 0;
8732}
8733
Johannes Berg3713b4e2013-02-14 16:19:38 +01008734static int nl80211_get_protocol_features(struct sk_buff *skb,
8735 struct genl_info *info)
8736{
8737 void *hdr;
8738 struct sk_buff *msg;
8739
8740 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8741 if (!msg)
8742 return -ENOMEM;
8743
8744 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8745 NL80211_CMD_GET_PROTOCOL_FEATURES);
8746 if (!hdr)
8747 goto nla_put_failure;
8748
8749 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8750 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8751 goto nla_put_failure;
8752
8753 genlmsg_end(msg, hdr);
8754 return genlmsg_reply(msg, info);
8755
8756 nla_put_failure:
8757 kfree_skb(msg);
8758 return -ENOBUFS;
8759}
8760
Jouni Malinen355199e2013-02-27 17:14:27 +02008761static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8762{
8763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8764 struct cfg80211_update_ft_ies_params ft_params;
8765 struct net_device *dev = info->user_ptr[1];
8766
8767 if (!rdev->ops->update_ft_ies)
8768 return -EOPNOTSUPP;
8769
8770 if (!info->attrs[NL80211_ATTR_MDID] ||
8771 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8772 return -EINVAL;
8773
8774 memset(&ft_params, 0, sizeof(ft_params));
8775 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8776 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8777 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8778
8779 return rdev_update_ft_ies(rdev, dev, &ft_params);
8780}
8781
Arend van Spriel5de17982013-04-18 15:49:00 +02008782static int nl80211_crit_protocol_start(struct sk_buff *skb,
8783 struct genl_info *info)
8784{
8785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8786 struct wireless_dev *wdev = info->user_ptr[1];
8787 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8788 u16 duration;
8789 int ret;
8790
8791 if (!rdev->ops->crit_proto_start)
8792 return -EOPNOTSUPP;
8793
8794 if (WARN_ON(!rdev->ops->crit_proto_stop))
8795 return -EINVAL;
8796
8797 if (rdev->crit_proto_nlportid)
8798 return -EBUSY;
8799
8800 /* determine protocol if provided */
8801 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8802 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8803
8804 if (proto >= NUM_NL80211_CRIT_PROTO)
8805 return -EINVAL;
8806
8807 /* timeout must be provided */
8808 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8809 return -EINVAL;
8810
8811 duration =
8812 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8813
8814 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8815 return -ERANGE;
8816
8817 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8818 if (!ret)
8819 rdev->crit_proto_nlportid = info->snd_portid;
8820
8821 return ret;
8822}
8823
8824static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8825 struct genl_info *info)
8826{
8827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8828 struct wireless_dev *wdev = info->user_ptr[1];
8829
8830 if (!rdev->ops->crit_proto_stop)
8831 return -EOPNOTSUPP;
8832
8833 if (rdev->crit_proto_nlportid) {
8834 rdev->crit_proto_nlportid = 0;
8835 rdev_crit_proto_stop(rdev, wdev);
8836 }
8837 return 0;
8838}
8839
Johannes Berg4c476992010-10-04 21:36:35 +02008840#define NL80211_FLAG_NEED_WIPHY 0x01
8841#define NL80211_FLAG_NEED_NETDEV 0x02
8842#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008843#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8844#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8845 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008846#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008847/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008848#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8849 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008850
8851static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8852 struct genl_info *info)
8853{
8854 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008855 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008856 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008857 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8858
8859 if (rtnl)
8860 rtnl_lock();
8861
8862 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008863 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008864 if (IS_ERR(rdev)) {
8865 if (rtnl)
8866 rtnl_unlock();
8867 return PTR_ERR(rdev);
8868 }
8869 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008870 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8871 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008872 ASSERT_RTNL();
8873
Johannes Berg89a54e42012-06-15 14:33:17 +02008874 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8875 info->attrs);
8876 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008877 if (rtnl)
8878 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008879 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008880 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008881
Johannes Berg89a54e42012-06-15 14:33:17 +02008882 dev = wdev->netdev;
8883 rdev = wiphy_to_dev(wdev->wiphy);
8884
Johannes Berg1bf614e2012-06-15 15:23:36 +02008885 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8886 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008887 if (rtnl)
8888 rtnl_unlock();
8889 return -EINVAL;
8890 }
8891
8892 info->user_ptr[1] = dev;
8893 } else {
8894 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008895 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008896
Johannes Berg1bf614e2012-06-15 15:23:36 +02008897 if (dev) {
8898 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8899 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008900 if (rtnl)
8901 rtnl_unlock();
8902 return -ENETDOWN;
8903 }
8904
8905 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008906 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8907 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008908 if (rtnl)
8909 rtnl_unlock();
8910 return -ENETDOWN;
8911 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008912 }
8913
Johannes Berg4c476992010-10-04 21:36:35 +02008914 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008915 }
8916
8917 return 0;
8918}
8919
8920static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8921 struct genl_info *info)
8922{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008923 if (info->user_ptr[1]) {
8924 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8925 struct wireless_dev *wdev = info->user_ptr[1];
8926
8927 if (wdev->netdev)
8928 dev_put(wdev->netdev);
8929 } else {
8930 dev_put(info->user_ptr[1]);
8931 }
8932 }
Johannes Berg4c476992010-10-04 21:36:35 +02008933 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8934 rtnl_unlock();
8935}
8936
Johannes Berg55682962007-09-20 13:09:35 -04008937static struct genl_ops nl80211_ops[] = {
8938 {
8939 .cmd = NL80211_CMD_GET_WIPHY,
8940 .doit = nl80211_get_wiphy,
8941 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008942 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008943 .policy = nl80211_policy,
8944 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008945 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8946 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008947 },
8948 {
8949 .cmd = NL80211_CMD_SET_WIPHY,
8950 .doit = nl80211_set_wiphy,
8951 .policy = nl80211_policy,
8952 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008953 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008954 },
8955 {
8956 .cmd = NL80211_CMD_GET_INTERFACE,
8957 .doit = nl80211_get_interface,
8958 .dumpit = nl80211_dump_interface,
8959 .policy = nl80211_policy,
8960 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008961 .internal_flags = NL80211_FLAG_NEED_WDEV |
8962 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008963 },
8964 {
8965 .cmd = NL80211_CMD_SET_INTERFACE,
8966 .doit = nl80211_set_interface,
8967 .policy = nl80211_policy,
8968 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008969 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8970 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008971 },
8972 {
8973 .cmd = NL80211_CMD_NEW_INTERFACE,
8974 .doit = nl80211_new_interface,
8975 .policy = nl80211_policy,
8976 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008977 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8978 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008979 },
8980 {
8981 .cmd = NL80211_CMD_DEL_INTERFACE,
8982 .doit = nl80211_del_interface,
8983 .policy = nl80211_policy,
8984 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008985 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008986 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008987 },
Johannes Berg41ade002007-12-19 02:03:29 +01008988 {
8989 .cmd = NL80211_CMD_GET_KEY,
8990 .doit = nl80211_get_key,
8991 .policy = nl80211_policy,
8992 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008993 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008994 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008995 },
8996 {
8997 .cmd = NL80211_CMD_SET_KEY,
8998 .doit = nl80211_set_key,
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,
Johannes Berg41ade002007-12-19 02:03:29 +01009003 },
9004 {
9005 .cmd = NL80211_CMD_NEW_KEY,
9006 .doit = nl80211_new_key,
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,
Johannes Berg41ade002007-12-19 02:03:29 +01009011 },
9012 {
9013 .cmd = NL80211_CMD_DEL_KEY,
9014 .doit = nl80211_del_key,
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,
Johannes Berg41ade002007-12-19 02:03:29 +01009019 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009020 {
9021 .cmd = NL80211_CMD_SET_BEACON,
9022 .policy = nl80211_policy,
9023 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009024 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009026 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009027 },
9028 {
Johannes Berg88600202012-02-13 15:17:18 +01009029 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009030 .policy = nl80211_policy,
9031 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009032 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009034 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009035 },
9036 {
Johannes Berg88600202012-02-13 15:17:18 +01009037 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009038 .policy = nl80211_policy,
9039 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009040 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009042 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009043 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009044 {
9045 .cmd = NL80211_CMD_GET_STATION,
9046 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009047 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009048 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009049 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9050 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009051 },
9052 {
9053 .cmd = NL80211_CMD_SET_STATION,
9054 .doit = nl80211_set_station,
9055 .policy = nl80211_policy,
9056 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009058 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009059 },
9060 {
9061 .cmd = NL80211_CMD_NEW_STATION,
9062 .doit = nl80211_new_station,
9063 .policy = nl80211_policy,
9064 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009066 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009067 },
9068 {
9069 .cmd = NL80211_CMD_DEL_STATION,
9070 .doit = nl80211_del_station,
9071 .policy = nl80211_policy,
9072 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009073 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009074 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009075 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009076 {
9077 .cmd = NL80211_CMD_GET_MPATH,
9078 .doit = nl80211_get_mpath,
9079 .dumpit = nl80211_dump_mpath,
9080 .policy = nl80211_policy,
9081 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009083 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009084 },
9085 {
9086 .cmd = NL80211_CMD_SET_MPATH,
9087 .doit = nl80211_set_mpath,
9088 .policy = nl80211_policy,
9089 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009091 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009092 },
9093 {
9094 .cmd = NL80211_CMD_NEW_MPATH,
9095 .doit = nl80211_new_mpath,
9096 .policy = nl80211_policy,
9097 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009098 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009099 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009100 },
9101 {
9102 .cmd = NL80211_CMD_DEL_MPATH,
9103 .doit = nl80211_del_mpath,
9104 .policy = nl80211_policy,
9105 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009106 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009107 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009108 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009109 {
9110 .cmd = NL80211_CMD_SET_BSS,
9111 .doit = nl80211_set_bss,
9112 .policy = nl80211_policy,
9113 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009114 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009115 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009116 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009117 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009118 .cmd = NL80211_CMD_GET_REG,
9119 .doit = nl80211_get_reg,
9120 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009121 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009122 /* can be retrieved by unprivileged users */
9123 },
9124 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009125 .cmd = NL80211_CMD_SET_REG,
9126 .doit = nl80211_set_reg,
9127 .policy = nl80211_policy,
9128 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009129 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009130 },
9131 {
9132 .cmd = NL80211_CMD_REQ_SET_REG,
9133 .doit = nl80211_req_set_reg,
9134 .policy = nl80211_policy,
9135 .flags = GENL_ADMIN_PERM,
9136 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009137 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009138 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9139 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009140 .policy = nl80211_policy,
9141 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009142 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009143 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009144 },
9145 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009146 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9147 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009148 .policy = nl80211_policy,
9149 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009150 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009151 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009152 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009153 {
Johannes Berg2a519312009-02-10 21:25:55 +01009154 .cmd = NL80211_CMD_TRIGGER_SCAN,
9155 .doit = nl80211_trigger_scan,
9156 .policy = nl80211_policy,
9157 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009158 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009159 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009160 },
9161 {
9162 .cmd = NL80211_CMD_GET_SCAN,
9163 .policy = nl80211_policy,
9164 .dumpit = nl80211_dump_scan,
9165 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009166 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009167 .cmd = NL80211_CMD_START_SCHED_SCAN,
9168 .doit = nl80211_start_sched_scan,
9169 .policy = nl80211_policy,
9170 .flags = GENL_ADMIN_PERM,
9171 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9172 NL80211_FLAG_NEED_RTNL,
9173 },
9174 {
9175 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9176 .doit = nl80211_stop_sched_scan,
9177 .policy = nl80211_policy,
9178 .flags = GENL_ADMIN_PERM,
9179 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9180 NL80211_FLAG_NEED_RTNL,
9181 },
9182 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009183 .cmd = NL80211_CMD_AUTHENTICATE,
9184 .doit = nl80211_authenticate,
9185 .policy = nl80211_policy,
9186 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009187 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009188 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009189 },
9190 {
9191 .cmd = NL80211_CMD_ASSOCIATE,
9192 .doit = nl80211_associate,
9193 .policy = nl80211_policy,
9194 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009195 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009196 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009197 },
9198 {
9199 .cmd = NL80211_CMD_DEAUTHENTICATE,
9200 .doit = nl80211_deauthenticate,
9201 .policy = nl80211_policy,
9202 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009203 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009204 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009205 },
9206 {
9207 .cmd = NL80211_CMD_DISASSOCIATE,
9208 .doit = nl80211_disassociate,
9209 .policy = nl80211_policy,
9210 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009211 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009212 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009213 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009214 {
9215 .cmd = NL80211_CMD_JOIN_IBSS,
9216 .doit = nl80211_join_ibss,
9217 .policy = nl80211_policy,
9218 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009220 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009221 },
9222 {
9223 .cmd = NL80211_CMD_LEAVE_IBSS,
9224 .doit = nl80211_leave_ibss,
9225 .policy = nl80211_policy,
9226 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009227 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009228 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009229 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009230#ifdef CONFIG_NL80211_TESTMODE
9231 {
9232 .cmd = NL80211_CMD_TESTMODE,
9233 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009234 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009235 .policy = nl80211_policy,
9236 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009237 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9238 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009239 },
9240#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009241 {
9242 .cmd = NL80211_CMD_CONNECT,
9243 .doit = nl80211_connect,
9244 .policy = nl80211_policy,
9245 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009247 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009248 },
9249 {
9250 .cmd = NL80211_CMD_DISCONNECT,
9251 .doit = nl80211_disconnect,
9252 .policy = nl80211_policy,
9253 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009254 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009255 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009256 },
Johannes Berg463d0182009-07-14 00:33:35 +02009257 {
9258 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9259 .doit = nl80211_wiphy_netns,
9260 .policy = nl80211_policy,
9261 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009262 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9263 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009264 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009265 {
9266 .cmd = NL80211_CMD_GET_SURVEY,
9267 .policy = nl80211_policy,
9268 .dumpit = nl80211_dump_survey,
9269 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009270 {
9271 .cmd = NL80211_CMD_SET_PMKSA,
9272 .doit = nl80211_setdel_pmksa,
9273 .policy = nl80211_policy,
9274 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009275 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009276 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009277 },
9278 {
9279 .cmd = NL80211_CMD_DEL_PMKSA,
9280 .doit = nl80211_setdel_pmksa,
9281 .policy = nl80211_policy,
9282 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009283 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009284 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009285 },
9286 {
9287 .cmd = NL80211_CMD_FLUSH_PMKSA,
9288 .doit = nl80211_flush_pmksa,
9289 .policy = nl80211_policy,
9290 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009291 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009292 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009293 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009294 {
9295 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9296 .doit = nl80211_remain_on_channel,
9297 .policy = nl80211_policy,
9298 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009299 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009300 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009301 },
9302 {
9303 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9304 .doit = nl80211_cancel_remain_on_channel,
9305 .policy = nl80211_policy,
9306 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009307 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009308 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009309 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009310 {
9311 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9312 .doit = nl80211_set_tx_bitrate_mask,
9313 .policy = nl80211_policy,
9314 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009315 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9316 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009317 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009318 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009319 .cmd = NL80211_CMD_REGISTER_FRAME,
9320 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009321 .policy = nl80211_policy,
9322 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009323 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009324 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009325 },
9326 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009327 .cmd = NL80211_CMD_FRAME,
9328 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009329 .policy = nl80211_policy,
9330 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009331 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009332 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009333 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009334 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009335 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9336 .doit = nl80211_tx_mgmt_cancel_wait,
9337 .policy = nl80211_policy,
9338 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009339 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009340 NL80211_FLAG_NEED_RTNL,
9341 },
9342 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009343 .cmd = NL80211_CMD_SET_POWER_SAVE,
9344 .doit = nl80211_set_power_save,
9345 .policy = nl80211_policy,
9346 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009347 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9348 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009349 },
9350 {
9351 .cmd = NL80211_CMD_GET_POWER_SAVE,
9352 .doit = nl80211_get_power_save,
9353 .policy = nl80211_policy,
9354 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009355 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9356 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009357 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009358 {
9359 .cmd = NL80211_CMD_SET_CQM,
9360 .doit = nl80211_set_cqm,
9361 .policy = nl80211_policy,
9362 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009363 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9364 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009365 },
Johannes Bergf444de02010-05-05 15:25:02 +02009366 {
9367 .cmd = NL80211_CMD_SET_CHANNEL,
9368 .doit = nl80211_set_channel,
9369 .policy = nl80211_policy,
9370 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009371 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9372 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009373 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009374 {
9375 .cmd = NL80211_CMD_SET_WDS_PEER,
9376 .doit = nl80211_set_wds_peer,
9377 .policy = nl80211_policy,
9378 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009379 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9380 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009381 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009382 {
9383 .cmd = NL80211_CMD_JOIN_MESH,
9384 .doit = nl80211_join_mesh,
9385 .policy = nl80211_policy,
9386 .flags = GENL_ADMIN_PERM,
9387 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9388 NL80211_FLAG_NEED_RTNL,
9389 },
9390 {
9391 .cmd = NL80211_CMD_LEAVE_MESH,
9392 .doit = nl80211_leave_mesh,
9393 .policy = nl80211_policy,
9394 .flags = GENL_ADMIN_PERM,
9395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9396 NL80211_FLAG_NEED_RTNL,
9397 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009398#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009399 {
9400 .cmd = NL80211_CMD_GET_WOWLAN,
9401 .doit = nl80211_get_wowlan,
9402 .policy = nl80211_policy,
9403 /* can be retrieved by unprivileged users */
9404 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9405 NL80211_FLAG_NEED_RTNL,
9406 },
9407 {
9408 .cmd = NL80211_CMD_SET_WOWLAN,
9409 .doit = nl80211_set_wowlan,
9410 .policy = nl80211_policy,
9411 .flags = GENL_ADMIN_PERM,
9412 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9413 NL80211_FLAG_NEED_RTNL,
9414 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009415#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009416 {
9417 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9418 .doit = nl80211_set_rekey_data,
9419 .policy = nl80211_policy,
9420 .flags = GENL_ADMIN_PERM,
9421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9422 NL80211_FLAG_NEED_RTNL,
9423 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009424 {
9425 .cmd = NL80211_CMD_TDLS_MGMT,
9426 .doit = nl80211_tdls_mgmt,
9427 .policy = nl80211_policy,
9428 .flags = GENL_ADMIN_PERM,
9429 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9430 NL80211_FLAG_NEED_RTNL,
9431 },
9432 {
9433 .cmd = NL80211_CMD_TDLS_OPER,
9434 .doit = nl80211_tdls_oper,
9435 .policy = nl80211_policy,
9436 .flags = GENL_ADMIN_PERM,
9437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9438 NL80211_FLAG_NEED_RTNL,
9439 },
Johannes Berg28946da2011-11-04 11:18:12 +01009440 {
9441 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9442 .doit = nl80211_register_unexpected_frame,
9443 .policy = nl80211_policy,
9444 .flags = GENL_ADMIN_PERM,
9445 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9446 NL80211_FLAG_NEED_RTNL,
9447 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009448 {
9449 .cmd = NL80211_CMD_PROBE_CLIENT,
9450 .doit = nl80211_probe_client,
9451 .policy = nl80211_policy,
9452 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009454 NL80211_FLAG_NEED_RTNL,
9455 },
Johannes Berg5e760232011-11-04 11:18:17 +01009456 {
9457 .cmd = NL80211_CMD_REGISTER_BEACONS,
9458 .doit = nl80211_register_beacons,
9459 .policy = nl80211_policy,
9460 .flags = GENL_ADMIN_PERM,
9461 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9462 NL80211_FLAG_NEED_RTNL,
9463 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009464 {
9465 .cmd = NL80211_CMD_SET_NOACK_MAP,
9466 .doit = nl80211_set_noack_map,
9467 .policy = nl80211_policy,
9468 .flags = GENL_ADMIN_PERM,
9469 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9470 NL80211_FLAG_NEED_RTNL,
9471 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009472 {
9473 .cmd = NL80211_CMD_START_P2P_DEVICE,
9474 .doit = nl80211_start_p2p_device,
9475 .policy = nl80211_policy,
9476 .flags = GENL_ADMIN_PERM,
9477 .internal_flags = NL80211_FLAG_NEED_WDEV |
9478 NL80211_FLAG_NEED_RTNL,
9479 },
9480 {
9481 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9482 .doit = nl80211_stop_p2p_device,
9483 .policy = nl80211_policy,
9484 .flags = GENL_ADMIN_PERM,
9485 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9486 NL80211_FLAG_NEED_RTNL,
9487 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009488 {
9489 .cmd = NL80211_CMD_SET_MCAST_RATE,
9490 .doit = nl80211_set_mcast_rate,
9491 .policy = nl80211_policy,
9492 .flags = GENL_ADMIN_PERM,
9493 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9494 NL80211_FLAG_NEED_RTNL,
9495 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309496 {
9497 .cmd = NL80211_CMD_SET_MAC_ACL,
9498 .doit = nl80211_set_mac_acl,
9499 .policy = nl80211_policy,
9500 .flags = GENL_ADMIN_PERM,
9501 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9502 NL80211_FLAG_NEED_RTNL,
9503 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009504 {
9505 .cmd = NL80211_CMD_RADAR_DETECT,
9506 .doit = nl80211_start_radar_detection,
9507 .policy = nl80211_policy,
9508 .flags = GENL_ADMIN_PERM,
9509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9510 NL80211_FLAG_NEED_RTNL,
9511 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009512 {
9513 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9514 .doit = nl80211_get_protocol_features,
9515 .policy = nl80211_policy,
9516 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009517 {
9518 .cmd = NL80211_CMD_UPDATE_FT_IES,
9519 .doit = nl80211_update_ft_ies,
9520 .policy = nl80211_policy,
9521 .flags = GENL_ADMIN_PERM,
9522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9523 NL80211_FLAG_NEED_RTNL,
9524 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009525 {
9526 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9527 .doit = nl80211_crit_protocol_start,
9528 .policy = nl80211_policy,
9529 .flags = GENL_ADMIN_PERM,
9530 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9531 NL80211_FLAG_NEED_RTNL,
9532 },
9533 {
9534 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9535 .doit = nl80211_crit_protocol_stop,
9536 .policy = nl80211_policy,
9537 .flags = GENL_ADMIN_PERM,
9538 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9539 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009540 },
9541 {
9542 .cmd = NL80211_CMD_GET_COALESCE,
9543 .doit = nl80211_get_coalesce,
9544 .policy = nl80211_policy,
9545 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9546 NL80211_FLAG_NEED_RTNL,
9547 },
9548 {
9549 .cmd = NL80211_CMD_SET_COALESCE,
9550 .doit = nl80211_set_coalesce,
9551 .policy = nl80211_policy,
9552 .flags = GENL_ADMIN_PERM,
9553 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9554 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009555 },
9556 {
9557 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9558 .doit = nl80211_channel_switch,
9559 .policy = nl80211_policy,
9560 .flags = GENL_ADMIN_PERM,
9561 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9562 NL80211_FLAG_NEED_RTNL,
9563 },
Johannes Berg55682962007-09-20 13:09:35 -04009564};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009565
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009566static struct genl_multicast_group nl80211_mlme_mcgrp = {
9567 .name = "mlme",
9568};
Johannes Berg55682962007-09-20 13:09:35 -04009569
9570/* multicast groups */
9571static struct genl_multicast_group nl80211_config_mcgrp = {
9572 .name = "config",
9573};
Johannes Berg2a519312009-02-10 21:25:55 +01009574static struct genl_multicast_group nl80211_scan_mcgrp = {
9575 .name = "scan",
9576};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009577static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9578 .name = "regulatory",
9579};
Johannes Berg55682962007-09-20 13:09:35 -04009580
9581/* notification functions */
9582
9583void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9584{
9585 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009586 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009587
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009588 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009589 if (!msg)
9590 return;
9591
Johannes Berg86e8cf92013-06-19 10:57:22 +02009592 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009593 nlmsg_free(msg);
9594 return;
9595 }
9596
Johannes Berg463d0182009-07-14 00:33:35 +02009597 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9598 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009599}
9600
Johannes Berg362a4152009-05-24 16:43:15 +02009601static int nl80211_add_scan_req(struct sk_buff *msg,
9602 struct cfg80211_registered_device *rdev)
9603{
9604 struct cfg80211_scan_request *req = rdev->scan_req;
9605 struct nlattr *nest;
9606 int i;
9607
9608 if (WARN_ON(!req))
9609 return 0;
9610
9611 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9612 if (!nest)
9613 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009614 for (i = 0; i < req->n_ssids; i++) {
9615 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9616 goto nla_put_failure;
9617 }
Johannes Berg362a4152009-05-24 16:43:15 +02009618 nla_nest_end(msg, nest);
9619
9620 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9621 if (!nest)
9622 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009623 for (i = 0; i < req->n_channels; i++) {
9624 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9625 goto nla_put_failure;
9626 }
Johannes Berg362a4152009-05-24 16:43:15 +02009627 nla_nest_end(msg, nest);
9628
David S. Miller9360ffd2012-03-29 04:41:26 -04009629 if (req->ie &&
9630 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9631 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009632
Sam Lefflered4737712012-10-11 21:03:31 -07009633 if (req->flags)
9634 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9635
Johannes Berg362a4152009-05-24 16:43:15 +02009636 return 0;
9637 nla_put_failure:
9638 return -ENOBUFS;
9639}
9640
Johannes Berga538e2d2009-06-16 19:56:42 +02009641static int nl80211_send_scan_msg(struct sk_buff *msg,
9642 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009643 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009644 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009645 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009646{
9647 void *hdr;
9648
Eric W. Biederman15e47302012-09-07 20:12:54 +00009649 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009650 if (!hdr)
9651 return -1;
9652
David S. Miller9360ffd2012-03-29 04:41:26 -04009653 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009654 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9655 wdev->netdev->ifindex)) ||
9656 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009657 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009658
Johannes Berg362a4152009-05-24 16:43:15 +02009659 /* ignore errors and send incomplete event anyway */
9660 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009661
9662 return genlmsg_end(msg, hdr);
9663
9664 nla_put_failure:
9665 genlmsg_cancel(msg, hdr);
9666 return -EMSGSIZE;
9667}
9668
Luciano Coelho807f8a82011-05-11 17:09:35 +03009669static int
9670nl80211_send_sched_scan_msg(struct sk_buff *msg,
9671 struct cfg80211_registered_device *rdev,
9672 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009673 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009674{
9675 void *hdr;
9676
Eric W. Biederman15e47302012-09-07 20:12:54 +00009677 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009678 if (!hdr)
9679 return -1;
9680
David S. Miller9360ffd2012-03-29 04:41:26 -04009681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9682 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9683 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009684
9685 return genlmsg_end(msg, hdr);
9686
9687 nla_put_failure:
9688 genlmsg_cancel(msg, hdr);
9689 return -EMSGSIZE;
9690}
9691
Johannes Berga538e2d2009-06-16 19:56:42 +02009692void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009693 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009694{
9695 struct sk_buff *msg;
9696
Thomas Graf58050fc2012-06-28 03:57:45 +00009697 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009698 if (!msg)
9699 return;
9700
Johannes Bergfd014282012-06-18 19:17:03 +02009701 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009702 NL80211_CMD_TRIGGER_SCAN) < 0) {
9703 nlmsg_free(msg);
9704 return;
9705 }
9706
Johannes Berg463d0182009-07-14 00:33:35 +02009707 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9708 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009709}
9710
Johannes Berg2a519312009-02-10 21:25:55 +01009711void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009712 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009713{
9714 struct sk_buff *msg;
9715
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009716 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009717 if (!msg)
9718 return;
9719
Johannes Bergfd014282012-06-18 19:17:03 +02009720 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009721 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009722 nlmsg_free(msg);
9723 return;
9724 }
9725
Johannes Berg463d0182009-07-14 00:33:35 +02009726 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9727 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009728}
9729
9730void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009731 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009732{
9733 struct sk_buff *msg;
9734
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009735 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009736 if (!msg)
9737 return;
9738
Johannes Bergfd014282012-06-18 19:17:03 +02009739 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009740 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009741 nlmsg_free(msg);
9742 return;
9743 }
9744
Johannes Berg463d0182009-07-14 00:33:35 +02009745 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9746 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009747}
9748
Luciano Coelho807f8a82011-05-11 17:09:35 +03009749void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9750 struct net_device *netdev)
9751{
9752 struct sk_buff *msg;
9753
9754 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9755 if (!msg)
9756 return;
9757
9758 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9759 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9760 nlmsg_free(msg);
9761 return;
9762 }
9763
9764 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9765 nl80211_scan_mcgrp.id, GFP_KERNEL);
9766}
9767
9768void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9769 struct net_device *netdev, u32 cmd)
9770{
9771 struct sk_buff *msg;
9772
Thomas Graf58050fc2012-06-28 03:57:45 +00009773 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009774 if (!msg)
9775 return;
9776
9777 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9778 nlmsg_free(msg);
9779 return;
9780 }
9781
9782 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9783 nl80211_scan_mcgrp.id, GFP_KERNEL);
9784}
9785
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009786/*
9787 * This can happen on global regulatory changes or device specific settings
9788 * based on custom world regulatory domains.
9789 */
9790void nl80211_send_reg_change_event(struct regulatory_request *request)
9791{
9792 struct sk_buff *msg;
9793 void *hdr;
9794
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009795 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009796 if (!msg)
9797 return;
9798
9799 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9800 if (!hdr) {
9801 nlmsg_free(msg);
9802 return;
9803 }
9804
9805 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009806 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9807 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009808
David S. Miller9360ffd2012-03-29 04:41:26 -04009809 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9810 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9811 NL80211_REGDOM_TYPE_WORLD))
9812 goto nla_put_failure;
9813 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9814 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9815 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9816 goto nla_put_failure;
9817 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9818 request->intersect) {
9819 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9820 NL80211_REGDOM_TYPE_INTERSECTION))
9821 goto nla_put_failure;
9822 } else {
9823 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9824 NL80211_REGDOM_TYPE_COUNTRY) ||
9825 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9826 request->alpha2))
9827 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009828 }
9829
Johannes Bergf4173762012-12-03 18:23:37 +01009830 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009831 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9832 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009833
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009834 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009835
Johannes Bergbc43b282009-07-25 10:54:13 +02009836 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009837 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009838 GFP_ATOMIC);
9839 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009840
9841 return;
9842
9843nla_put_failure:
9844 genlmsg_cancel(msg, hdr);
9845 nlmsg_free(msg);
9846}
9847
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009848static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9849 struct net_device *netdev,
9850 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009851 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009852{
9853 struct sk_buff *msg;
9854 void *hdr;
9855
Johannes Berge6d6e342009-07-01 21:26:47 +02009856 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009857 if (!msg)
9858 return;
9859
9860 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9861 if (!hdr) {
9862 nlmsg_free(msg);
9863 return;
9864 }
9865
David S. Miller9360ffd2012-03-29 04:41:26 -04009866 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9867 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9868 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9869 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009870
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009871 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009872
Johannes Berg463d0182009-07-14 00:33:35 +02009873 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9874 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009875 return;
9876
9877 nla_put_failure:
9878 genlmsg_cancel(msg, hdr);
9879 nlmsg_free(msg);
9880}
9881
9882void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009883 struct net_device *netdev, const u8 *buf,
9884 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009885{
9886 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009887 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009888}
9889
9890void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9891 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009892 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009893{
Johannes Berge6d6e342009-07-01 21:26:47 +02009894 nl80211_send_mlme_event(rdev, netdev, buf, len,
9895 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009896}
9897
Jouni Malinen53b46b82009-03-27 20:53:56 +02009898void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009899 struct net_device *netdev, const u8 *buf,
9900 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009901{
9902 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009903 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009904}
9905
Jouni Malinen53b46b82009-03-27 20:53:56 +02009906void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9907 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009908 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009909{
9910 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009911 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009912}
9913
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009914void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9915 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009916{
Johannes Berg947add32013-02-22 22:05:20 +01009917 struct wireless_dev *wdev = dev->ieee80211_ptr;
9918 struct wiphy *wiphy = wdev->wiphy;
9919 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009920 const struct ieee80211_mgmt *mgmt = (void *)buf;
9921 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009922
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009923 if (WARN_ON(len < 2))
9924 return;
9925
9926 if (ieee80211_is_deauth(mgmt->frame_control))
9927 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9928 else
9929 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9930
9931 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9932 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009933}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009934EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009935
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009936static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9937 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009938 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009939{
9940 struct sk_buff *msg;
9941 void *hdr;
9942
Johannes Berge6d6e342009-07-01 21:26:47 +02009943 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009944 if (!msg)
9945 return;
9946
9947 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9948 if (!hdr) {
9949 nlmsg_free(msg);
9950 return;
9951 }
9952
David S. Miller9360ffd2012-03-29 04:41:26 -04009953 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9954 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9955 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9956 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9957 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009958
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009959 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009960
Johannes Berg463d0182009-07-14 00:33:35 +02009961 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9962 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009963 return;
9964
9965 nla_put_failure:
9966 genlmsg_cancel(msg, hdr);
9967 nlmsg_free(msg);
9968}
9969
9970void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009971 struct net_device *netdev, const u8 *addr,
9972 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009973{
9974 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009975 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009976}
9977
9978void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009979 struct net_device *netdev, const u8 *addr,
9980 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009981{
Johannes Berge6d6e342009-07-01 21:26:47 +02009982 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9983 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009984}
9985
Samuel Ortizb23aa672009-07-01 21:26:54 +02009986void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9987 struct net_device *netdev, const u8 *bssid,
9988 const u8 *req_ie, size_t req_ie_len,
9989 const u8 *resp_ie, size_t resp_ie_len,
9990 u16 status, gfp_t gfp)
9991{
9992 struct sk_buff *msg;
9993 void *hdr;
9994
Thomas Graf58050fc2012-06-28 03:57:45 +00009995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009996 if (!msg)
9997 return;
9998
9999 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10000 if (!hdr) {
10001 nlmsg_free(msg);
10002 return;
10003 }
10004
David S. Miller9360ffd2012-03-29 04:41:26 -040010005 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10006 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10007 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10008 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10009 (req_ie &&
10010 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10011 (resp_ie &&
10012 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10013 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010014
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010015 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010016
Johannes Berg463d0182009-07-14 00:33:35 +020010017 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10018 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010019 return;
10020
10021 nla_put_failure:
10022 genlmsg_cancel(msg, hdr);
10023 nlmsg_free(msg);
10024
10025}
10026
10027void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10028 struct net_device *netdev, const u8 *bssid,
10029 const u8 *req_ie, size_t req_ie_len,
10030 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10031{
10032 struct sk_buff *msg;
10033 void *hdr;
10034
Thomas Graf58050fc2012-06-28 03:57:45 +000010035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010036 if (!msg)
10037 return;
10038
10039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10040 if (!hdr) {
10041 nlmsg_free(msg);
10042 return;
10043 }
10044
David S. Miller9360ffd2012-03-29 04:41:26 -040010045 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10046 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10047 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10048 (req_ie &&
10049 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10050 (resp_ie &&
10051 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10052 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010053
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010054 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010055
Johannes Berg463d0182009-07-14 00:33:35 +020010056 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10057 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010058 return;
10059
10060 nla_put_failure:
10061 genlmsg_cancel(msg, hdr);
10062 nlmsg_free(msg);
10063
10064}
10065
10066void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10067 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010068 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010069{
10070 struct sk_buff *msg;
10071 void *hdr;
10072
Thomas Graf58050fc2012-06-28 03:57:45 +000010073 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010074 if (!msg)
10075 return;
10076
10077 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10078 if (!hdr) {
10079 nlmsg_free(msg);
10080 return;
10081 }
10082
David S. Miller9360ffd2012-03-29 04:41:26 -040010083 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10084 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10085 (from_ap && reason &&
10086 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10087 (from_ap &&
10088 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10089 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10090 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010091
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010092 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010093
Johannes Berg463d0182009-07-14 00:33:35 +020010094 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10095 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010096 return;
10097
10098 nla_put_failure:
10099 genlmsg_cancel(msg, hdr);
10100 nlmsg_free(msg);
10101
10102}
10103
Johannes Berg04a773a2009-04-19 21:24:32 +020010104void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10105 struct net_device *netdev, const u8 *bssid,
10106 gfp_t gfp)
10107{
10108 struct sk_buff *msg;
10109 void *hdr;
10110
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010111 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010112 if (!msg)
10113 return;
10114
10115 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10116 if (!hdr) {
10117 nlmsg_free(msg);
10118 return;
10119 }
10120
David S. Miller9360ffd2012-03-29 04:41:26 -040010121 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10122 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10123 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10124 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010125
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010126 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010127
Johannes Berg463d0182009-07-14 00:33:35 +020010128 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10129 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010130 return;
10131
10132 nla_put_failure:
10133 genlmsg_cancel(msg, hdr);
10134 nlmsg_free(msg);
10135}
10136
Johannes Berg947add32013-02-22 22:05:20 +010010137void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10138 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010139{
Johannes Berg947add32013-02-22 22:05:20 +010010140 struct wireless_dev *wdev = dev->ieee80211_ptr;
10141 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010142 struct sk_buff *msg;
10143 void *hdr;
10144
Johannes Berg947add32013-02-22 22:05:20 +010010145 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10146 return;
10147
10148 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10149
Javier Cardonac93b5e72011-04-07 15:08:34 -070010150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10151 if (!msg)
10152 return;
10153
10154 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10155 if (!hdr) {
10156 nlmsg_free(msg);
10157 return;
10158 }
10159
David S. Miller9360ffd2012-03-29 04:41:26 -040010160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010161 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10162 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010163 (ie_len && ie &&
10164 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10165 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010166
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010167 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010168
10169 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10170 nl80211_mlme_mcgrp.id, gfp);
10171 return;
10172
10173 nla_put_failure:
10174 genlmsg_cancel(msg, hdr);
10175 nlmsg_free(msg);
10176}
Johannes Berg947add32013-02-22 22:05:20 +010010177EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010178
Jouni Malinena3b8b052009-03-27 21:59:49 +020010179void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10180 struct net_device *netdev, const u8 *addr,
10181 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010182 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010183{
10184 struct sk_buff *msg;
10185 void *hdr;
10186
Johannes Berge6d6e342009-07-01 21:26:47 +020010187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010188 if (!msg)
10189 return;
10190
10191 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10192 if (!hdr) {
10193 nlmsg_free(msg);
10194 return;
10195 }
10196
David S. Miller9360ffd2012-03-29 04:41:26 -040010197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10198 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10199 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10200 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10201 (key_id != -1 &&
10202 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10203 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10204 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010205
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010206 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010207
Johannes Berg463d0182009-07-14 00:33:35 +020010208 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10209 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010210 return;
10211
10212 nla_put_failure:
10213 genlmsg_cancel(msg, hdr);
10214 nlmsg_free(msg);
10215}
10216
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010217void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10218 struct ieee80211_channel *channel_before,
10219 struct ieee80211_channel *channel_after)
10220{
10221 struct sk_buff *msg;
10222 void *hdr;
10223 struct nlattr *nl_freq;
10224
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010225 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010226 if (!msg)
10227 return;
10228
10229 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10230 if (!hdr) {
10231 nlmsg_free(msg);
10232 return;
10233 }
10234
10235 /*
10236 * Since we are applying the beacon hint to a wiphy we know its
10237 * wiphy_idx is valid
10238 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010239 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10240 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010241
10242 /* Before */
10243 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10244 if (!nl_freq)
10245 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010246 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010247 goto nla_put_failure;
10248 nla_nest_end(msg, nl_freq);
10249
10250 /* After */
10251 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10252 if (!nl_freq)
10253 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010254 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010255 goto nla_put_failure;
10256 nla_nest_end(msg, nl_freq);
10257
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010258 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010259
Johannes Berg463d0182009-07-14 00:33:35 +020010260 rcu_read_lock();
10261 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10262 GFP_ATOMIC);
10263 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010264
10265 return;
10266
10267nla_put_failure:
10268 genlmsg_cancel(msg, hdr);
10269 nlmsg_free(msg);
10270}
10271
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010272static void nl80211_send_remain_on_chan_event(
10273 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010274 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010275 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010276 unsigned int duration, gfp_t gfp)
10277{
10278 struct sk_buff *msg;
10279 void *hdr;
10280
10281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10282 if (!msg)
10283 return;
10284
10285 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10286 if (!hdr) {
10287 nlmsg_free(msg);
10288 return;
10289 }
10290
David S. Miller9360ffd2012-03-29 04:41:26 -040010291 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010292 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10293 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010294 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010295 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010296 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10297 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010298 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10299 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010300
David S. Miller9360ffd2012-03-29 04:41:26 -040010301 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10302 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10303 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010304
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010305 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010306
10307 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10308 nl80211_mlme_mcgrp.id, gfp);
10309 return;
10310
10311 nla_put_failure:
10312 genlmsg_cancel(msg, hdr);
10313 nlmsg_free(msg);
10314}
10315
Johannes Berg947add32013-02-22 22:05:20 +010010316void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10317 struct ieee80211_channel *chan,
10318 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010319{
Johannes Berg947add32013-02-22 22:05:20 +010010320 struct wiphy *wiphy = wdev->wiphy;
10321 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10322
10323 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010324 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010325 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010326 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010327}
Johannes Berg947add32013-02-22 22:05:20 +010010328EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010329
Johannes Berg947add32013-02-22 22:05:20 +010010330void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10331 struct ieee80211_channel *chan,
10332 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010333{
Johannes Berg947add32013-02-22 22:05:20 +010010334 struct wiphy *wiphy = wdev->wiphy;
10335 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10336
10337 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010338 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010339 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010340}
Johannes Berg947add32013-02-22 22:05:20 +010010341EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010342
Johannes Berg947add32013-02-22 22:05:20 +010010343void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10344 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010345{
Johannes Berg947add32013-02-22 22:05:20 +010010346 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10347 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010348 struct sk_buff *msg;
10349
Johannes Berg947add32013-02-22 22:05:20 +010010350 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10351
Thomas Graf58050fc2012-06-28 03:57:45 +000010352 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010353 if (!msg)
10354 return;
10355
John W. Linville66266b32012-03-15 13:25:41 -040010356 if (nl80211_send_station(msg, 0, 0, 0,
10357 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010358 nlmsg_free(msg);
10359 return;
10360 }
10361
10362 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10363 nl80211_mlme_mcgrp.id, gfp);
10364}
Johannes Berg947add32013-02-22 22:05:20 +010010365EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010366
Johannes Berg947add32013-02-22 22:05:20 +010010367void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010368{
Johannes Berg947add32013-02-22 22:05:20 +010010369 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10370 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010371 struct sk_buff *msg;
10372 void *hdr;
10373
Johannes Berg947add32013-02-22 22:05:20 +010010374 trace_cfg80211_del_sta(dev, mac_addr);
10375
Thomas Graf58050fc2012-06-28 03:57:45 +000010376 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010377 if (!msg)
10378 return;
10379
10380 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10381 if (!hdr) {
10382 nlmsg_free(msg);
10383 return;
10384 }
10385
David S. Miller9360ffd2012-03-29 04:41:26 -040010386 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10387 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10388 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010389
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010390 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010391
10392 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10393 nl80211_mlme_mcgrp.id, gfp);
10394 return;
10395
10396 nla_put_failure:
10397 genlmsg_cancel(msg, hdr);
10398 nlmsg_free(msg);
10399}
Johannes Berg947add32013-02-22 22:05:20 +010010400EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010401
Johannes Berg947add32013-02-22 22:05:20 +010010402void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10403 enum nl80211_connect_failed_reason reason,
10404 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010405{
Johannes Berg947add32013-02-22 22:05:20 +010010406 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10407 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010408 struct sk_buff *msg;
10409 void *hdr;
10410
10411 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10412 if (!msg)
10413 return;
10414
10415 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10416 if (!hdr) {
10417 nlmsg_free(msg);
10418 return;
10419 }
10420
10421 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10422 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10423 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10424 goto nla_put_failure;
10425
10426 genlmsg_end(msg, hdr);
10427
10428 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10429 nl80211_mlme_mcgrp.id, gfp);
10430 return;
10431
10432 nla_put_failure:
10433 genlmsg_cancel(msg, hdr);
10434 nlmsg_free(msg);
10435}
Johannes Berg947add32013-02-22 22:05:20 +010010436EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010437
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010438static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10439 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010440{
10441 struct wireless_dev *wdev = dev->ieee80211_ptr;
10442 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10443 struct sk_buff *msg;
10444 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010445 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010446
Eric W. Biederman15e47302012-09-07 20:12:54 +000010447 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010448 return false;
10449
10450 msg = nlmsg_new(100, gfp);
10451 if (!msg)
10452 return true;
10453
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010454 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010455 if (!hdr) {
10456 nlmsg_free(msg);
10457 return true;
10458 }
10459
David S. Miller9360ffd2012-03-29 04:41:26 -040010460 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10461 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10462 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10463 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010464
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010465 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010466 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010467 return true;
10468
10469 nla_put_failure:
10470 genlmsg_cancel(msg, hdr);
10471 nlmsg_free(msg);
10472 return true;
10473}
10474
Johannes Berg947add32013-02-22 22:05:20 +010010475bool cfg80211_rx_spurious_frame(struct net_device *dev,
10476 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010477{
Johannes Berg947add32013-02-22 22:05:20 +010010478 struct wireless_dev *wdev = dev->ieee80211_ptr;
10479 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010480
Johannes Berg947add32013-02-22 22:05:20 +010010481 trace_cfg80211_rx_spurious_frame(dev, addr);
10482
10483 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10484 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10485 trace_cfg80211_return_bool(false);
10486 return false;
10487 }
10488 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10489 addr, gfp);
10490 trace_cfg80211_return_bool(ret);
10491 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010492}
Johannes Berg947add32013-02-22 22:05:20 +010010493EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10494
10495bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10496 const u8 *addr, gfp_t gfp)
10497{
10498 struct wireless_dev *wdev = dev->ieee80211_ptr;
10499 bool ret;
10500
10501 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10502
10503 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10504 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10505 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10506 trace_cfg80211_return_bool(false);
10507 return false;
10508 }
10509 ret = __nl80211_unexpected_frame(dev,
10510 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10511 addr, gfp);
10512 trace_cfg80211_return_bool(ret);
10513 return ret;
10514}
10515EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010516
Johannes Berg2e161f72010-08-12 15:38:38 +020010517int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010518 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010519 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010520 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010521{
Johannes Berg71bbc992012-06-15 15:30:18 +020010522 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010523 struct sk_buff *msg;
10524 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010525
10526 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10527 if (!msg)
10528 return -ENOMEM;
10529
Johannes Berg2e161f72010-08-12 15:38:38 +020010530 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010531 if (!hdr) {
10532 nlmsg_free(msg);
10533 return -ENOMEM;
10534 }
10535
David S. Miller9360ffd2012-03-29 04:41:26 -040010536 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010537 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10538 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010539 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010540 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10541 (sig_dbm &&
10542 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010543 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10544 (flags &&
10545 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010546 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010547
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010548 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010549
Eric W. Biederman15e47302012-09-07 20:12:54 +000010550 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010551
10552 nla_put_failure:
10553 genlmsg_cancel(msg, hdr);
10554 nlmsg_free(msg);
10555 return -ENOBUFS;
10556}
10557
Johannes Berg947add32013-02-22 22:05:20 +010010558void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10559 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010560{
Johannes Berg947add32013-02-22 22:05:20 +010010561 struct wiphy *wiphy = wdev->wiphy;
10562 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010563 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010564 struct sk_buff *msg;
10565 void *hdr;
10566
Johannes Berg947add32013-02-22 22:05:20 +010010567 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10568
Jouni Malinen026331c2010-02-15 12:53:10 +020010569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10570 if (!msg)
10571 return;
10572
Johannes Berg2e161f72010-08-12 15:38:38 +020010573 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010574 if (!hdr) {
10575 nlmsg_free(msg);
10576 return;
10577 }
10578
David S. Miller9360ffd2012-03-29 04:41:26 -040010579 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010580 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10581 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010582 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010583 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10584 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10585 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10586 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010587
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010588 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010589
Michal Kaziora0ec5702013-06-25 09:17:17 +020010590 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10591 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010592 return;
10593
10594 nla_put_failure:
10595 genlmsg_cancel(msg, hdr);
10596 nlmsg_free(msg);
10597}
Johannes Berg947add32013-02-22 22:05:20 +010010598EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010599
Johannes Berg947add32013-02-22 22:05:20 +010010600void cfg80211_cqm_rssi_notify(struct net_device *dev,
10601 enum nl80211_cqm_rssi_threshold_event rssi_event,
10602 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010603{
Johannes Berg947add32013-02-22 22:05:20 +010010604 struct wireless_dev *wdev = dev->ieee80211_ptr;
10605 struct wiphy *wiphy = wdev->wiphy;
10606 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010607 struct sk_buff *msg;
10608 struct nlattr *pinfoattr;
10609 void *hdr;
10610
Johannes Berg947add32013-02-22 22:05:20 +010010611 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10612
Thomas Graf58050fc2012-06-28 03:57:45 +000010613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010614 if (!msg)
10615 return;
10616
10617 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10618 if (!hdr) {
10619 nlmsg_free(msg);
10620 return;
10621 }
10622
David S. Miller9360ffd2012-03-29 04:41:26 -040010623 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010624 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010625 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010626
10627 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10628 if (!pinfoattr)
10629 goto nla_put_failure;
10630
David S. Miller9360ffd2012-03-29 04:41:26 -040010631 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10632 rssi_event))
10633 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010634
10635 nla_nest_end(msg, pinfoattr);
10636
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010637 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010638
10639 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10640 nl80211_mlme_mcgrp.id, gfp);
10641 return;
10642
10643 nla_put_failure:
10644 genlmsg_cancel(msg, hdr);
10645 nlmsg_free(msg);
10646}
Johannes Berg947add32013-02-22 22:05:20 +010010647EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010648
Johannes Berg947add32013-02-22 22:05:20 +010010649static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10650 struct net_device *netdev, const u8 *bssid,
10651 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010652{
10653 struct sk_buff *msg;
10654 struct nlattr *rekey_attr;
10655 void *hdr;
10656
Thomas Graf58050fc2012-06-28 03:57:45 +000010657 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010658 if (!msg)
10659 return;
10660
10661 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10662 if (!hdr) {
10663 nlmsg_free(msg);
10664 return;
10665 }
10666
David S. Miller9360ffd2012-03-29 04:41:26 -040010667 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10668 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10669 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10670 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010671
10672 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10673 if (!rekey_attr)
10674 goto nla_put_failure;
10675
David S. Miller9360ffd2012-03-29 04:41:26 -040010676 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10677 NL80211_REPLAY_CTR_LEN, replay_ctr))
10678 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010679
10680 nla_nest_end(msg, rekey_attr);
10681
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010682 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010683
10684 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10685 nl80211_mlme_mcgrp.id, gfp);
10686 return;
10687
10688 nla_put_failure:
10689 genlmsg_cancel(msg, hdr);
10690 nlmsg_free(msg);
10691}
10692
Johannes Berg947add32013-02-22 22:05:20 +010010693void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10694 const u8 *replay_ctr, gfp_t gfp)
10695{
10696 struct wireless_dev *wdev = dev->ieee80211_ptr;
10697 struct wiphy *wiphy = wdev->wiphy;
10698 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10699
10700 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10701 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10702}
10703EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10704
10705static void
10706nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10707 struct net_device *netdev, int index,
10708 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010709{
10710 struct sk_buff *msg;
10711 struct nlattr *attr;
10712 void *hdr;
10713
Thomas Graf58050fc2012-06-28 03:57:45 +000010714 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010715 if (!msg)
10716 return;
10717
10718 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10719 if (!hdr) {
10720 nlmsg_free(msg);
10721 return;
10722 }
10723
David S. Miller9360ffd2012-03-29 04:41:26 -040010724 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10725 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10726 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010727
10728 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10729 if (!attr)
10730 goto nla_put_failure;
10731
David S. Miller9360ffd2012-03-29 04:41:26 -040010732 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10733 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10734 (preauth &&
10735 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10736 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010737
10738 nla_nest_end(msg, attr);
10739
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010740 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010741
10742 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10743 nl80211_mlme_mcgrp.id, gfp);
10744 return;
10745
10746 nla_put_failure:
10747 genlmsg_cancel(msg, hdr);
10748 nlmsg_free(msg);
10749}
10750
Johannes Berg947add32013-02-22 22:05:20 +010010751void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10752 const u8 *bssid, bool preauth, gfp_t gfp)
10753{
10754 struct wireless_dev *wdev = dev->ieee80211_ptr;
10755 struct wiphy *wiphy = wdev->wiphy;
10756 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10757
10758 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10759 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10760}
10761EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10762
10763static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10764 struct net_device *netdev,
10765 struct cfg80211_chan_def *chandef,
10766 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010767{
10768 struct sk_buff *msg;
10769 void *hdr;
10770
Thomas Graf58050fc2012-06-28 03:57:45 +000010771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010772 if (!msg)
10773 return;
10774
10775 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10776 if (!hdr) {
10777 nlmsg_free(msg);
10778 return;
10779 }
10780
Johannes Berg683b6d32012-11-08 21:25:48 +010010781 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10782 goto nla_put_failure;
10783
10784 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010785 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010786
10787 genlmsg_end(msg, hdr);
10788
10789 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10790 nl80211_mlme_mcgrp.id, gfp);
10791 return;
10792
10793 nla_put_failure:
10794 genlmsg_cancel(msg, hdr);
10795 nlmsg_free(msg);
10796}
10797
Johannes Berg947add32013-02-22 22:05:20 +010010798void cfg80211_ch_switch_notify(struct net_device *dev,
10799 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010800{
Johannes Berg947add32013-02-22 22:05:20 +010010801 struct wireless_dev *wdev = dev->ieee80211_ptr;
10802 struct wiphy *wiphy = wdev->wiphy;
10803 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10804
10805 trace_cfg80211_ch_switch_notify(dev, chandef);
10806
10807 wdev_lock(wdev);
10808
10809 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020010810 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10811 wdev->iftype != NL80211_IFTYPE_ADHOC))
Johannes Berg947add32013-02-22 22:05:20 +010010812 goto out;
10813
10814 wdev->channel = chandef->chan;
10815 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10816out:
10817 wdev_unlock(wdev);
10818 return;
10819}
10820EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10821
10822void cfg80211_cqm_txe_notify(struct net_device *dev,
10823 const u8 *peer, u32 num_packets,
10824 u32 rate, u32 intvl, gfp_t gfp)
10825{
10826 struct wireless_dev *wdev = dev->ieee80211_ptr;
10827 struct wiphy *wiphy = wdev->wiphy;
10828 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010829 struct sk_buff *msg;
10830 struct nlattr *pinfoattr;
10831 void *hdr;
10832
10833 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10834 if (!msg)
10835 return;
10836
10837 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10838 if (!hdr) {
10839 nlmsg_free(msg);
10840 return;
10841 }
10842
10843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010845 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10846 goto nla_put_failure;
10847
10848 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10849 if (!pinfoattr)
10850 goto nla_put_failure;
10851
10852 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10853 goto nla_put_failure;
10854
10855 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10856 goto nla_put_failure;
10857
10858 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10859 goto nla_put_failure;
10860
10861 nla_nest_end(msg, pinfoattr);
10862
10863 genlmsg_end(msg, hdr);
10864
10865 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10866 nl80211_mlme_mcgrp.id, gfp);
10867 return;
10868
10869 nla_put_failure:
10870 genlmsg_cancel(msg, hdr);
10871 nlmsg_free(msg);
10872}
Johannes Berg947add32013-02-22 22:05:20 +010010873EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010874
10875void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010876nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10877 struct cfg80211_chan_def *chandef,
10878 enum nl80211_radar_event event,
10879 struct net_device *netdev, gfp_t gfp)
10880{
10881 struct sk_buff *msg;
10882 void *hdr;
10883
10884 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10885 if (!msg)
10886 return;
10887
10888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10889 if (!hdr) {
10890 nlmsg_free(msg);
10891 return;
10892 }
10893
10894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10895 goto nla_put_failure;
10896
10897 /* NOP and radar events don't need a netdev parameter */
10898 if (netdev) {
10899 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10900
10901 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10902 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10903 goto nla_put_failure;
10904 }
10905
10906 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10907 goto nla_put_failure;
10908
10909 if (nl80211_send_chandef(msg, chandef))
10910 goto nla_put_failure;
10911
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010912 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010913
10914 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10915 nl80211_mlme_mcgrp.id, gfp);
10916 return;
10917
10918 nla_put_failure:
10919 genlmsg_cancel(msg, hdr);
10920 nlmsg_free(msg);
10921}
10922
Johannes Berg947add32013-02-22 22:05:20 +010010923void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10924 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010925{
Johannes Berg947add32013-02-22 22:05:20 +010010926 struct wireless_dev *wdev = dev->ieee80211_ptr;
10927 struct wiphy *wiphy = wdev->wiphy;
10928 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010929 struct sk_buff *msg;
10930 struct nlattr *pinfoattr;
10931 void *hdr;
10932
Johannes Berg947add32013-02-22 22:05:20 +010010933 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10934
Thomas Graf58050fc2012-06-28 03:57:45 +000010935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010936 if (!msg)
10937 return;
10938
10939 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10940 if (!hdr) {
10941 nlmsg_free(msg);
10942 return;
10943 }
10944
David S. Miller9360ffd2012-03-29 04:41:26 -040010945 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010946 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010947 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10948 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010949
10950 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10951 if (!pinfoattr)
10952 goto nla_put_failure;
10953
David S. Miller9360ffd2012-03-29 04:41:26 -040010954 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10955 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010956
10957 nla_nest_end(msg, pinfoattr);
10958
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010959 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010960
10961 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10962 nl80211_mlme_mcgrp.id, gfp);
10963 return;
10964
10965 nla_put_failure:
10966 genlmsg_cancel(msg, hdr);
10967 nlmsg_free(msg);
10968}
Johannes Berg947add32013-02-22 22:05:20 +010010969EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010970
Johannes Berg7f6cf312011-11-04 11:18:15 +010010971void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10972 u64 cookie, bool acked, gfp_t gfp)
10973{
10974 struct wireless_dev *wdev = dev->ieee80211_ptr;
10975 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10976 struct sk_buff *msg;
10977 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010978
Beni Lev4ee3e062012-08-27 12:49:39 +030010979 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10980
Thomas Graf58050fc2012-06-28 03:57:45 +000010981 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010982
Johannes Berg7f6cf312011-11-04 11:18:15 +010010983 if (!msg)
10984 return;
10985
10986 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10987 if (!hdr) {
10988 nlmsg_free(msg);
10989 return;
10990 }
10991
David S. Miller9360ffd2012-03-29 04:41:26 -040010992 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10994 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10995 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10996 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10997 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010998
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010999 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011000
11001 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11002 nl80211_mlme_mcgrp.id, gfp);
11003 return;
11004
11005 nla_put_failure:
11006 genlmsg_cancel(msg, hdr);
11007 nlmsg_free(msg);
11008}
11009EXPORT_SYMBOL(cfg80211_probe_status);
11010
Johannes Berg5e760232011-11-04 11:18:17 +010011011void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11012 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011013 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011014{
11015 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11016 struct sk_buff *msg;
11017 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011018 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011019
Beni Lev4ee3e062012-08-27 12:49:39 +030011020 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11021
Ben Greear37c73b52012-10-26 14:49:25 -070011022 spin_lock_bh(&rdev->beacon_registrations_lock);
11023 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11024 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11025 if (!msg) {
11026 spin_unlock_bh(&rdev->beacon_registrations_lock);
11027 return;
11028 }
Johannes Berg5e760232011-11-04 11:18:17 +010011029
Ben Greear37c73b52012-10-26 14:49:25 -070011030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11031 if (!hdr)
11032 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011033
Ben Greear37c73b52012-10-26 14:49:25 -070011034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11035 (freq &&
11036 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11037 (sig_dbm &&
11038 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11039 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11040 goto nla_put_failure;
11041
11042 genlmsg_end(msg, hdr);
11043
11044 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011045 }
Ben Greear37c73b52012-10-26 14:49:25 -070011046 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011047 return;
11048
11049 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011050 spin_unlock_bh(&rdev->beacon_registrations_lock);
11051 if (hdr)
11052 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011053 nlmsg_free(msg);
11054}
11055EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11056
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011057#ifdef CONFIG_PM
11058void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11059 struct cfg80211_wowlan_wakeup *wakeup,
11060 gfp_t gfp)
11061{
11062 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11063 struct sk_buff *msg;
11064 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011065 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011066
11067 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11068
11069 if (wakeup)
11070 size += wakeup->packet_present_len;
11071
11072 msg = nlmsg_new(size, gfp);
11073 if (!msg)
11074 return;
11075
11076 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11077 if (!hdr)
11078 goto free_msg;
11079
11080 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11081 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11082 goto free_msg;
11083
11084 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11085 wdev->netdev->ifindex))
11086 goto free_msg;
11087
11088 if (wakeup) {
11089 struct nlattr *reasons;
11090
11091 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11092
11093 if (wakeup->disconnect &&
11094 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11095 goto free_msg;
11096 if (wakeup->magic_pkt &&
11097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11098 goto free_msg;
11099 if (wakeup->gtk_rekey_failure &&
11100 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11101 goto free_msg;
11102 if (wakeup->eap_identity_req &&
11103 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11104 goto free_msg;
11105 if (wakeup->four_way_handshake &&
11106 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11107 goto free_msg;
11108 if (wakeup->rfkill_release &&
11109 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11110 goto free_msg;
11111
11112 if (wakeup->pattern_idx >= 0 &&
11113 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11114 wakeup->pattern_idx))
11115 goto free_msg;
11116
Johannes Berg2a0e0472013-01-23 22:57:40 +010011117 if (wakeup->tcp_match)
11118 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11119
11120 if (wakeup->tcp_connlost)
11121 nla_put_flag(msg,
11122 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11123
11124 if (wakeup->tcp_nomoretokens)
11125 nla_put_flag(msg,
11126 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11127
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011128 if (wakeup->packet) {
11129 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11130 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11131
11132 if (!wakeup->packet_80211) {
11133 pkt_attr =
11134 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11135 len_attr =
11136 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11137 }
11138
11139 if (wakeup->packet_len &&
11140 nla_put_u32(msg, len_attr, wakeup->packet_len))
11141 goto free_msg;
11142
11143 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11144 wakeup->packet))
11145 goto free_msg;
11146 }
11147
11148 nla_nest_end(msg, reasons);
11149 }
11150
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011151 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011152
11153 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11154 nl80211_mlme_mcgrp.id, gfp);
11155 return;
11156
11157 free_msg:
11158 nlmsg_free(msg);
11159}
11160EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11161#endif
11162
Jouni Malinen3475b092012-11-16 22:49:57 +020011163void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11164 enum nl80211_tdls_operation oper,
11165 u16 reason_code, gfp_t gfp)
11166{
11167 struct wireless_dev *wdev = dev->ieee80211_ptr;
11168 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11169 struct sk_buff *msg;
11170 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011171
11172 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11173 reason_code);
11174
11175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11176 if (!msg)
11177 return;
11178
11179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11180 if (!hdr) {
11181 nlmsg_free(msg);
11182 return;
11183 }
11184
11185 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11186 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11187 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11188 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11189 (reason_code > 0 &&
11190 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11191 goto nla_put_failure;
11192
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011193 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011194
11195 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11196 nl80211_mlme_mcgrp.id, gfp);
11197 return;
11198
11199 nla_put_failure:
11200 genlmsg_cancel(msg, hdr);
11201 nlmsg_free(msg);
11202}
11203EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11204
Jouni Malinen026331c2010-02-15 12:53:10 +020011205static int nl80211_netlink_notify(struct notifier_block * nb,
11206 unsigned long state,
11207 void *_notify)
11208{
11209 struct netlink_notify *notify = _notify;
11210 struct cfg80211_registered_device *rdev;
11211 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011212 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011213
11214 if (state != NETLINK_URELEASE)
11215 return NOTIFY_DONE;
11216
11217 rcu_read_lock();
11218
Johannes Berg5e760232011-11-04 11:18:17 +010011219 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011220 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011221 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011222
11223 spin_lock_bh(&rdev->beacon_registrations_lock);
11224 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11225 list) {
11226 if (reg->nlportid == notify->portid) {
11227 list_del(&reg->list);
11228 kfree(reg);
11229 break;
11230 }
11231 }
11232 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011233 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011234
11235 rcu_read_unlock();
11236
11237 return NOTIFY_DONE;
11238}
11239
11240static struct notifier_block nl80211_netlink_notifier = {
11241 .notifier_call = nl80211_netlink_notify,
11242};
11243
Jouni Malinen355199e2013-02-27 17:14:27 +020011244void cfg80211_ft_event(struct net_device *netdev,
11245 struct cfg80211_ft_event_params *ft_event)
11246{
11247 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11248 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11249 struct sk_buff *msg;
11250 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011251
11252 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11253
11254 if (!ft_event->target_ap)
11255 return;
11256
11257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11258 if (!msg)
11259 return;
11260
11261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11262 if (!hdr) {
11263 nlmsg_free(msg);
11264 return;
11265 }
11266
11267 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11268 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11269 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11270 if (ft_event->ies)
11271 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11272 if (ft_event->ric_ies)
11273 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11274 ft_event->ric_ies);
11275
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011276 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011277
11278 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11279 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11280}
11281EXPORT_SYMBOL(cfg80211_ft_event);
11282
Arend van Spriel5de17982013-04-18 15:49:00 +020011283void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11284{
11285 struct cfg80211_registered_device *rdev;
11286 struct sk_buff *msg;
11287 void *hdr;
11288 u32 nlportid;
11289
11290 rdev = wiphy_to_dev(wdev->wiphy);
11291 if (!rdev->crit_proto_nlportid)
11292 return;
11293
11294 nlportid = rdev->crit_proto_nlportid;
11295 rdev->crit_proto_nlportid = 0;
11296
11297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11298 if (!msg)
11299 return;
11300
11301 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11302 if (!hdr)
11303 goto nla_put_failure;
11304
11305 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11306 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11307 goto nla_put_failure;
11308
11309 genlmsg_end(msg, hdr);
11310
11311 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11312 return;
11313
11314 nla_put_failure:
11315 if (hdr)
11316 genlmsg_cancel(msg, hdr);
11317 nlmsg_free(msg);
11318
11319}
11320EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11321
Johannes Berg55682962007-09-20 13:09:35 -040011322/* initialisation/exit functions */
11323
11324int nl80211_init(void)
11325{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011326 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011327
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011328 err = genl_register_family_with_ops(&nl80211_fam,
11329 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011330 if (err)
11331 return err;
11332
Johannes Berg55682962007-09-20 13:09:35 -040011333 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11334 if (err)
11335 goto err_out;
11336
Johannes Berg2a519312009-02-10 21:25:55 +010011337 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11338 if (err)
11339 goto err_out;
11340
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011341 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11342 if (err)
11343 goto err_out;
11344
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011345 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11346 if (err)
11347 goto err_out;
11348
Johannes Bergaff89a92009-07-01 21:26:51 +020011349#ifdef CONFIG_NL80211_TESTMODE
11350 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11351 if (err)
11352 goto err_out;
11353#endif
11354
Jouni Malinen026331c2010-02-15 12:53:10 +020011355 err = netlink_register_notifier(&nl80211_netlink_notifier);
11356 if (err)
11357 goto err_out;
11358
Johannes Berg55682962007-09-20 13:09:35 -040011359 return 0;
11360 err_out:
11361 genl_unregister_family(&nl80211_fam);
11362 return err;
11363}
11364
11365void nl80211_exit(void)
11366{
Jouni Malinen026331c2010-02-15 12:53:10 +020011367 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011368 genl_unregister_family(&nl80211_fam);
11369}