blob: e4028197b75dcc28af9b0011a5052e2adeeb702e [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 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Johannes Berge5497d72011-07-05 16:35:40 +0200406/* policy for GTK rekey offload attributes */
407static const struct nla_policy
408nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
409 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
410 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
411 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
412};
413
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300414static const struct nla_policy
415nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300417 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300419};
420
Johannes Berg97990a02013-04-19 01:02:55 +0200421static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
422 struct netlink_callback *cb,
423 struct cfg80211_registered_device **rdev,
424 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100425{
Johannes Berg67748892010-10-04 21:14:06 +0200426 int err;
427
Johannes Berg67748892010-10-04 21:14:06 +0200428 rtnl_lock();
429
Johannes Berg97990a02013-04-19 01:02:55 +0200430 if (!cb->args[0]) {
431 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
432 nl80211_fam.attrbuf, nl80211_fam.maxattr,
433 nl80211_policy);
434 if (err)
435 goto out_unlock;
436
437 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
438 nl80211_fam.attrbuf);
439 if (IS_ERR(*wdev)) {
440 err = PTR_ERR(*wdev);
441 goto out_unlock;
442 }
443 *rdev = wiphy_to_dev((*wdev)->wiphy);
444 cb->args[0] = (*rdev)->wiphy_idx;
445 cb->args[1] = (*wdev)->identifier;
446 } else {
447 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
448 struct wireless_dev *tmp;
449
450 if (!wiphy) {
451 err = -ENODEV;
452 goto out_unlock;
453 }
454 *rdev = wiphy_to_dev(wiphy);
455 *wdev = NULL;
456
Johannes Berg97990a02013-04-19 01:02:55 +0200457 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
458 if (tmp->identifier == cb->args[1]) {
459 *wdev = tmp;
460 break;
461 }
462 }
Johannes Berg97990a02013-04-19 01:02:55 +0200463
464 if (!*wdev) {
465 err = -ENODEV;
466 goto out_unlock;
467 }
Johannes Berg67748892010-10-04 21:14:06 +0200468 }
469
Johannes Berg67748892010-10-04 21:14:06 +0200470 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200471 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200472 rtnl_unlock();
473 return err;
474}
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200477{
Johannes Berg67748892010-10-04 21:14:06 +0200478 rtnl_unlock();
479}
480
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100481/* IE validation */
482static bool is_valid_ie_attr(const struct nlattr *attr)
483{
484 const u8 *pos;
485 int len;
486
487 if (!attr)
488 return true;
489
490 pos = nla_data(attr);
491 len = nla_len(attr);
492
493 while (len) {
494 u8 elemlen;
495
496 if (len < 2)
497 return false;
498 len -= 2;
499
500 elemlen = pos[1];
501 if (elemlen > len)
502 return false;
503
504 len -= elemlen;
505 pos += 2 + elemlen;
506 }
507
508 return true;
509}
510
Johannes Berg55682962007-09-20 13:09:35 -0400511/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000512static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400513 int flags, u8 cmd)
514{
515 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000516 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400517}
518
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400519static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100520 struct ieee80211_channel *chan,
521 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400522{
David S. Miller9360ffd2012-03-29 04:41:26 -0400523 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
524 chan->center_freq))
525 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400526
David S. Miller9360ffd2012-03-29 04:41:26 -0400527 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
528 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
529 goto nla_put_failure;
530 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
531 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
532 goto nla_put_failure;
533 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
534 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
535 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100536 if (chan->flags & IEEE80211_CHAN_RADAR) {
537 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
538 goto nla_put_failure;
539 if (large) {
540 u32 time;
541
542 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
543
544 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
545 chan->dfs_state))
546 goto nla_put_failure;
547 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
548 time))
549 goto nla_put_failure;
550 }
551 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100553 if (large) {
554 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
565 goto nla_put_failure;
566 }
567
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
569 DBM_TO_MBM(chan->max_power)))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
572 return 0;
573
574 nla_put_failure:
575 return -ENOBUFS;
576}
577
Johannes Berg55682962007-09-20 13:09:35 -0400578/* netlink command implementations */
579
Johannes Bergb9454e82009-07-08 13:29:08 +0200580struct key_parse {
581 struct key_params p;
582 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200583 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200584 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100585 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200586};
587
588static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
589{
590 struct nlattr *tb[NL80211_KEY_MAX + 1];
591 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
592 nl80211_key_policy);
593 if (err)
594 return err;
595
596 k->def = !!tb[NL80211_KEY_DEFAULT];
597 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
598
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100599 if (k->def) {
600 k->def_uni = true;
601 k->def_multi = true;
602 }
603 if (k->defmgmt)
604 k->def_multi = true;
605
Johannes Bergb9454e82009-07-08 13:29:08 +0200606 if (tb[NL80211_KEY_IDX])
607 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
608
609 if (tb[NL80211_KEY_DATA]) {
610 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
611 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
612 }
613
614 if (tb[NL80211_KEY_SEQ]) {
615 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
616 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
617 }
618
619 if (tb[NL80211_KEY_CIPHER])
620 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
621
Johannes Berge31b8212010-10-05 19:39:30 +0200622 if (tb[NL80211_KEY_TYPE]) {
623 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
624 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
625 return -EINVAL;
626 }
627
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100628 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
629 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100630 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
631 tb[NL80211_KEY_DEFAULT_TYPES],
632 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100633 if (err)
634 return err;
635
636 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
637 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
638 }
639
Johannes Bergb9454e82009-07-08 13:29:08 +0200640 return 0;
641}
642
643static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
644{
645 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
646 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
647 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
648 }
649
650 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
651 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
652 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
653 }
654
655 if (info->attrs[NL80211_ATTR_KEY_IDX])
656 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
657
658 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
659 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
660
661 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
662 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
663
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 if (k->def) {
665 k->def_uni = true;
666 k->def_multi = true;
667 }
668 if (k->defmgmt)
669 k->def_multi = true;
670
Johannes Berge31b8212010-10-05 19:39:30 +0200671 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
672 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
673 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
674 return -EINVAL;
675 }
676
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
678 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
679 int err = nla_parse_nested(
680 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
681 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
682 nl80211_key_default_policy);
683 if (err)
684 return err;
685
686 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
687 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
688 }
689
Johannes Bergb9454e82009-07-08 13:29:08 +0200690 return 0;
691}
692
693static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
694{
695 int err;
696
697 memset(k, 0, sizeof(*k));
698 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200699 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200700
701 if (info->attrs[NL80211_ATTR_KEY])
702 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
703 else
704 err = nl80211_parse_key_old(info, k);
705
706 if (err)
707 return err;
708
709 if (k->def && k->defmgmt)
710 return -EINVAL;
711
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (k->defmgmt) {
713 if (k->def_uni || !k->def_multi)
714 return -EINVAL;
715 }
716
Johannes Bergb9454e82009-07-08 13:29:08 +0200717 if (k->idx != -1) {
718 if (k->defmgmt) {
719 if (k->idx < 4 || k->idx > 5)
720 return -EINVAL;
721 } else if (k->def) {
722 if (k->idx < 0 || k->idx > 3)
723 return -EINVAL;
724 } else {
725 if (k->idx < 0 || k->idx > 5)
726 return -EINVAL;
727 }
728 }
729
730 return 0;
731}
732
Johannes Bergfffd0932009-07-08 14:22:54 +0200733static struct cfg80211_cached_keys *
734nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530735 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200736{
737 struct key_parse parse;
738 struct nlattr *key;
739 struct cfg80211_cached_keys *result;
740 int rem, err, def = 0;
741
742 result = kzalloc(sizeof(*result), GFP_KERNEL);
743 if (!result)
744 return ERR_PTR(-ENOMEM);
745
746 result->def = -1;
747 result->defmgmt = -1;
748
749 nla_for_each_nested(key, keys, rem) {
750 memset(&parse, 0, sizeof(parse));
751 parse.idx = -1;
752
753 err = nl80211_parse_key_new(key, &parse);
754 if (err)
755 goto error;
756 err = -EINVAL;
757 if (!parse.p.key)
758 goto error;
759 if (parse.idx < 0 || parse.idx > 4)
760 goto error;
761 if (parse.def) {
762 if (def)
763 goto error;
764 def = 1;
765 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100766 if (!parse.def_uni || !parse.def_multi)
767 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200768 } else if (parse.defmgmt)
769 goto error;
770 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200771 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (err)
773 goto error;
774 result->params[parse.idx].cipher = parse.p.cipher;
775 result->params[parse.idx].key_len = parse.p.key_len;
776 result->params[parse.idx].key = result->data[parse.idx];
777 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530778
779 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
780 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
781 if (no_ht)
782 *no_ht = true;
783 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200784 }
785
786 return result;
787 error:
788 kfree(result);
789 return ERR_PTR(err);
790}
791
792static int nl80211_key_allowed(struct wireless_dev *wdev)
793{
794 ASSERT_WDEV_LOCK(wdev);
795
Johannes Bergfffd0932009-07-08 14:22:54 +0200796 switch (wdev->iftype) {
797 case NL80211_IFTYPE_AP:
798 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200799 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700800 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200801 break;
802 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200803 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200804 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200805 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806 return -ENOLINK;
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 return 0;
813}
814
Johannes Berg7527a782011-05-13 10:58:57 +0200815static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
816{
817 struct nlattr *nl_modes = nla_nest_start(msg, attr);
818 int i;
819
820 if (!nl_modes)
821 goto nla_put_failure;
822
823 i = 0;
824 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400825 if ((ifmodes & 1) && nla_put_flag(msg, i))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 ifmodes >>= 1;
828 i++;
829 }
830
831 nla_nest_end(msg, nl_modes);
832 return 0;
833
834nla_put_failure:
835 return -ENOBUFS;
836}
837
838static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100839 struct sk_buff *msg,
840 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200841{
842 struct nlattr *nl_combis;
843 int i, j;
844
845 nl_combis = nla_nest_start(msg,
846 NL80211_ATTR_INTERFACE_COMBINATIONS);
847 if (!nl_combis)
848 goto nla_put_failure;
849
850 for (i = 0; i < wiphy->n_iface_combinations; i++) {
851 const struct ieee80211_iface_combination *c;
852 struct nlattr *nl_combi, *nl_limits;
853
854 c = &wiphy->iface_combinations[i];
855
856 nl_combi = nla_nest_start(msg, i + 1);
857 if (!nl_combi)
858 goto nla_put_failure;
859
860 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
861 if (!nl_limits)
862 goto nla_put_failure;
863
864 for (j = 0; j < c->n_limits; j++) {
865 struct nlattr *nl_limit;
866
867 nl_limit = nla_nest_start(msg, j + 1);
868 if (!nl_limit)
869 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
871 c->limits[j].max))
872 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200873 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
874 c->limits[j].types))
875 goto nla_put_failure;
876 nla_nest_end(msg, nl_limit);
877 }
878
879 nla_nest_end(msg, nl_limits);
880
David S. Miller9360ffd2012-03-29 04:41:26 -0400881 if (c->beacon_int_infra_match &&
882 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
883 goto nla_put_failure;
884 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
885 c->num_different_channels) ||
886 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
887 c->max_interfaces))
888 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100889 if (large &&
890 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
891 c->radar_detect_widths))
892 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200893
894 nla_nest_end(msg, nl_combi);
895 }
896
897 nla_nest_end(msg, nl_combis);
898
899 return 0;
900nla_put_failure:
901 return -ENOBUFS;
902}
903
Johannes Berg3713b4e2013-02-14 16:19:38 +0100904#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100905static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
906 struct sk_buff *msg)
907{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200908 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100909 struct nlattr *nl_tcp;
910
911 if (!tcp)
912 return 0;
913
914 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
915 if (!nl_tcp)
916 return -ENOBUFS;
917
918 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
919 tcp->data_payload_max))
920 return -ENOBUFS;
921
922 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
923 tcp->data_payload_max))
924 return -ENOBUFS;
925
926 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
927 return -ENOBUFS;
928
929 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
930 sizeof(*tcp->tok), tcp->tok))
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
934 tcp->data_interval_max))
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
938 tcp->wake_payload_max))
939 return -ENOBUFS;
940
941 nla_nest_end(msg, nl_tcp);
942 return 0;
943}
944
Johannes Berg3713b4e2013-02-14 16:19:38 +0100945static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100946 struct cfg80211_registered_device *dev,
947 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948{
949 struct nlattr *nl_wowlan;
950
Johannes Berg964dc9e2013-06-03 17:25:34 +0200951 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100952 return 0;
953
954 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
955 if (!nl_wowlan)
956 return -ENOBUFS;
957
Johannes Berg964dc9e2013-06-03 17:25:34 +0200958 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200960 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200962 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200964 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
974 return -ENOBUFS;
975
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 if (dev->wiphy.wowlan->n_patterns) {
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 struct nl80211_wowlan_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 .max_patterns = dev->wiphy.wowlan->n_patterns,
979 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
980 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
981 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 };
983
984 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
985 sizeof(pat), &pat))
986 return -ENOBUFS;
987 }
988
Johannes Bergb56cf722013-02-20 01:02:38 +0100989 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
990 return -ENOBUFS;
991
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992 nla_nest_end(msg, nl_wowlan);
993
994 return 0;
995}
996#endif
997
998static int nl80211_send_band_rateinfo(struct sk_buff *msg,
999 struct ieee80211_supported_band *sband)
1000{
1001 struct nlattr *nl_rates, *nl_rate;
1002 struct ieee80211_rate *rate;
1003 int i;
1004
1005 /* add HT info */
1006 if (sband->ht_cap.ht_supported &&
1007 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1008 sizeof(sband->ht_cap.mcs),
1009 &sband->ht_cap.mcs) ||
1010 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1011 sband->ht_cap.cap) ||
1012 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1013 sband->ht_cap.ampdu_factor) ||
1014 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1015 sband->ht_cap.ampdu_density)))
1016 return -ENOBUFS;
1017
1018 /* add VHT info */
1019 if (sband->vht_cap.vht_supported &&
1020 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1021 sizeof(sband->vht_cap.vht_mcs),
1022 &sband->vht_cap.vht_mcs) ||
1023 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1024 sband->vht_cap.cap)))
1025 return -ENOBUFS;
1026
1027 /* add bitrates */
1028 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1029 if (!nl_rates)
1030 return -ENOBUFS;
1031
1032 for (i = 0; i < sband->n_bitrates; i++) {
1033 nl_rate = nla_nest_start(msg, i);
1034 if (!nl_rate)
1035 return -ENOBUFS;
1036
1037 rate = &sband->bitrates[i];
1038 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1039 rate->bitrate))
1040 return -ENOBUFS;
1041 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1042 nla_put_flag(msg,
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_rate);
1047 }
1048
1049 nla_nest_end(msg, nl_rates);
1050
1051 return 0;
1052}
1053
1054static int
1055nl80211_send_mgmt_stypes(struct sk_buff *msg,
1056 const struct ieee80211_txrx_stypes *mgmt_stypes)
1057{
1058 u16 stypes;
1059 struct nlattr *nl_ftypes, *nl_ifs;
1060 enum nl80211_iftype ift;
1061 int i;
1062
1063 if (!mgmt_stypes)
1064 return 0;
1065
1066 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1067 if (!nl_ifs)
1068 return -ENOBUFS;
1069
1070 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1071 nl_ftypes = nla_nest_start(msg, ift);
1072 if (!nl_ftypes)
1073 return -ENOBUFS;
1074 i = 0;
1075 stypes = mgmt_stypes[ift].tx;
1076 while (stypes) {
1077 if ((stypes & 1) &&
1078 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1079 (i << 4) | IEEE80211_FTYPE_MGMT))
1080 return -ENOBUFS;
1081 stypes >>= 1;
1082 i++;
1083 }
1084 nla_nest_end(msg, nl_ftypes);
1085 }
1086
1087 nla_nest_end(msg, nl_ifs);
1088
1089 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1090 if (!nl_ifs)
1091 return -ENOBUFS;
1092
1093 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1094 nl_ftypes = nla_nest_start(msg, ift);
1095 if (!nl_ftypes)
1096 return -ENOBUFS;
1097 i = 0;
1098 stypes = mgmt_stypes[ift].rx;
1099 while (stypes) {
1100 if ((stypes & 1) &&
1101 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1102 (i << 4) | IEEE80211_FTYPE_MGMT))
1103 return -ENOBUFS;
1104 stypes >>= 1;
1105 i++;
1106 }
1107 nla_nest_end(msg, nl_ftypes);
1108 }
1109 nla_nest_end(msg, nl_ifs);
1110
1111 return 0;
1112}
1113
1114static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1115 struct sk_buff *msg, u32 portid, u32 seq,
1116 int flags, bool split, long *split_start,
1117 long *band_start, long *chan_start)
Johannes Berg55682962007-09-20 13:09:35 -04001118{
1119 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001120 struct nlattr *nl_bands, *nl_band;
1121 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001122 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001123 enum ieee80211_band band;
1124 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001125 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001126 const struct ieee80211_txrx_stypes *mgmt_stypes =
1127 dev->wiphy.mgmt_stypes;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001128 long start = 0, start_chan = 0, start_band = 0;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001129 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001130
Eric W. Biederman15e47302012-09-07 20:12:54 +00001131 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001132 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001133 return -ENOBUFS;
1134
1135 /* allow always using the variables */
1136 if (!split) {
1137 split_start = &start;
1138 band_start = &start_band;
1139 chan_start = &start_chan;
1140 }
Johannes Berg55682962007-09-20 13:09:35 -04001141
David S. Miller9360ffd2012-03-29 04:41:26 -04001142 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001143 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1144 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001145 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001146 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001147 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001148
Johannes Berg3713b4e2013-02-14 16:19:38 +01001149 switch (*split_start) {
1150 case 0:
1151 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1152 dev->wiphy.retry_short) ||
1153 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1154 dev->wiphy.retry_long) ||
1155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1156 dev->wiphy.frag_threshold) ||
1157 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1158 dev->wiphy.rts_threshold) ||
1159 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1160 dev->wiphy.coverage_class) ||
1161 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1162 dev->wiphy.max_scan_ssids) ||
1163 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1164 dev->wiphy.max_sched_scan_ssids) ||
1165 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1166 dev->wiphy.max_scan_ie_len) ||
1167 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1168 dev->wiphy.max_sched_scan_ie_len) ||
1169 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1170 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001171 goto nla_put_failure;
1172
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1174 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1175 goto nla_put_failure;
1176 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1177 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1178 goto nla_put_failure;
1179 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1180 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1181 goto nla_put_failure;
1182 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1183 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1184 goto nla_put_failure;
1185 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1186 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1187 goto nla_put_failure;
1188 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1189 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001190 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001191
Johannes Berg3713b4e2013-02-14 16:19:38 +01001192 (*split_start)++;
1193 if (split)
1194 break;
1195 case 1:
1196 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1197 sizeof(u32) * dev->wiphy.n_cipher_suites,
1198 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001199 goto nla_put_failure;
1200
Johannes Berg3713b4e2013-02-14 16:19:38 +01001201 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1202 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001203 goto nla_put_failure;
1204
Johannes Berg3713b4e2013-02-14 16:19:38 +01001205 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1206 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1207 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001208
Johannes Berg3713b4e2013-02-14 16:19:38 +01001209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1210 dev->wiphy.available_antennas_tx) ||
1211 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1212 dev->wiphy.available_antennas_rx))
1213 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001214
Johannes Berg3713b4e2013-02-14 16:19:38 +01001215 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1216 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1217 dev->wiphy.probe_resp_offload))
1218 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001219
Johannes Berg3713b4e2013-02-14 16:19:38 +01001220 if ((dev->wiphy.available_antennas_tx ||
1221 dev->wiphy.available_antennas_rx) &&
1222 dev->ops->get_antenna) {
1223 u32 tx_ant = 0, rx_ant = 0;
1224 int res;
1225 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1226 if (!res) {
1227 if (nla_put_u32(msg,
1228 NL80211_ATTR_WIPHY_ANTENNA_TX,
1229 tx_ant) ||
1230 nla_put_u32(msg,
1231 NL80211_ATTR_WIPHY_ANTENNA_RX,
1232 rx_ant))
1233 goto nla_put_failure;
1234 }
Johannes Bergee688b002008-01-24 19:38:39 +01001235 }
1236
Johannes Berg3713b4e2013-02-14 16:19:38 +01001237 (*split_start)++;
1238 if (split)
1239 break;
1240 case 2:
1241 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1242 dev->wiphy.interface_modes))
1243 goto nla_put_failure;
1244 (*split_start)++;
1245 if (split)
1246 break;
1247 case 3:
1248 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1249 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001250 goto nla_put_failure;
1251
Johannes Berg3713b4e2013-02-14 16:19:38 +01001252 for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) {
1253 struct ieee80211_supported_band *sband;
1254
1255 sband = dev->wiphy.bands[band];
1256
1257 if (!sband)
1258 continue;
1259
1260 nl_band = nla_nest_start(msg, band);
1261 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001262 goto nla_put_failure;
1263
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 switch (*chan_start) {
1265 case 0:
1266 if (nl80211_send_band_rateinfo(msg, sband))
1267 goto nla_put_failure;
1268 (*chan_start)++;
1269 if (split)
1270 break;
1271 default:
1272 /* add frequencies */
1273 nl_freqs = nla_nest_start(
1274 msg, NL80211_BAND_ATTR_FREQS);
1275 if (!nl_freqs)
1276 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001277
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 for (i = *chan_start - 1;
1279 i < sband->n_channels;
1280 i++) {
1281 nl_freq = nla_nest_start(msg, i);
1282 if (!nl_freq)
1283 goto nla_put_failure;
1284
1285 chan = &sband->channels[i];
1286
Johannes Bergcdc89b92013-02-18 23:54:36 +01001287 if (nl80211_msg_put_channel(msg, chan,
1288 split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 goto nla_put_failure;
1290
1291 nla_nest_end(msg, nl_freq);
1292 if (split)
1293 break;
1294 }
1295 if (i < sband->n_channels)
1296 *chan_start = i + 2;
1297 else
1298 *chan_start = 0;
1299 nla_nest_end(msg, nl_freqs);
1300 }
1301
1302 nla_nest_end(msg, nl_band);
1303
1304 if (split) {
1305 /* start again here */
1306 if (*chan_start)
1307 band--;
1308 break;
1309 }
Johannes Bergee688b002008-01-24 19:38:39 +01001310 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001312
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 if (band < IEEE80211_NUM_BANDS)
1314 *band_start = band + 1;
1315 else
1316 *band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001317
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 /* if bands & channels are done, continue outside */
1319 if (*band_start == 0 && *chan_start == 0)
1320 (*split_start)++;
1321 if (split)
1322 break;
1323 case 4:
1324 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1325 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327
1328 i = 0;
1329#define CMD(op, n) \
1330 do { \
1331 if (dev->ops->op) { \
1332 i++; \
1333 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1334 goto nla_put_failure; \
1335 } \
1336 } while (0)
1337
1338 CMD(add_virtual_intf, NEW_INTERFACE);
1339 CMD(change_virtual_intf, SET_INTERFACE);
1340 CMD(add_key, NEW_KEY);
1341 CMD(start_ap, START_AP);
1342 CMD(add_station, NEW_STATION);
1343 CMD(add_mpath, NEW_MPATH);
1344 CMD(update_mesh_config, SET_MESH_CONFIG);
1345 CMD(change_bss, SET_BSS);
1346 CMD(auth, AUTHENTICATE);
1347 CMD(assoc, ASSOCIATE);
1348 CMD(deauth, DEAUTHENTICATE);
1349 CMD(disassoc, DISASSOCIATE);
1350 CMD(join_ibss, JOIN_IBSS);
1351 CMD(join_mesh, JOIN_MESH);
1352 CMD(set_pmksa, SET_PMKSA);
1353 CMD(del_pmksa, DEL_PMKSA);
1354 CMD(flush_pmksa, FLUSH_PMKSA);
1355 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1356 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1357 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1358 CMD(mgmt_tx, FRAME);
1359 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1360 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1361 i++;
1362 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1363 goto nla_put_failure;
1364 }
1365 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1366 dev->ops->join_mesh) {
1367 i++;
1368 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1369 goto nla_put_failure;
1370 }
1371 CMD(set_wds_peer, SET_WDS_PEER);
1372 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1373 CMD(tdls_mgmt, TDLS_MGMT);
1374 CMD(tdls_oper, TDLS_OPER);
1375 }
1376 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1377 CMD(sched_scan_start, START_SCHED_SCAN);
1378 CMD(probe_client, PROBE_CLIENT);
1379 CMD(set_noack_map, SET_NOACK_MAP);
1380 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1381 i++;
1382 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1383 goto nla_put_failure;
1384 }
1385 CMD(start_p2p_device, START_P2P_DEVICE);
1386 CMD(set_mcast_rate, SET_MCAST_RATE);
Arend van Spriel5de17982013-04-18 15:49:00 +02001387 if (split) {
1388 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1389 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1390 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001391
Kalle Valo4745fc02011-11-17 19:06:10 +02001392#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001394#endif
1395
Johannes Berg8fdc6212009-03-14 09:34:01 +01001396#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001397
Johannes Berg3713b4e2013-02-14 16:19:38 +01001398 if (dev->ops->connect || dev->ops->auth) {
1399 i++;
1400 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001401 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001402 }
1403
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 if (dev->ops->disconnect || dev->ops->deauth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1407 goto nla_put_failure;
1408 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001409
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 nla_nest_end(msg, nl_cmds);
1411 (*split_start)++;
1412 if (split)
1413 break;
1414 case 5:
1415 if (dev->ops->remain_on_channel &&
1416 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1417 nla_put_u32(msg,
1418 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1419 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001420 goto nla_put_failure;
1421
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1423 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1424 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001425
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1427 goto nla_put_failure;
1428 (*split_start)++;
1429 if (split)
1430 break;
1431 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001432#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001433 if (nl80211_send_wowlan(msg, dev, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 goto nla_put_failure;
1435 (*split_start)++;
1436 if (split)
1437 break;
1438#else
1439 (*split_start)++;
1440#endif
1441 case 7:
1442 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1443 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001444 goto nla_put_failure;
1445
Johannes Bergcdc89b92013-02-18 23:54:36 +01001446 if (nl80211_put_iface_combinations(&dev->wiphy, msg, split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001448
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 (*split_start)++;
1450 if (split)
1451 break;
1452 case 8:
1453 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1454 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1455 dev->wiphy.ap_sme_capa))
1456 goto nla_put_failure;
1457
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001458 features = dev->wiphy.features;
1459 /*
1460 * We can only add the per-channel limit information if the
1461 * dump is split, otherwise it makes it too big. Therefore
1462 * only advertise it in that case.
1463 */
1464 if (split)
1465 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1466 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001467 goto nla_put_failure;
1468
1469 if (dev->wiphy.ht_capa_mod_mask &&
1470 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1471 sizeof(*dev->wiphy.ht_capa_mod_mask),
1472 dev->wiphy.ht_capa_mod_mask))
1473 goto nla_put_failure;
1474
1475 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1476 dev->wiphy.max_acl_mac_addrs &&
1477 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1478 dev->wiphy.max_acl_mac_addrs))
1479 goto nla_put_failure;
1480
1481 /*
1482 * Any information below this point is only available to
1483 * applications that can deal with it being split. This
1484 * helps ensure that newly added capabilities don't break
1485 * older tools by overrunning their buffers.
1486 *
1487 * We still increment split_start so that in the split
1488 * case we'll continue with more data in the next round,
1489 * but break unconditionally so unsplit data stops here.
1490 */
1491 (*split_start)++;
1492 break;
1493 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001494 if (dev->wiphy.extended_capabilities &&
1495 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1496 dev->wiphy.extended_capabilities_len,
1497 dev->wiphy.extended_capabilities) ||
1498 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1499 dev->wiphy.extended_capabilities_len,
1500 dev->wiphy.extended_capabilities_mask)))
1501 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502
Johannes Bergee2aca32013-02-21 17:36:01 +01001503 if (dev->wiphy.vht_capa_mod_mask &&
1504 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1505 sizeof(*dev->wiphy.vht_capa_mod_mask),
1506 dev->wiphy.vht_capa_mod_mask))
1507 goto nla_put_failure;
1508
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509 /* done */
1510 *split_start = 0;
1511 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001512 }
Johannes Berg55682962007-09-20 13:09:35 -04001513 return genlmsg_end(msg, hdr);
1514
1515 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001516 genlmsg_cancel(msg, hdr);
1517 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001518}
1519
1520static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1521{
Johannes Berg645e77d2013-03-01 14:03:49 +01001522 int idx = 0, ret;
Johannes Berg55682962007-09-20 13:09:35 -04001523 int start = cb->args[0];
1524 struct cfg80211_registered_device *dev;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 s64 filter_wiphy = -1;
1526 bool split = false;
1527 struct nlattr **tb = nl80211_fam.attrbuf;
1528 int res;
Johannes Berg55682962007-09-20 13:09:35 -04001529
Johannes Berg5fe231e2013-05-08 21:45:15 +02001530 rtnl_lock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1532 tb, nl80211_fam.maxattr, nl80211_policy);
1533 if (res == 0) {
1534 split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1535 if (tb[NL80211_ATTR_WIPHY])
1536 filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1537 if (tb[NL80211_ATTR_WDEV])
1538 filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1539 if (tb[NL80211_ATTR_IFINDEX]) {
1540 struct net_device *netdev;
1541 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1542
1543 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg940d0ac2013-06-11 16:51:03 +02001544 if (!netdev) {
1545 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 return -ENODEV;
Johannes Berg940d0ac2013-06-11 16:51:03 +02001547 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 if (netdev->ieee80211_ptr) {
1549 dev = wiphy_to_dev(
1550 netdev->ieee80211_ptr->wiphy);
1551 filter_wiphy = dev->wiphy_idx;
1552 }
1553 dev_put(netdev);
1554 }
1555 }
1556
Johannes Berg79c97e92009-07-07 03:56:12 +02001557 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001558 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1559 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001560 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001561 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1563 continue;
1564 /* attempt to fit multiple wiphy data chunks into the skb */
1565 do {
1566 ret = nl80211_send_wiphy(dev, skb,
1567 NETLINK_CB(cb->skb).portid,
1568 cb->nlh->nlmsg_seq,
1569 NLM_F_MULTI,
1570 split, &cb->args[1],
1571 &cb->args[2],
1572 &cb->args[3]);
1573 if (ret < 0) {
1574 /*
1575 * If sending the wiphy data didn't fit (ENOBUFS
1576 * or EMSGSIZE returned), this SKB is still
1577 * empty (so it's not too big because another
1578 * wiphy dataset is already in the skb) and
1579 * we've not tried to adjust the dump allocation
1580 * yet ... then adjust the alloc size to be
1581 * bigger, and return 1 but with the empty skb.
1582 * This results in an empty message being RX'ed
1583 * in userspace, but that is ignored.
1584 *
1585 * We can then retry with the larger buffer.
1586 */
1587 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1588 !skb->len &&
1589 cb->min_dump_alloc < 4096) {
1590 cb->min_dump_alloc = 4096;
Johannes Berg940d0ac2013-06-11 16:51:03 +02001591 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 return 1;
1593 }
1594 idx--;
1595 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001596 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 } while (cb->args[1] > 0);
1598 break;
Johannes Berg55682962007-09-20 13:09:35 -04001599 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001600 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001601
1602 cb->args[0] = idx;
1603
1604 return skb->len;
1605}
1606
1607static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1608{
1609 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001610 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001611
Johannes Berg645e77d2013-03-01 14:03:49 +01001612 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001613 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001614 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001615
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1617 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001618 nlmsg_free(msg);
1619 return -ENOBUFS;
1620 }
Johannes Berg55682962007-09-20 13:09:35 -04001621
Johannes Berg134e6372009-07-10 09:51:34 +00001622 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001623}
1624
Jouni Malinen31888482008-10-30 16:59:24 +02001625static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1626 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1627 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1628 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1629 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1630 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1631};
1632
1633static int parse_txq_params(struct nlattr *tb[],
1634 struct ieee80211_txq_params *txq_params)
1635{
Johannes Berga3304b02012-03-28 11:04:24 +02001636 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001637 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1638 !tb[NL80211_TXQ_ATTR_AIFS])
1639 return -EINVAL;
1640
Johannes Berga3304b02012-03-28 11:04:24 +02001641 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001642 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1643 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1644 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1645 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1646
Johannes Berga3304b02012-03-28 11:04:24 +02001647 if (txq_params->ac >= NL80211_NUM_ACS)
1648 return -EINVAL;
1649
Jouni Malinen31888482008-10-30 16:59:24 +02001650 return 0;
1651}
1652
Johannes Bergf444de02010-05-05 15:25:02 +02001653static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1654{
1655 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001656 * You can only set the channel explicitly for WDS interfaces,
1657 * all others have their channel managed via their respective
1658 * "establish a connection" command (connect, join, ...)
1659 *
1660 * For AP/GO and mesh mode, the channel can be set with the
1661 * channel userspace API, but is only stored and passed to the
1662 * low-level driver when the AP starts or the mesh is joined.
1663 * This is for backward compatibility, userspace can also give
1664 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001665 *
1666 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001667 * whatever else is going on, so they have their own special
1668 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001669 */
1670 return !wdev ||
1671 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001672 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001673 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1674 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001675}
1676
Johannes Berg683b6d32012-11-08 21:25:48 +01001677static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1678 struct genl_info *info,
1679 struct cfg80211_chan_def *chandef)
1680{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301681 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001682
1683 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1684 return -EINVAL;
1685
1686 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1687
1688 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001689 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1690 chandef->center_freq1 = control_freq;
1691 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001692
1693 /* Primary channel not allowed */
1694 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1695 return -EINVAL;
1696
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001697 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1698 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001699
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001700 chantype = nla_get_u32(
1701 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1702
1703 switch (chantype) {
1704 case NL80211_CHAN_NO_HT:
1705 case NL80211_CHAN_HT20:
1706 case NL80211_CHAN_HT40PLUS:
1707 case NL80211_CHAN_HT40MINUS:
1708 cfg80211_chandef_create(chandef, chandef->chan,
1709 chantype);
1710 break;
1711 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001712 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001713 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001714 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1715 chandef->width =
1716 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1717 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1718 chandef->center_freq1 =
1719 nla_get_u32(
1720 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1721 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1722 chandef->center_freq2 =
1723 nla_get_u32(
1724 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1725 }
1726
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001727 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001728 return -EINVAL;
1729
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001730 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1731 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001732 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001733
Johannes Berg683b6d32012-11-08 21:25:48 +01001734 return 0;
1735}
1736
Johannes Bergf444de02010-05-05 15:25:02 +02001737static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1738 struct wireless_dev *wdev,
1739 struct genl_info *info)
1740{
Johannes Berg683b6d32012-11-08 21:25:48 +01001741 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001742 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001743 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1744
1745 if (wdev)
1746 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001747
Johannes Bergf444de02010-05-05 15:25:02 +02001748 if (!nl80211_can_set_dev_channel(wdev))
1749 return -EOPNOTSUPP;
1750
Johannes Berg683b6d32012-11-08 21:25:48 +01001751 result = nl80211_parse_chandef(rdev, info, &chandef);
1752 if (result)
1753 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001754
Johannes Berge8c9bd52012-06-06 08:18:22 +02001755 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001756 case NL80211_IFTYPE_AP:
1757 case NL80211_IFTYPE_P2P_GO:
1758 if (wdev->beacon_interval) {
1759 result = -EBUSY;
1760 break;
1761 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001762 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001763 result = -EINVAL;
1764 break;
1765 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001766 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001767 result = 0;
1768 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001769 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001771 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001772 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001773 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001774 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001775 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001776 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001777 }
Johannes Bergf444de02010-05-05 15:25:02 +02001778
1779 return result;
1780}
1781
1782static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1783{
Johannes Berg4c476992010-10-04 21:36:35 +02001784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1785 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001786
Johannes Berg4c476992010-10-04 21:36:35 +02001787 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001788}
1789
Bill Jordane8347eb2010-10-01 13:54:28 -04001790static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1791{
Johannes Berg43b19952010-10-07 13:10:30 +02001792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1793 struct net_device *dev = info->user_ptr[1];
1794 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001795 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001796
1797 if (!info->attrs[NL80211_ATTR_MAC])
1798 return -EINVAL;
1799
Johannes Berg43b19952010-10-07 13:10:30 +02001800 if (netif_running(dev))
1801 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001802
Johannes Berg43b19952010-10-07 13:10:30 +02001803 if (!rdev->ops->set_wds_peer)
1804 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001805
Johannes Berg43b19952010-10-07 13:10:30 +02001806 if (wdev->iftype != NL80211_IFTYPE_WDS)
1807 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001808
1809 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001810 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001811}
1812
1813
Johannes Berg55682962007-09-20 13:09:35 -04001814static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1815{
1816 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001817 struct net_device *netdev = NULL;
1818 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001819 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001820 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001821 u32 changed;
1822 u8 retry_short = 0, retry_long = 0;
1823 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001824 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001825
Johannes Berg5fe231e2013-05-08 21:45:15 +02001826 ASSERT_RTNL();
1827
Johannes Bergf444de02010-05-05 15:25:02 +02001828 /*
1829 * Try to find the wiphy and netdev. Normally this
1830 * function shouldn't need the netdev, but this is
1831 * done for backward compatibility -- previously
1832 * setting the channel was done per wiphy, but now
1833 * it is per netdev. Previous userland like hostapd
1834 * also passed a netdev to set_wiphy, so that it is
1835 * possible to let that go to the right netdev!
1836 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001837
Johannes Bergf444de02010-05-05 15:25:02 +02001838 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1839 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1840
1841 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001842 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001843 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001844 else
Johannes Bergf444de02010-05-05 15:25:02 +02001845 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001846 }
1847
Johannes Bergf444de02010-05-05 15:25:02 +02001848 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001849 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1850 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001851 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001852 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001853 wdev = NULL;
1854 netdev = NULL;
1855 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001856 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001857 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001858
1859 /*
1860 * end workaround code, by now the rdev is available
1861 * and locked, and wdev may or may not be NULL.
1862 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001863
1864 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001865 result = cfg80211_dev_rename(
1866 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001867
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001868 if (result)
1869 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001870
Jouni Malinen31888482008-10-30 16:59:24 +02001871 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1872 struct ieee80211_txq_params txq_params;
1873 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1874
1875 if (!rdev->ops->set_txq_params) {
1876 result = -EOPNOTSUPP;
1877 goto bad_res;
1878 }
1879
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001880 if (!netdev) {
1881 result = -EINVAL;
1882 goto bad_res;
1883 }
1884
Johannes Berg133a3ff2011-11-03 14:50:13 +01001885 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1886 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1887 result = -EINVAL;
1888 goto bad_res;
1889 }
1890
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001891 if (!netif_running(netdev)) {
1892 result = -ENETDOWN;
1893 goto bad_res;
1894 }
1895
Jouni Malinen31888482008-10-30 16:59:24 +02001896 nla_for_each_nested(nl_txq_params,
1897 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1898 rem_txq_params) {
1899 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1900 nla_data(nl_txq_params),
1901 nla_len(nl_txq_params),
1902 txq_params_policy);
1903 result = parse_txq_params(tb, &txq_params);
1904 if (result)
1905 goto bad_res;
1906
Hila Gonene35e4d22012-06-27 17:19:42 +03001907 result = rdev_set_txq_params(rdev, netdev,
1908 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001909 if (result)
1910 goto bad_res;
1911 }
1912 }
1913
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001914 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001915 result = __nl80211_set_channel(rdev,
1916 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1917 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001918 if (result)
1919 goto bad_res;
1920 }
1921
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001922 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001923 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001924 enum nl80211_tx_power_setting type;
1925 int idx, mbm = 0;
1926
Johannes Bergc8442112012-10-24 10:17:18 +02001927 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1928 txp_wdev = NULL;
1929
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001930 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001931 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001932 goto bad_res;
1933 }
1934
1935 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1936 type = nla_get_u32(info->attrs[idx]);
1937
1938 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1939 (type != NL80211_TX_POWER_AUTOMATIC)) {
1940 result = -EINVAL;
1941 goto bad_res;
1942 }
1943
1944 if (type != NL80211_TX_POWER_AUTOMATIC) {
1945 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1946 mbm = nla_get_u32(info->attrs[idx]);
1947 }
1948
Johannes Bergc8442112012-10-24 10:17:18 +02001949 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001950 if (result)
1951 goto bad_res;
1952 }
1953
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001954 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1955 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1956 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001957 if ((!rdev->wiphy.available_antennas_tx &&
1958 !rdev->wiphy.available_antennas_rx) ||
1959 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001960 result = -EOPNOTSUPP;
1961 goto bad_res;
1962 }
1963
1964 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1965 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1966
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001967 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001968 * available antenna masks, except for the "all" mask */
1969 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1970 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001971 result = -EINVAL;
1972 goto bad_res;
1973 }
1974
Bruno Randolf7f531e02010-12-16 11:30:22 +09001975 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1976 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001977
Hila Gonene35e4d22012-06-27 17:19:42 +03001978 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001979 if (result)
1980 goto bad_res;
1981 }
1982
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001983 changed = 0;
1984
1985 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1986 retry_short = nla_get_u8(
1987 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1988 if (retry_short == 0) {
1989 result = -EINVAL;
1990 goto bad_res;
1991 }
1992 changed |= WIPHY_PARAM_RETRY_SHORT;
1993 }
1994
1995 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1996 retry_long = nla_get_u8(
1997 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1998 if (retry_long == 0) {
1999 result = -EINVAL;
2000 goto bad_res;
2001 }
2002 changed |= WIPHY_PARAM_RETRY_LONG;
2003 }
2004
2005 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2006 frag_threshold = nla_get_u32(
2007 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2008 if (frag_threshold < 256) {
2009 result = -EINVAL;
2010 goto bad_res;
2011 }
2012 if (frag_threshold != (u32) -1) {
2013 /*
2014 * Fragments (apart from the last one) are required to
2015 * have even length. Make the fragmentation code
2016 * simpler by stripping LSB should someone try to use
2017 * odd threshold value.
2018 */
2019 frag_threshold &= ~0x1;
2020 }
2021 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2022 }
2023
2024 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2025 rts_threshold = nla_get_u32(
2026 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2027 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2028 }
2029
Lukáš Turek81077e82009-12-21 22:50:47 +01002030 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2031 coverage_class = nla_get_u8(
2032 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2033 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2034 }
2035
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002036 if (changed) {
2037 u8 old_retry_short, old_retry_long;
2038 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002039 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002040
2041 if (!rdev->ops->set_wiphy_params) {
2042 result = -EOPNOTSUPP;
2043 goto bad_res;
2044 }
2045
2046 old_retry_short = rdev->wiphy.retry_short;
2047 old_retry_long = rdev->wiphy.retry_long;
2048 old_frag_threshold = rdev->wiphy.frag_threshold;
2049 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002050 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002051
2052 if (changed & WIPHY_PARAM_RETRY_SHORT)
2053 rdev->wiphy.retry_short = retry_short;
2054 if (changed & WIPHY_PARAM_RETRY_LONG)
2055 rdev->wiphy.retry_long = retry_long;
2056 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2057 rdev->wiphy.frag_threshold = frag_threshold;
2058 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2059 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002060 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2061 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002062
Hila Gonene35e4d22012-06-27 17:19:42 +03002063 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002064 if (result) {
2065 rdev->wiphy.retry_short = old_retry_short;
2066 rdev->wiphy.retry_long = old_retry_long;
2067 rdev->wiphy.frag_threshold = old_frag_threshold;
2068 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002069 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070 }
2071 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002072
Johannes Berg306d6112008-12-08 12:39:04 +01002073 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002074 if (netdev)
2075 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002076 return result;
2077}
2078
Johannes Berg71bbc992012-06-15 15:30:18 +02002079static inline u64 wdev_id(struct wireless_dev *wdev)
2080{
2081 return (u64)wdev->identifier |
2082 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2083}
Johannes Berg55682962007-09-20 13:09:35 -04002084
Johannes Berg683b6d32012-11-08 21:25:48 +01002085static int nl80211_send_chandef(struct sk_buff *msg,
2086 struct cfg80211_chan_def *chandef)
2087{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002088 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002089
Johannes Berg683b6d32012-11-08 21:25:48 +01002090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2091 chandef->chan->center_freq))
2092 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002093 switch (chandef->width) {
2094 case NL80211_CHAN_WIDTH_20_NOHT:
2095 case NL80211_CHAN_WIDTH_20:
2096 case NL80211_CHAN_WIDTH_40:
2097 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2098 cfg80211_get_chandef_type(chandef)))
2099 return -ENOBUFS;
2100 break;
2101 default:
2102 break;
2103 }
2104 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2105 return -ENOBUFS;
2106 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2107 return -ENOBUFS;
2108 if (chandef->center_freq2 &&
2109 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002110 return -ENOBUFS;
2111 return 0;
2112}
2113
Eric W. Biederman15e47302012-09-07 20:12:54 +00002114static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002115 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002116 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002117{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002118 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002119 void *hdr;
2120
Eric W. Biederman15e47302012-09-07 20:12:54 +00002121 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002122 if (!hdr)
2123 return -1;
2124
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002125 if (dev &&
2126 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002127 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002128 goto nla_put_failure;
2129
2130 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2131 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002132 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002133 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002134 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2135 rdev->devlist_generation ^
2136 (cfg80211_rdev_list_generation << 2)))
2137 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002138
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002139 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002140 int ret;
2141 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002142
Johannes Berg683b6d32012-11-08 21:25:48 +01002143 ret = rdev_get_channel(rdev, wdev, &chandef);
2144 if (ret == 0) {
2145 if (nl80211_send_chandef(msg, &chandef))
2146 goto nla_put_failure;
2147 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002148 }
2149
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002150 if (wdev->ssid_len) {
2151 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2152 goto nla_put_failure;
2153 }
2154
Johannes Berg55682962007-09-20 13:09:35 -04002155 return genlmsg_end(msg, hdr);
2156
2157 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002158 genlmsg_cancel(msg, hdr);
2159 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002160}
2161
2162static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2163{
2164 int wp_idx = 0;
2165 int if_idx = 0;
2166 int wp_start = cb->args[0];
2167 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002168 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002169 struct wireless_dev *wdev;
2170
Johannes Berg5fe231e2013-05-08 21:45:15 +02002171 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002172 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2173 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002174 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002175 if (wp_idx < wp_start) {
2176 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002177 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002178 }
Johannes Berg55682962007-09-20 13:09:35 -04002179 if_idx = 0;
2180
Johannes Berg89a54e42012-06-15 14:33:17 +02002181 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002182 if (if_idx < if_start) {
2183 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002184 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002185 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002186 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002187 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002188 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002189 goto out;
2190 }
2191 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002192 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193
2194 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002195 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002196 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002197 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002198
2199 cb->args[0] = wp_idx;
2200 cb->args[1] = if_idx;
2201
2202 return skb->len;
2203}
2204
2205static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2206{
2207 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002208 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002209 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002210
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002212 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002213 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002214
Eric W. Biederman15e47302012-09-07 20:12:54 +00002215 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002216 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002217 nlmsg_free(msg);
2218 return -ENOBUFS;
2219 }
Johannes Berg55682962007-09-20 13:09:35 -04002220
Johannes Berg134e6372009-07-10 09:51:34 +00002221 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002222}
2223
Michael Wu66f7ac52008-01-31 19:48:22 +01002224static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2225 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2226 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2227 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2228 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2229 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002230 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002231};
2232
2233static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2234{
2235 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2236 int flag;
2237
2238 *mntrflags = 0;
2239
2240 if (!nla)
2241 return -EINVAL;
2242
2243 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2244 nla, mntr_flags_policy))
2245 return -EINVAL;
2246
2247 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2248 if (flags[flag])
2249 *mntrflags |= (1<<flag);
2250
2251 return 0;
2252}
2253
Johannes Berg9bc383d2009-11-19 11:55:19 +01002254static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002255 struct net_device *netdev, u8 use_4addr,
2256 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002257{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002258 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002259 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002260 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002261 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002262 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002263
2264 switch (iftype) {
2265 case NL80211_IFTYPE_AP_VLAN:
2266 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2267 return 0;
2268 break;
2269 case NL80211_IFTYPE_STATION:
2270 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2271 return 0;
2272 break;
2273 default:
2274 break;
2275 }
2276
2277 return -EOPNOTSUPP;
2278}
2279
Johannes Berg55682962007-09-20 13:09:35 -04002280static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2281{
Johannes Berg4c476992010-10-04 21:36:35 +02002282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002283 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002284 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002285 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002286 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002287 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002288 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002289
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002290 memset(&params, 0, sizeof(params));
2291
Johannes Berg04a773a2009-04-19 21:24:32 +02002292 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002293
Johannes Berg723b0382008-09-16 20:22:09 +02002294 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002295 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002296 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002297 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002298 if (ntype > NL80211_IFTYPE_MAX)
2299 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002300 }
2301
Johannes Berg92ffe052008-09-16 20:39:36 +02002302 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002303 struct wireless_dev *wdev = dev->ieee80211_ptr;
2304
Johannes Berg4c476992010-10-04 21:36:35 +02002305 if (ntype != NL80211_IFTYPE_MESH_POINT)
2306 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002307 if (netif_running(dev))
2308 return -EBUSY;
2309
2310 wdev_lock(wdev);
2311 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2312 IEEE80211_MAX_MESH_ID_LEN);
2313 wdev->mesh_id_up_len =
2314 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2315 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2316 wdev->mesh_id_up_len);
2317 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002318 }
2319
Felix Fietkau8b787642009-11-10 18:53:10 +01002320 if (info->attrs[NL80211_ATTR_4ADDR]) {
2321 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2322 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002323 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002324 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002325 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002326 } else {
2327 params.use_4addr = -1;
2328 }
2329
Johannes Berg92ffe052008-09-16 20:39:36 +02002330 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002331 if (ntype != NL80211_IFTYPE_MONITOR)
2332 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002333 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2334 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002335 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002336 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002337
2338 flags = &_flags;
2339 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002340 }
Johannes Berg3b858752009-03-12 09:55:09 +01002341
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002342 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2343 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2344 return -EOPNOTSUPP;
2345
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002346 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002347 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002348 else
2349 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002350
Johannes Berg9bc383d2009-11-19 11:55:19 +01002351 if (!err && params.use_4addr != -1)
2352 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2353
Johannes Berg55682962007-09-20 13:09:35 -04002354 return err;
2355}
2356
2357static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2358{
Johannes Berg4c476992010-10-04 21:36:35 +02002359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002360 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002361 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002362 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002363 int err;
2364 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002365 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002366
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002367 memset(&params, 0, sizeof(params));
2368
Johannes Berg55682962007-09-20 13:09:35 -04002369 if (!info->attrs[NL80211_ATTR_IFNAME])
2370 return -EINVAL;
2371
2372 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2373 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2374 if (type > NL80211_IFTYPE_MAX)
2375 return -EINVAL;
2376 }
2377
Johannes Berg79c97e92009-07-07 03:56:12 +02002378 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002379 !(rdev->wiphy.interface_modes & (1 << type)))
2380 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002381
Arend van Spriel1c18f142013-01-08 10:17:27 +01002382 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2383 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2384 ETH_ALEN);
2385 if (!is_valid_ether_addr(params.macaddr))
2386 return -EADDRNOTAVAIL;
2387 }
2388
Johannes Berg9bc383d2009-11-19 11:55:19 +01002389 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002390 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002391 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002392 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002393 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002394 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002395
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002396 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2397 if (!msg)
2398 return -ENOMEM;
2399
Michael Wu66f7ac52008-01-31 19:48:22 +01002400 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2401 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2402 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002403
2404 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2405 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2406 return -EOPNOTSUPP;
2407
Hila Gonene35e4d22012-06-27 17:19:42 +03002408 wdev = rdev_add_virtual_intf(rdev,
2409 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2410 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002411 if (IS_ERR(wdev)) {
2412 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002413 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002414 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002415
Johannes Berg98104fde2012-06-16 00:19:54 +02002416 switch (type) {
2417 case NL80211_IFTYPE_MESH_POINT:
2418 if (!info->attrs[NL80211_ATTR_MESH_ID])
2419 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002420 wdev_lock(wdev);
2421 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2422 IEEE80211_MAX_MESH_ID_LEN);
2423 wdev->mesh_id_up_len =
2424 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2425 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2426 wdev->mesh_id_up_len);
2427 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002428 break;
2429 case NL80211_IFTYPE_P2P_DEVICE:
2430 /*
2431 * P2P Device doesn't have a netdev, so doesn't go
2432 * through the netdev notifier and must be added here
2433 */
2434 mutex_init(&wdev->mtx);
2435 INIT_LIST_HEAD(&wdev->event_list);
2436 spin_lock_init(&wdev->event_lock);
2437 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2438 spin_lock_init(&wdev->mgmt_registrations_lock);
2439
Johannes Berg98104fde2012-06-16 00:19:54 +02002440 wdev->identifier = ++rdev->wdev_id;
2441 list_add_rcu(&wdev->list, &rdev->wdev_list);
2442 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002443 break;
2444 default:
2445 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002446 }
2447
Eric W. Biederman15e47302012-09-07 20:12:54 +00002448 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002449 rdev, wdev) < 0) {
2450 nlmsg_free(msg);
2451 return -ENOBUFS;
2452 }
2453
2454 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002455}
2456
2457static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2458{
Johannes Berg4c476992010-10-04 21:36:35 +02002459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002460 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002461
Johannes Berg4c476992010-10-04 21:36:35 +02002462 if (!rdev->ops->del_virtual_intf)
2463 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002464
Johannes Berg84efbb82012-06-16 00:00:26 +02002465 /*
2466 * If we remove a wireless device without a netdev then clear
2467 * user_ptr[1] so that nl80211_post_doit won't dereference it
2468 * to check if it needs to do dev_put(). Otherwise it crashes
2469 * since the wdev has been freed, unlike with a netdev where
2470 * we need the dev_put() for the netdev to really be freed.
2471 */
2472 if (!wdev->netdev)
2473 info->user_ptr[1] = NULL;
2474
Hila Gonene35e4d22012-06-27 17:19:42 +03002475 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002476}
2477
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002478static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2479{
2480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2481 struct net_device *dev = info->user_ptr[1];
2482 u16 noack_map;
2483
2484 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2485 return -EINVAL;
2486
2487 if (!rdev->ops->set_noack_map)
2488 return -EOPNOTSUPP;
2489
2490 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2491
Hila Gonene35e4d22012-06-27 17:19:42 +03002492 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002493}
2494
Johannes Berg41ade002007-12-19 02:03:29 +01002495struct get_key_cookie {
2496 struct sk_buff *msg;
2497 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002498 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002499};
2500
2501static void get_key_callback(void *c, struct key_params *params)
2502{
Johannes Bergb9454e82009-07-08 13:29:08 +02002503 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002504 struct get_key_cookie *cookie = c;
2505
David S. Miller9360ffd2012-03-29 04:41:26 -04002506 if ((params->key &&
2507 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2508 params->key_len, params->key)) ||
2509 (params->seq &&
2510 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2511 params->seq_len, params->seq)) ||
2512 (params->cipher &&
2513 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2514 params->cipher)))
2515 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002516
Johannes Bergb9454e82009-07-08 13:29:08 +02002517 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2518 if (!key)
2519 goto nla_put_failure;
2520
David S. Miller9360ffd2012-03-29 04:41:26 -04002521 if ((params->key &&
2522 nla_put(cookie->msg, NL80211_KEY_DATA,
2523 params->key_len, params->key)) ||
2524 (params->seq &&
2525 nla_put(cookie->msg, NL80211_KEY_SEQ,
2526 params->seq_len, params->seq)) ||
2527 (params->cipher &&
2528 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2529 params->cipher)))
2530 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531
David S. Miller9360ffd2012-03-29 04:41:26 -04002532 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2533 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002534
2535 nla_nest_end(cookie->msg, key);
2536
Johannes Berg41ade002007-12-19 02:03:29 +01002537 return;
2538 nla_put_failure:
2539 cookie->error = 1;
2540}
2541
2542static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2543{
Johannes Berg4c476992010-10-04 21:36:35 +02002544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002545 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002546 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002547 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002548 const u8 *mac_addr = NULL;
2549 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002550 struct get_key_cookie cookie = {
2551 .error = 0,
2552 };
2553 void *hdr;
2554 struct sk_buff *msg;
2555
2556 if (info->attrs[NL80211_ATTR_KEY_IDX])
2557 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2558
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002559 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002560 return -EINVAL;
2561
2562 if (info->attrs[NL80211_ATTR_MAC])
2563 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2564
Johannes Berge31b8212010-10-05 19:39:30 +02002565 pairwise = !!mac_addr;
2566 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2567 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2568 if (kt >= NUM_NL80211_KEYTYPES)
2569 return -EINVAL;
2570 if (kt != NL80211_KEYTYPE_GROUP &&
2571 kt != NL80211_KEYTYPE_PAIRWISE)
2572 return -EINVAL;
2573 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2574 }
2575
Johannes Berg4c476992010-10-04 21:36:35 +02002576 if (!rdev->ops->get_key)
2577 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002578
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002580 if (!msg)
2581 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002582
Eric W. Biederman15e47302012-09-07 20:12:54 +00002583 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002584 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002585 if (IS_ERR(hdr))
2586 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002587
2588 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002589 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002590
David S. Miller9360ffd2012-03-29 04:41:26 -04002591 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2592 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2593 goto nla_put_failure;
2594 if (mac_addr &&
2595 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2596 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002597
Johannes Berge31b8212010-10-05 19:39:30 +02002598 if (pairwise && mac_addr &&
2599 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2600 return -ENOENT;
2601
Hila Gonene35e4d22012-06-27 17:19:42 +03002602 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2603 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002604
2605 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002606 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002607
2608 if (cookie.error)
2609 goto nla_put_failure;
2610
2611 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002612 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002613
2614 nla_put_failure:
2615 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002616 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002617 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002618 return err;
2619}
2620
2621static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2622{
Johannes Berg4c476992010-10-04 21:36:35 +02002623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002624 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002625 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002626 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002627
Johannes Bergb9454e82009-07-08 13:29:08 +02002628 err = nl80211_parse_key(info, &key);
2629 if (err)
2630 return err;
2631
2632 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002633 return -EINVAL;
2634
Johannes Bergb9454e82009-07-08 13:29:08 +02002635 /* only support setting default key */
2636 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002637 return -EINVAL;
2638
Johannes Bergfffd0932009-07-08 14:22:54 +02002639 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002640
2641 if (key.def) {
2642 if (!rdev->ops->set_default_key) {
2643 err = -EOPNOTSUPP;
2644 goto out;
2645 }
2646
2647 err = nl80211_key_allowed(dev->ieee80211_ptr);
2648 if (err)
2649 goto out;
2650
Hila Gonene35e4d22012-06-27 17:19:42 +03002651 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002652 key.def_uni, key.def_multi);
2653
2654 if (err)
2655 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002656
Johannes Berg3d23e342009-09-29 23:27:28 +02002657#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002658 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002659#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002660 } else {
2661 if (key.def_uni || !key.def_multi) {
2662 err = -EINVAL;
2663 goto out;
2664 }
2665
2666 if (!rdev->ops->set_default_mgmt_key) {
2667 err = -EOPNOTSUPP;
2668 goto out;
2669 }
2670
2671 err = nl80211_key_allowed(dev->ieee80211_ptr);
2672 if (err)
2673 goto out;
2674
Hila Gonene35e4d22012-06-27 17:19:42 +03002675 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002676 if (err)
2677 goto out;
2678
2679#ifdef CONFIG_CFG80211_WEXT
2680 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2681#endif
2682 }
2683
2684 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002685 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002686
Johannes Berg41ade002007-12-19 02:03:29 +01002687 return err;
2688}
2689
2690static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2691{
Johannes Berg4c476992010-10-04 21:36:35 +02002692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002693 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002694 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002695 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002696 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002697
Johannes Bergb9454e82009-07-08 13:29:08 +02002698 err = nl80211_parse_key(info, &key);
2699 if (err)
2700 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002701
Johannes Bergb9454e82009-07-08 13:29:08 +02002702 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002703 return -EINVAL;
2704
Johannes Berg41ade002007-12-19 02:03:29 +01002705 if (info->attrs[NL80211_ATTR_MAC])
2706 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2707
Johannes Berge31b8212010-10-05 19:39:30 +02002708 if (key.type == -1) {
2709 if (mac_addr)
2710 key.type = NL80211_KEYTYPE_PAIRWISE;
2711 else
2712 key.type = NL80211_KEYTYPE_GROUP;
2713 }
2714
2715 /* for now */
2716 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2717 key.type != NL80211_KEYTYPE_GROUP)
2718 return -EINVAL;
2719
Johannes Berg4c476992010-10-04 21:36:35 +02002720 if (!rdev->ops->add_key)
2721 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002722
Johannes Berge31b8212010-10-05 19:39:30 +02002723 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2724 key.type == NL80211_KEYTYPE_PAIRWISE,
2725 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002726 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002727
2728 wdev_lock(dev->ieee80211_ptr);
2729 err = nl80211_key_allowed(dev->ieee80211_ptr);
2730 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002731 err = rdev_add_key(rdev, dev, key.idx,
2732 key.type == NL80211_KEYTYPE_PAIRWISE,
2733 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002734 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002735
Johannes Berg41ade002007-12-19 02:03:29 +01002736 return err;
2737}
2738
2739static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2740{
Johannes Berg4c476992010-10-04 21:36:35 +02002741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002742 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002743 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002744 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002745 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002746
Johannes Bergb9454e82009-07-08 13:29:08 +02002747 err = nl80211_parse_key(info, &key);
2748 if (err)
2749 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002750
2751 if (info->attrs[NL80211_ATTR_MAC])
2752 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2753
Johannes Berge31b8212010-10-05 19:39:30 +02002754 if (key.type == -1) {
2755 if (mac_addr)
2756 key.type = NL80211_KEYTYPE_PAIRWISE;
2757 else
2758 key.type = NL80211_KEYTYPE_GROUP;
2759 }
2760
2761 /* for now */
2762 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2763 key.type != NL80211_KEYTYPE_GROUP)
2764 return -EINVAL;
2765
Johannes Berg4c476992010-10-04 21:36:35 +02002766 if (!rdev->ops->del_key)
2767 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002768
Johannes Bergfffd0932009-07-08 14:22:54 +02002769 wdev_lock(dev->ieee80211_ptr);
2770 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002771
2772 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2773 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2774 err = -ENOENT;
2775
Johannes Bergfffd0932009-07-08 14:22:54 +02002776 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002777 err = rdev_del_key(rdev, dev, key.idx,
2778 key.type == NL80211_KEYTYPE_PAIRWISE,
2779 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002780
Johannes Berg3d23e342009-09-29 23:27:28 +02002781#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002782 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002783 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002784 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002785 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002786 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2787 }
2788#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002789 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002790
Johannes Berg41ade002007-12-19 02:03:29 +01002791 return err;
2792}
2793
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302794/* This function returns an error or the number of nested attributes */
2795static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2796{
2797 struct nlattr *attr;
2798 int n_entries = 0, tmp;
2799
2800 nla_for_each_nested(attr, nl_attr, tmp) {
2801 if (nla_len(attr) != ETH_ALEN)
2802 return -EINVAL;
2803
2804 n_entries++;
2805 }
2806
2807 return n_entries;
2808}
2809
2810/*
2811 * This function parses ACL information and allocates memory for ACL data.
2812 * On successful return, the calling function is responsible to free the
2813 * ACL buffer returned by this function.
2814 */
2815static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2816 struct genl_info *info)
2817{
2818 enum nl80211_acl_policy acl_policy;
2819 struct nlattr *attr;
2820 struct cfg80211_acl_data *acl;
2821 int i = 0, n_entries, tmp;
2822
2823 if (!wiphy->max_acl_mac_addrs)
2824 return ERR_PTR(-EOPNOTSUPP);
2825
2826 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2827 return ERR_PTR(-EINVAL);
2828
2829 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2830 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2831 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2832 return ERR_PTR(-EINVAL);
2833
2834 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2835 return ERR_PTR(-EINVAL);
2836
2837 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2838 if (n_entries < 0)
2839 return ERR_PTR(n_entries);
2840
2841 if (n_entries > wiphy->max_acl_mac_addrs)
2842 return ERR_PTR(-ENOTSUPP);
2843
2844 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2845 GFP_KERNEL);
2846 if (!acl)
2847 return ERR_PTR(-ENOMEM);
2848
2849 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2850 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2851 i++;
2852 }
2853
2854 acl->n_acl_entries = n_entries;
2855 acl->acl_policy = acl_policy;
2856
2857 return acl;
2858}
2859
2860static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2861{
2862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2863 struct net_device *dev = info->user_ptr[1];
2864 struct cfg80211_acl_data *acl;
2865 int err;
2866
2867 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2868 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2869 return -EOPNOTSUPP;
2870
2871 if (!dev->ieee80211_ptr->beacon_interval)
2872 return -EINVAL;
2873
2874 acl = parse_acl_data(&rdev->wiphy, info);
2875 if (IS_ERR(acl))
2876 return PTR_ERR(acl);
2877
2878 err = rdev_set_mac_acl(rdev, dev, acl);
2879
2880 kfree(acl);
2881
2882 return err;
2883}
2884
Johannes Berg88600202012-02-13 15:17:18 +01002885static int nl80211_parse_beacon(struct genl_info *info,
2886 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002887{
Johannes Berg88600202012-02-13 15:17:18 +01002888 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002889
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002890 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2891 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2892 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2893 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002894 return -EINVAL;
2895
Johannes Berg88600202012-02-13 15:17:18 +01002896 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002897
Johannes Berged1b6cc2007-12-19 02:03:32 +01002898 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002899 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2900 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2901 if (!bcn->head_len)
2902 return -EINVAL;
2903 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002904 }
2905
2906 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002907 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2908 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002909 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002910 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002911 }
2912
Johannes Berg4c476992010-10-04 21:36:35 +02002913 if (!haveinfo)
2914 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002915
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002916 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002917 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2918 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002919 }
2920
2921 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002922 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002923 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002924 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002925 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2926 }
2927
2928 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002929 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002930 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002931 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002932 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2933 }
2934
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002935 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002936 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002937 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002938 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002939 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2940 }
2941
Johannes Berg88600202012-02-13 15:17:18 +01002942 return 0;
2943}
2944
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002945static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2946 struct cfg80211_ap_settings *params)
2947{
2948 struct wireless_dev *wdev;
2949 bool ret = false;
2950
Johannes Berg89a54e42012-06-15 14:33:17 +02002951 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002952 if (wdev->iftype != NL80211_IFTYPE_AP &&
2953 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2954 continue;
2955
Johannes Berg683b6d32012-11-08 21:25:48 +01002956 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002957 continue;
2958
Johannes Berg683b6d32012-11-08 21:25:48 +01002959 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002960 ret = true;
2961 break;
2962 }
2963
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002964 return ret;
2965}
2966
Jouni Malinene39e5b52012-09-30 19:29:39 +03002967static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2968 enum nl80211_auth_type auth_type,
2969 enum nl80211_commands cmd)
2970{
2971 if (auth_type > NL80211_AUTHTYPE_MAX)
2972 return false;
2973
2974 switch (cmd) {
2975 case NL80211_CMD_AUTHENTICATE:
2976 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2977 auth_type == NL80211_AUTHTYPE_SAE)
2978 return false;
2979 return true;
2980 case NL80211_CMD_CONNECT:
2981 case NL80211_CMD_START_AP:
2982 /* SAE not supported yet */
2983 if (auth_type == NL80211_AUTHTYPE_SAE)
2984 return false;
2985 return true;
2986 default:
2987 return false;
2988 }
2989}
2990
Johannes Berg88600202012-02-13 15:17:18 +01002991static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2992{
2993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2994 struct net_device *dev = info->user_ptr[1];
2995 struct wireless_dev *wdev = dev->ieee80211_ptr;
2996 struct cfg80211_ap_settings params;
2997 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01002998 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01002999
3000 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3001 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3002 return -EOPNOTSUPP;
3003
3004 if (!rdev->ops->start_ap)
3005 return -EOPNOTSUPP;
3006
3007 if (wdev->beacon_interval)
3008 return -EALREADY;
3009
3010 memset(&params, 0, sizeof(params));
3011
3012 /* these are required for START_AP */
3013 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3014 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3015 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3016 return -EINVAL;
3017
3018 err = nl80211_parse_beacon(info, &params.beacon);
3019 if (err)
3020 return err;
3021
3022 params.beacon_interval =
3023 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3024 params.dtim_period =
3025 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3026
3027 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3028 if (err)
3029 return err;
3030
3031 /*
3032 * In theory, some of these attributes should be required here
3033 * but since they were not used when the command was originally
3034 * added, keep them optional for old user space programs to let
3035 * them continue to work with drivers that do not need the
3036 * additional information -- drivers must check!
3037 */
3038 if (info->attrs[NL80211_ATTR_SSID]) {
3039 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3040 params.ssid_len =
3041 nla_len(info->attrs[NL80211_ATTR_SSID]);
3042 if (params.ssid_len == 0 ||
3043 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3044 return -EINVAL;
3045 }
3046
3047 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3048 params.hidden_ssid = nla_get_u32(
3049 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3050 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3051 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3052 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3053 return -EINVAL;
3054 }
3055
3056 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3057
3058 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3059 params.auth_type = nla_get_u32(
3060 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003061 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3062 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003063 return -EINVAL;
3064 } else
3065 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3066
3067 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3068 NL80211_MAX_NR_CIPHER_SUITES);
3069 if (err)
3070 return err;
3071
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303072 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3073 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3074 return -EOPNOTSUPP;
3075 params.inactivity_timeout = nla_get_u16(
3076 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3077 }
3078
Johannes Berg53cabad2012-11-14 15:17:28 +01003079 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3080 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3081 return -EINVAL;
3082 params.p2p_ctwindow =
3083 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3084 if (params.p2p_ctwindow > 127)
3085 return -EINVAL;
3086 if (params.p2p_ctwindow != 0 &&
3087 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3088 return -EINVAL;
3089 }
3090
3091 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3092 u8 tmp;
3093
3094 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3095 return -EINVAL;
3096 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3097 if (tmp > 1)
3098 return -EINVAL;
3099 params.p2p_opp_ps = tmp;
3100 if (params.p2p_opp_ps != 0 &&
3101 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3102 return -EINVAL;
3103 }
3104
Johannes Bergaa430da2012-05-16 23:50:18 +02003105 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003106 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3107 if (err)
3108 return err;
3109 } else if (wdev->preset_chandef.chan) {
3110 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003111 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003112 return -EINVAL;
3113
Johannes Berg683b6d32012-11-08 21:25:48 +01003114 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003115 return -EINVAL;
3116
Simon Wunderlich04f39042013-02-08 18:16:19 +01003117 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3118 if (err < 0)
3119 return err;
3120 if (err) {
3121 radar_detect_width = BIT(params.chandef.width);
3122 params.radar_required = true;
3123 }
3124
Simon Wunderlich04f39042013-02-08 18:16:19 +01003125 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3126 params.chandef.chan,
3127 CHAN_MODE_SHARED,
3128 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003129 if (err)
3130 return err;
3131
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303132 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3133 params.acl = parse_acl_data(&rdev->wiphy, info);
3134 if (IS_ERR(params.acl))
3135 return PTR_ERR(params.acl);
3136 }
3137
Hila Gonene35e4d22012-06-27 17:19:42 +03003138 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003139 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003140 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003141 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003142 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003143 wdev->ssid_len = params.ssid_len;
3144 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003145 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303146
3147 kfree(params.acl);
3148
Johannes Berg56d18932011-05-09 18:41:15 +02003149 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003150}
3151
Johannes Berg88600202012-02-13 15:17:18 +01003152static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3153{
3154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3155 struct net_device *dev = info->user_ptr[1];
3156 struct wireless_dev *wdev = dev->ieee80211_ptr;
3157 struct cfg80211_beacon_data params;
3158 int err;
3159
3160 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3161 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3162 return -EOPNOTSUPP;
3163
3164 if (!rdev->ops->change_beacon)
3165 return -EOPNOTSUPP;
3166
3167 if (!wdev->beacon_interval)
3168 return -EINVAL;
3169
3170 err = nl80211_parse_beacon(info, &params);
3171 if (err)
3172 return err;
3173
Hila Gonene35e4d22012-06-27 17:19:42 +03003174 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003175}
3176
3177static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003178{
Johannes Berg4c476992010-10-04 21:36:35 +02003179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3180 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003181
Michal Kazior60771782012-06-29 12:46:56 +02003182 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003183}
3184
Johannes Berg5727ef12007-12-19 02:03:34 +01003185static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3186 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3187 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3188 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003189 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003190 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003191 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003192};
3193
Johannes Bergeccb8e82009-05-11 21:57:56 +03003194static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003195 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003196 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003197{
3198 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003199 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003200 int flag;
3201
Johannes Bergeccb8e82009-05-11 21:57:56 +03003202 /*
3203 * Try parsing the new attribute first so userspace
3204 * can specify both for older kernels.
3205 */
3206 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3207 if (nla) {
3208 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003209
Johannes Bergeccb8e82009-05-11 21:57:56 +03003210 sta_flags = nla_data(nla);
3211 params->sta_flags_mask = sta_flags->mask;
3212 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003213 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003214 if ((params->sta_flags_mask |
3215 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3216 return -EINVAL;
3217 return 0;
3218 }
3219
3220 /* if present, parse the old attribute */
3221
3222 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003223 if (!nla)
3224 return 0;
3225
3226 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3227 nla, sta_flags_policy))
3228 return -EINVAL;
3229
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003230 /*
3231 * Only allow certain flags for interface types so that
3232 * other attributes are silently ignored. Remember that
3233 * this is backward compatibility code with old userspace
3234 * and shouldn't be hit in other cases anyway.
3235 */
3236 switch (iftype) {
3237 case NL80211_IFTYPE_AP:
3238 case NL80211_IFTYPE_AP_VLAN:
3239 case NL80211_IFTYPE_P2P_GO:
3240 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3241 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3242 BIT(NL80211_STA_FLAG_WME) |
3243 BIT(NL80211_STA_FLAG_MFP);
3244 break;
3245 case NL80211_IFTYPE_P2P_CLIENT:
3246 case NL80211_IFTYPE_STATION:
3247 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3248 BIT(NL80211_STA_FLAG_TDLS_PEER);
3249 break;
3250 case NL80211_IFTYPE_MESH_POINT:
3251 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3252 BIT(NL80211_STA_FLAG_MFP) |
3253 BIT(NL80211_STA_FLAG_AUTHORIZED);
3254 default:
3255 return -EINVAL;
3256 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003257
Johannes Berg3383b5a2012-05-10 20:14:43 +02003258 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3259 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003260 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003261
Johannes Berg3383b5a2012-05-10 20:14:43 +02003262 /* no longer support new API additions in old API */
3263 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3264 return -EINVAL;
3265 }
3266 }
3267
Johannes Berg5727ef12007-12-19 02:03:34 +01003268 return 0;
3269}
3270
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003271static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3272 int attr)
3273{
3274 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003275 u32 bitrate;
3276 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003277
3278 rate = nla_nest_start(msg, attr);
3279 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003280 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003281
3282 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3283 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003284 /* report 16-bit bitrate only if we can */
3285 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003286 if (bitrate > 0 &&
3287 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3288 return false;
3289 if (bitrate_compat > 0 &&
3290 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3291 return false;
3292
3293 if (info->flags & RATE_INFO_FLAGS_MCS) {
3294 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3295 return false;
3296 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3297 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3298 return false;
3299 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3300 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3301 return false;
3302 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3303 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3304 return false;
3305 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3306 return false;
3307 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3308 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3309 return false;
3310 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3311 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3312 return false;
3313 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3314 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3315 return false;
3316 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3317 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3318 return false;
3319 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3320 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3321 return false;
3322 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003323
3324 nla_nest_end(msg, rate);
3325 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003326}
3327
Felix Fietkau119363c2013-04-22 16:29:30 +02003328static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3329 int id)
3330{
3331 void *attr;
3332 int i = 0;
3333
3334 if (!mask)
3335 return true;
3336
3337 attr = nla_nest_start(msg, id);
3338 if (!attr)
3339 return false;
3340
3341 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3342 if (!(mask & BIT(i)))
3343 continue;
3344
3345 if (nla_put_u8(msg, i, signal[i]))
3346 return false;
3347 }
3348
3349 nla_nest_end(msg, attr);
3350
3351 return true;
3352}
3353
Eric W. Biederman15e47302012-09-07 20:12:54 +00003354static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003355 int flags,
3356 struct cfg80211_registered_device *rdev,
3357 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003358 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003359{
3360 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003361 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003362
Eric W. Biederman15e47302012-09-07 20:12:54 +00003363 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003364 if (!hdr)
3365 return -1;
3366
David S. Miller9360ffd2012-03-29 04:41:26 -04003367 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3368 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3369 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3370 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003371
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003372 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3373 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003374 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003375 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3376 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3377 sinfo->connected_time))
3378 goto nla_put_failure;
3379 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3380 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3381 sinfo->inactive_time))
3382 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003383 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3384 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003385 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003386 (u32)sinfo->rx_bytes))
3387 goto nla_put_failure;
3388 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003389 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003390 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3391 (u32)sinfo->tx_bytes))
3392 goto nla_put_failure;
3393 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3394 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003395 sinfo->rx_bytes))
3396 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003397 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3398 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003399 sinfo->tx_bytes))
3400 goto nla_put_failure;
3401 if ((sinfo->filled & STATION_INFO_LLID) &&
3402 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3403 goto nla_put_failure;
3404 if ((sinfo->filled & STATION_INFO_PLID) &&
3405 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3406 goto nla_put_failure;
3407 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3408 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3409 sinfo->plink_state))
3410 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003411 switch (rdev->wiphy.signal_type) {
3412 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003413 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3414 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3415 sinfo->signal))
3416 goto nla_put_failure;
3417 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3418 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3419 sinfo->signal_avg))
3420 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003421 break;
3422 default:
3423 break;
3424 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003425 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3426 if (!nl80211_put_signal(msg, sinfo->chains,
3427 sinfo->chain_signal,
3428 NL80211_STA_INFO_CHAIN_SIGNAL))
3429 goto nla_put_failure;
3430 }
3431 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3432 if (!nl80211_put_signal(msg, sinfo->chains,
3433 sinfo->chain_signal_avg,
3434 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3435 goto nla_put_failure;
3436 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003437 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003438 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3439 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003440 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003441 }
3442 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3443 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3444 NL80211_STA_INFO_RX_BITRATE))
3445 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003446 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003447 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3448 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3449 sinfo->rx_packets))
3450 goto nla_put_failure;
3451 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3452 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3453 sinfo->tx_packets))
3454 goto nla_put_failure;
3455 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3456 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3457 sinfo->tx_retries))
3458 goto nla_put_failure;
3459 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3460 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3461 sinfo->tx_failed))
3462 goto nla_put_failure;
3463 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3464 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3465 sinfo->beacon_loss_count))
3466 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003467 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3468 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3469 sinfo->local_pm))
3470 goto nla_put_failure;
3471 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3472 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3473 sinfo->peer_pm))
3474 goto nla_put_failure;
3475 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3476 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3477 sinfo->nonpeer_pm))
3478 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003479 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3480 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3481 if (!bss_param)
3482 goto nla_put_failure;
3483
David S. Miller9360ffd2012-03-29 04:41:26 -04003484 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3485 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3486 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3487 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3488 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3489 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3490 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3491 sinfo->bss_param.dtim_period) ||
3492 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3493 sinfo->bss_param.beacon_interval))
3494 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003495
3496 nla_nest_end(msg, bss_param);
3497 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003498 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3499 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3500 sizeof(struct nl80211_sta_flag_update),
3501 &sinfo->sta_flags))
3502 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003503 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3504 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3505 sinfo->t_offset))
3506 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003507 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003508
David S. Miller9360ffd2012-03-29 04:41:26 -04003509 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3510 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3511 sinfo->assoc_req_ies))
3512 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003513
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003514 return genlmsg_end(msg, hdr);
3515
3516 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003517 genlmsg_cancel(msg, hdr);
3518 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003519}
3520
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003521static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003522 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003523{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003524 struct station_info sinfo;
3525 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003526 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003527 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003528 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003529 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003530
Johannes Berg97990a02013-04-19 01:02:55 +02003531 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003532 if (err)
3533 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003534
Johannes Berg97990a02013-04-19 01:02:55 +02003535 if (!wdev->netdev) {
3536 err = -EINVAL;
3537 goto out_err;
3538 }
3539
Johannes Bergbba95fe2008-07-29 13:22:51 +02003540 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003541 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 goto out_err;
3543 }
3544
Johannes Bergbba95fe2008-07-29 13:22:51 +02003545 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003546 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003547 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003548 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003549 if (err == -ENOENT)
3550 break;
3551 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003552 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553
3554 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003555 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003556 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003557 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003558 &sinfo) < 0)
3559 goto out;
3560
3561 sta_idx++;
3562 }
3563
3564
3565 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003566 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003568 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003569 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003570
3571 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003572}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003573
Johannes Berg5727ef12007-12-19 02:03:34 +01003574static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3575{
Johannes Berg4c476992010-10-04 21:36:35 +02003576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3577 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003578 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579 struct sk_buff *msg;
3580 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003581 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003582
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003583 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584
3585 if (!info->attrs[NL80211_ATTR_MAC])
3586 return -EINVAL;
3587
3588 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3589
Johannes Berg4c476992010-10-04 21:36:35 +02003590 if (!rdev->ops->get_station)
3591 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003592
Hila Gonene35e4d22012-06-27 17:19:42 +03003593 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003594 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003595 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003596
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003598 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003599 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003600
Eric W. Biederman15e47302012-09-07 20:12:54 +00003601 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003602 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003603 nlmsg_free(msg);
3604 return -ENOBUFS;
3605 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003606
Johannes Berg4c476992010-10-04 21:36:35 +02003607 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003608}
3609
Johannes Berg77ee7c82013-02-15 00:48:33 +01003610int cfg80211_check_station_change(struct wiphy *wiphy,
3611 struct station_parameters *params,
3612 enum cfg80211_station_type statype)
3613{
3614 if (params->listen_interval != -1)
3615 return -EINVAL;
3616 if (params->aid)
3617 return -EINVAL;
3618
3619 /* When you run into this, adjust the code below for the new flag */
3620 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3621
3622 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003623 case CFG80211_STA_MESH_PEER_KERNEL:
3624 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003625 /*
3626 * No ignoring the TDLS flag here -- the userspace mesh
3627 * code doesn't have the bug of including TDLS in the
3628 * mask everywhere.
3629 */
3630 if (params->sta_flags_mask &
3631 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3632 BIT(NL80211_STA_FLAG_MFP) |
3633 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3634 return -EINVAL;
3635 break;
3636 case CFG80211_STA_TDLS_PEER_SETUP:
3637 case CFG80211_STA_TDLS_PEER_ACTIVE:
3638 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3639 return -EINVAL;
3640 /* ignore since it can't change */
3641 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3642 break;
3643 default:
3644 /* disallow mesh-specific things */
3645 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3646 return -EINVAL;
3647 if (params->local_pm)
3648 return -EINVAL;
3649 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3650 return -EINVAL;
3651 }
3652
3653 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3654 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3655 /* TDLS can't be set, ... */
3656 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3657 return -EINVAL;
3658 /*
3659 * ... but don't bother the driver with it. This works around
3660 * a hostapd/wpa_supplicant issue -- it always includes the
3661 * TLDS_PEER flag in the mask even for AP mode.
3662 */
3663 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3664 }
3665
3666 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3667 /* reject other things that can't change */
3668 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3669 return -EINVAL;
3670 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3671 return -EINVAL;
3672 if (params->supported_rates)
3673 return -EINVAL;
3674 if (params->ext_capab || params->ht_capa || params->vht_capa)
3675 return -EINVAL;
3676 }
3677
3678 if (statype != CFG80211_STA_AP_CLIENT) {
3679 if (params->vlan)
3680 return -EINVAL;
3681 }
3682
3683 switch (statype) {
3684 case CFG80211_STA_AP_MLME_CLIENT:
3685 /* Use this only for authorizing/unauthorizing a station */
3686 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3687 return -EOPNOTSUPP;
3688 break;
3689 case CFG80211_STA_AP_CLIENT:
3690 /* accept only the listed bits */
3691 if (params->sta_flags_mask &
3692 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3693 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3694 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3695 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3696 BIT(NL80211_STA_FLAG_WME) |
3697 BIT(NL80211_STA_FLAG_MFP)))
3698 return -EINVAL;
3699
3700 /* but authenticated/associated only if driver handles it */
3701 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3702 params->sta_flags_mask &
3703 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3704 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3705 return -EINVAL;
3706 break;
3707 case CFG80211_STA_IBSS:
3708 case CFG80211_STA_AP_STA:
3709 /* reject any changes other than AUTHORIZED */
3710 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3711 return -EINVAL;
3712 break;
3713 case CFG80211_STA_TDLS_PEER_SETUP:
3714 /* reject any changes other than AUTHORIZED or WME */
3715 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3716 BIT(NL80211_STA_FLAG_WME)))
3717 return -EINVAL;
3718 /* force (at least) rates when authorizing */
3719 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3720 !params->supported_rates)
3721 return -EINVAL;
3722 break;
3723 case CFG80211_STA_TDLS_PEER_ACTIVE:
3724 /* reject any changes */
3725 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003726 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003727 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3728 return -EINVAL;
3729 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003730 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003731 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3732 return -EINVAL;
3733 break;
3734 }
3735
3736 return 0;
3737}
3738EXPORT_SYMBOL(cfg80211_check_station_change);
3739
Johannes Berg5727ef12007-12-19 02:03:34 +01003740/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003741 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003742 */
Johannes Berg80b99892011-11-18 16:23:01 +01003743static struct net_device *get_vlan(struct genl_info *info,
3744 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003745{
Johannes Berg463d0182009-07-14 00:33:35 +02003746 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003747 struct net_device *v;
3748 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003749
Johannes Berg80b99892011-11-18 16:23:01 +01003750 if (!vlanattr)
3751 return NULL;
3752
3753 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3754 if (!v)
3755 return ERR_PTR(-ENODEV);
3756
3757 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3758 ret = -EINVAL;
3759 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003760 }
Johannes Berg80b99892011-11-18 16:23:01 +01003761
Johannes Berg77ee7c82013-02-15 00:48:33 +01003762 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3763 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3764 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3765 ret = -EINVAL;
3766 goto error;
3767 }
3768
Johannes Berg80b99892011-11-18 16:23:01 +01003769 if (!netif_running(v)) {
3770 ret = -ENETDOWN;
3771 goto error;
3772 }
3773
3774 return v;
3775 error:
3776 dev_put(v);
3777 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003778}
3779
Jouni Malinendf881292013-02-14 21:10:54 +02003780static struct nla_policy
3781nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3782 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3783 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3784};
3785
Johannes Bergff276692013-02-15 00:09:01 +01003786static int nl80211_parse_sta_wme(struct genl_info *info,
3787 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003788{
Jouni Malinendf881292013-02-14 21:10:54 +02003789 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3790 struct nlattr *nla;
3791 int err;
3792
Jouni Malinendf881292013-02-14 21:10:54 +02003793 /* parse WME attributes if present */
3794 if (!info->attrs[NL80211_ATTR_STA_WME])
3795 return 0;
3796
3797 nla = info->attrs[NL80211_ATTR_STA_WME];
3798 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3799 nl80211_sta_wme_policy);
3800 if (err)
3801 return err;
3802
3803 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3804 params->uapsd_queues = nla_get_u8(
3805 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3806 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3807 return -EINVAL;
3808
3809 if (tb[NL80211_STA_WME_MAX_SP])
3810 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3811
3812 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3813 return -EINVAL;
3814
3815 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3816
3817 return 0;
3818}
3819
Johannes Bergff276692013-02-15 00:09:01 +01003820static int nl80211_set_station_tdls(struct genl_info *info,
3821 struct station_parameters *params)
3822{
3823 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003824 if (info->attrs[NL80211_ATTR_PEER_AID])
3825 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003826 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3827 params->ht_capa =
3828 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3829 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3830 params->vht_capa =
3831 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3832
3833 return nl80211_parse_sta_wme(info, params);
3834}
3835
Johannes Berg5727ef12007-12-19 02:03:34 +01003836static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3837{
Johannes Berg4c476992010-10-04 21:36:35 +02003838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003839 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003840 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003841 u8 *mac_addr;
3842 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003843
3844 memset(&params, 0, sizeof(params));
3845
3846 params.listen_interval = -1;
3847
Johannes Berg77ee7c82013-02-15 00:48:33 +01003848 if (!rdev->ops->change_station)
3849 return -EOPNOTSUPP;
3850
Johannes Berg5727ef12007-12-19 02:03:34 +01003851 if (info->attrs[NL80211_ATTR_STA_AID])
3852 return -EINVAL;
3853
3854 if (!info->attrs[NL80211_ATTR_MAC])
3855 return -EINVAL;
3856
3857 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3858
3859 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3860 params.supported_rates =
3861 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3862 params.supported_rates_len =
3863 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3864 }
3865
Jouni Malinen9d62a982013-02-14 21:10:13 +02003866 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3867 params.capability =
3868 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3869 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3870 }
3871
3872 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3873 params.ext_capab =
3874 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3875 params.ext_capab_len =
3876 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3877 }
3878
Jouni Malinendf881292013-02-14 21:10:54 +02003879 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003880 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003881
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003882 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003883 return -EINVAL;
3884
Johannes Bergf8bacc22013-02-14 23:27:01 +01003885 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003887 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3888 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3889 return -EINVAL;
3890 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003891
Johannes Bergf8bacc22013-02-14 23:27:01 +01003892 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003893 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003894 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3895 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3896 return -EINVAL;
3897 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3898 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003899
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003900 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3901 enum nl80211_mesh_power_mode pm = nla_get_u32(
3902 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3903
3904 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3905 pm > NL80211_MESH_POWER_MAX)
3906 return -EINVAL;
3907
3908 params.local_pm = pm;
3909 }
3910
Johannes Berg77ee7c82013-02-15 00:48:33 +01003911 /* Include parameters for TDLS peer (will check later) */
3912 err = nl80211_set_station_tdls(info, &params);
3913 if (err)
3914 return err;
3915
3916 params.vlan = get_vlan(info, rdev);
3917 if (IS_ERR(params.vlan))
3918 return PTR_ERR(params.vlan);
3919
Johannes Berga97f4422009-06-18 17:23:43 +02003920 switch (dev->ieee80211_ptr->iftype) {
3921 case NL80211_IFTYPE_AP:
3922 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003923 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003924 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003925 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003926 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003927 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003928 break;
3929 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003930 err = -EOPNOTSUPP;
3931 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003932 }
3933
Johannes Berg77ee7c82013-02-15 00:48:33 +01003934 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003935 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003936
Johannes Berg77ee7c82013-02-15 00:48:33 +01003937 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003938 if (params.vlan)
3939 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003940
Johannes Berg5727ef12007-12-19 02:03:34 +01003941 return err;
3942}
3943
3944static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3945{
Johannes Berg4c476992010-10-04 21:36:35 +02003946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003947 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003948 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003949 struct station_parameters params;
3950 u8 *mac_addr = NULL;
3951
3952 memset(&params, 0, sizeof(params));
3953
Johannes Berg984c3112013-02-14 23:43:25 +01003954 if (!rdev->ops->add_station)
3955 return -EOPNOTSUPP;
3956
Johannes Berg5727ef12007-12-19 02:03:34 +01003957 if (!info->attrs[NL80211_ATTR_MAC])
3958 return -EINVAL;
3959
Johannes Berg5727ef12007-12-19 02:03:34 +01003960 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3961 return -EINVAL;
3962
3963 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3964 return -EINVAL;
3965
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003966 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3967 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003968 return -EINVAL;
3969
Johannes Berg5727ef12007-12-19 02:03:34 +01003970 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3971 params.supported_rates =
3972 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3973 params.supported_rates_len =
3974 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3975 params.listen_interval =
3976 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003977
Jouni Malinen3d124ea2013-05-27 18:24:02 +03003978 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003979 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03003980 else
3981 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003982 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3983 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003984
Jouni Malinen9d62a982013-02-14 21:10:13 +02003985 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3986 params.capability =
3987 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3988 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3989 }
3990
3991 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3992 params.ext_capab =
3993 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3994 params.ext_capab_len =
3995 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3996 }
3997
Jouni Malinen36aedc92008-08-25 11:58:58 +03003998 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3999 params.ht_capa =
4000 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004001
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004002 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4003 params.vht_capa =
4004 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4005
Johannes Bergf8bacc22013-02-14 23:27:01 +01004006 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004007 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 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004012
Johannes Bergff276692013-02-15 00:09:01 +01004013 err = nl80211_parse_sta_wme(info, &params);
4014 if (err)
4015 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004016
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004017 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004018 return -EINVAL;
4019
Johannes Berg77ee7c82013-02-15 00:48:33 +01004020 /* When you run into this, adjust the code below for the new flag */
4021 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4022
Johannes Bergbdd90d52011-12-14 12:20:27 +01004023 switch (dev->ieee80211_ptr->iftype) {
4024 case NL80211_IFTYPE_AP:
4025 case NL80211_IFTYPE_AP_VLAN:
4026 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004027 /* ignore WME attributes if iface/sta is not capable */
4028 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4029 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4030 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004031
Johannes Bergbdd90d52011-12-14 12:20:27 +01004032 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004033 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4034 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004035 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004036 /* but don't bother the driver with it */
4037 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004038
Johannes Bergd582cff2012-10-26 17:53:44 +02004039 /* allow authenticated/associated only if driver handles it */
4040 if (!(rdev->wiphy.features &
4041 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4042 params.sta_flags_mask &
4043 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4044 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4045 return -EINVAL;
4046
Johannes Bergbdd90d52011-12-14 12:20:27 +01004047 /* must be last in here for error handling */
4048 params.vlan = get_vlan(info, rdev);
4049 if (IS_ERR(params.vlan))
4050 return PTR_ERR(params.vlan);
4051 break;
4052 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004053 /* ignore uAPSD data */
4054 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4055
Johannes Bergd582cff2012-10-26 17:53:44 +02004056 /* associated is disallowed */
4057 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4058 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004059 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004060 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4061 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004062 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004063 break;
4064 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004065 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004066 /* ignore uAPSD data */
4067 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4068
Johannes Berg77ee7c82013-02-15 00:48:33 +01004069 /* these are disallowed */
4070 if (params.sta_flags_mask &
4071 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4072 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004073 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004074 /* Only TDLS peers can be added */
4075 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4076 return -EINVAL;
4077 /* Can only add if TDLS ... */
4078 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4079 return -EOPNOTSUPP;
4080 /* ... with external setup is supported */
4081 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4082 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004083 /*
4084 * Older wpa_supplicant versions always mark the TDLS peer
4085 * as authorized, but it shouldn't yet be.
4086 */
4087 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004088 break;
4089 default:
4090 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004091 }
4092
Johannes Bergbdd90d52011-12-14 12:20:27 +01004093 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004094
Hila Gonene35e4d22012-06-27 17:19:42 +03004095 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004096
Johannes Berg5727ef12007-12-19 02:03:34 +01004097 if (params.vlan)
4098 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004099 return err;
4100}
4101
4102static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4103{
Johannes Berg4c476992010-10-04 21:36:35 +02004104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4105 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004106 u8 *mac_addr = NULL;
4107
4108 if (info->attrs[NL80211_ATTR_MAC])
4109 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4110
Johannes Berge80cf852009-05-11 14:43:13 +02004111 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004112 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004113 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004114 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4115 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004116
Johannes Berg4c476992010-10-04 21:36:35 +02004117 if (!rdev->ops->del_station)
4118 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004119
Hila Gonene35e4d22012-06-27 17:19:42 +03004120 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004121}
4122
Eric W. Biederman15e47302012-09-07 20:12:54 +00004123static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004124 int flags, struct net_device *dev,
4125 u8 *dst, u8 *next_hop,
4126 struct mpath_info *pinfo)
4127{
4128 void *hdr;
4129 struct nlattr *pinfoattr;
4130
Eric W. Biederman15e47302012-09-07 20:12:54 +00004131 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004132 if (!hdr)
4133 return -1;
4134
David S. Miller9360ffd2012-03-29 04:41:26 -04004135 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4136 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4137 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4138 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4139 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004140
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004141 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4142 if (!pinfoattr)
4143 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004144 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4145 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4146 pinfo->frame_qlen))
4147 goto nla_put_failure;
4148 if (((pinfo->filled & MPATH_INFO_SN) &&
4149 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4150 ((pinfo->filled & MPATH_INFO_METRIC) &&
4151 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4152 pinfo->metric)) ||
4153 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4154 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4155 pinfo->exptime)) ||
4156 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4157 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4158 pinfo->flags)) ||
4159 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4160 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4161 pinfo->discovery_timeout)) ||
4162 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4163 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4164 pinfo->discovery_retries)))
4165 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004166
4167 nla_nest_end(msg, pinfoattr);
4168
4169 return genlmsg_end(msg, hdr);
4170
4171 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004172 genlmsg_cancel(msg, hdr);
4173 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174}
4175
4176static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004177 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004178{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004179 struct mpath_info pinfo;
4180 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004181 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004182 u8 dst[ETH_ALEN];
4183 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004184 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004185 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004186
Johannes Berg97990a02013-04-19 01:02:55 +02004187 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004188 if (err)
4189 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004190
4191 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004192 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004193 goto out_err;
4194 }
4195
Johannes Berg97990a02013-04-19 01:02:55 +02004196 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004197 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004198 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004199 }
4200
Johannes Bergbba95fe2008-07-29 13:22:51 +02004201 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004202 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4203 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004204 if (err == -ENOENT)
4205 break;
4206 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004207 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004208
Eric W. Biederman15e47302012-09-07 20:12:54 +00004209 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004210 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004211 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004212 &pinfo) < 0)
4213 goto out;
4214
4215 path_idx++;
4216 }
4217
4218
4219 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004220 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004221 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004222 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004223 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004224 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004225}
4226
4227static int nl80211_get_mpath(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];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004230 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004231 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004232 struct mpath_info pinfo;
4233 struct sk_buff *msg;
4234 u8 *dst = NULL;
4235 u8 next_hop[ETH_ALEN];
4236
4237 memset(&pinfo, 0, sizeof(pinfo));
4238
4239 if (!info->attrs[NL80211_ATTR_MAC])
4240 return -EINVAL;
4241
4242 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4243
Johannes Berg4c476992010-10-04 21:36:35 +02004244 if (!rdev->ops->get_mpath)
4245 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004246
Johannes Berg4c476992010-10-04 21:36:35 +02004247 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4248 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004249
Hila Gonene35e4d22012-06-27 17:19:42 +03004250 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004251 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004252 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004253
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004255 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004256 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004257
Eric W. Biederman15e47302012-09-07 20:12:54 +00004258 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004259 dev, dst, next_hop, &pinfo) < 0) {
4260 nlmsg_free(msg);
4261 return -ENOBUFS;
4262 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004263
Johannes Berg4c476992010-10-04 21:36:35 +02004264 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004265}
4266
4267static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4268{
Johannes Berg4c476992010-10-04 21:36:35 +02004269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4270 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004271 u8 *dst = NULL;
4272 u8 *next_hop = NULL;
4273
4274 if (!info->attrs[NL80211_ATTR_MAC])
4275 return -EINVAL;
4276
4277 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4278 return -EINVAL;
4279
4280 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4281 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4282
Johannes Berg4c476992010-10-04 21:36:35 +02004283 if (!rdev->ops->change_mpath)
4284 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004285
Johannes Berg4c476992010-10-04 21:36:35 +02004286 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4287 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004288
Hila Gonene35e4d22012-06-27 17:19:42 +03004289 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004290}
Johannes Berg4c476992010-10-04 21:36:35 +02004291
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004292static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4293{
Johannes Berg4c476992010-10-04 21:36:35 +02004294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4295 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004296 u8 *dst = NULL;
4297 u8 *next_hop = NULL;
4298
4299 if (!info->attrs[NL80211_ATTR_MAC])
4300 return -EINVAL;
4301
4302 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4303 return -EINVAL;
4304
4305 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4306 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4307
Johannes Berg4c476992010-10-04 21:36:35 +02004308 if (!rdev->ops->add_mpath)
4309 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004310
Johannes Berg4c476992010-10-04 21:36:35 +02004311 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4312 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004313
Hila Gonene35e4d22012-06-27 17:19:42 +03004314 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004315}
4316
4317static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4318{
Johannes Berg4c476992010-10-04 21:36:35 +02004319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4320 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004321 u8 *dst = NULL;
4322
4323 if (info->attrs[NL80211_ATTR_MAC])
4324 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4325
Johannes Berg4c476992010-10-04 21:36:35 +02004326 if (!rdev->ops->del_mpath)
4327 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004328
Hila Gonene35e4d22012-06-27 17:19:42 +03004329 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004330}
4331
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004332static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4333{
Johannes Berg4c476992010-10-04 21:36:35 +02004334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4335 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004336 struct bss_parameters params;
4337
4338 memset(&params, 0, sizeof(params));
4339 /* default to not changing parameters */
4340 params.use_cts_prot = -1;
4341 params.use_short_preamble = -1;
4342 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004343 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004344 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004345 params.p2p_ctwindow = -1;
4346 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004347
4348 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4349 params.use_cts_prot =
4350 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4351 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4352 params.use_short_preamble =
4353 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4354 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4355 params.use_short_slot_time =
4356 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004357 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4358 params.basic_rates =
4359 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4360 params.basic_rates_len =
4361 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4362 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004363 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4364 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004365 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4366 params.ht_opmode =
4367 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004368
Johannes Berg53cabad2012-11-14 15:17:28 +01004369 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4370 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4371 return -EINVAL;
4372 params.p2p_ctwindow =
4373 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4374 if (params.p2p_ctwindow < 0)
4375 return -EINVAL;
4376 if (params.p2p_ctwindow != 0 &&
4377 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4378 return -EINVAL;
4379 }
4380
4381 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4382 u8 tmp;
4383
4384 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4385 return -EINVAL;
4386 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4387 if (tmp > 1)
4388 return -EINVAL;
4389 params.p2p_opp_ps = tmp;
4390 if (params.p2p_opp_ps &&
4391 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4392 return -EINVAL;
4393 }
4394
Johannes Berg4c476992010-10-04 21:36:35 +02004395 if (!rdev->ops->change_bss)
4396 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004397
Johannes Berg074ac8d2010-09-16 14:58:22 +02004398 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004399 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4400 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004401
Hila Gonene35e4d22012-06-27 17:19:42 +03004402 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004403}
4404
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004405static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004406 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4407 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4408 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4409 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4410 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4411 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4412};
4413
4414static int parse_reg_rule(struct nlattr *tb[],
4415 struct ieee80211_reg_rule *reg_rule)
4416{
4417 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4418 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4419
4420 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4421 return -EINVAL;
4422 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4423 return -EINVAL;
4424 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4425 return -EINVAL;
4426 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4427 return -EINVAL;
4428 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4429 return -EINVAL;
4430
4431 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4432
4433 freq_range->start_freq_khz =
4434 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4435 freq_range->end_freq_khz =
4436 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4437 freq_range->max_bandwidth_khz =
4438 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4439
4440 power_rule->max_eirp =
4441 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4442
4443 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4444 power_rule->max_antenna_gain =
4445 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4446
4447 return 0;
4448}
4449
4450static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4451{
4452 int r;
4453 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004454 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004455
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004456 /*
4457 * You should only get this when cfg80211 hasn't yet initialized
4458 * completely when built-in to the kernel right between the time
4459 * window between nl80211_init() and regulatory_init(), if that is
4460 * even possible.
4461 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004462 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004463 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004464
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004465 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4466 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004467
4468 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4469
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004470 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4471 user_reg_hint_type =
4472 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4473 else
4474 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4475
4476 switch (user_reg_hint_type) {
4477 case NL80211_USER_REG_HINT_USER:
4478 case NL80211_USER_REG_HINT_CELL_BASE:
4479 break;
4480 default:
4481 return -EINVAL;
4482 }
4483
4484 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004485
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004486 return r;
4487}
4488
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004489static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004490 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004491{
Johannes Berg4c476992010-10-04 21:36:35 +02004492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004493 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004494 struct wireless_dev *wdev = dev->ieee80211_ptr;
4495 struct mesh_config cur_params;
4496 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004497 void *hdr;
4498 struct nlattr *pinfoattr;
4499 struct sk_buff *msg;
4500
Johannes Berg29cbe682010-12-03 09:20:44 +01004501 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4502 return -EOPNOTSUPP;
4503
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004504 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004505 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004506
Johannes Berg29cbe682010-12-03 09:20:44 +01004507 wdev_lock(wdev);
4508 /* If not connected, get default parameters */
4509 if (!wdev->mesh_id_len)
4510 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4511 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004512 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004513 wdev_unlock(wdev);
4514
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004515 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004516 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004517
4518 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004520 if (!msg)
4521 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004522 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004523 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004524 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004525 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004526 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004527 if (!pinfoattr)
4528 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004529 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4530 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4531 cur_params.dot11MeshRetryTimeout) ||
4532 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4533 cur_params.dot11MeshConfirmTimeout) ||
4534 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4535 cur_params.dot11MeshHoldingTimeout) ||
4536 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4537 cur_params.dot11MeshMaxPeerLinks) ||
4538 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4539 cur_params.dot11MeshMaxRetries) ||
4540 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4541 cur_params.dot11MeshTTL) ||
4542 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4543 cur_params.element_ttl) ||
4544 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4545 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004546 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4547 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004548 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4549 cur_params.dot11MeshHWMPmaxPREQretries) ||
4550 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4551 cur_params.path_refresh_time) ||
4552 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4553 cur_params.min_discovery_timeout) ||
4554 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4555 cur_params.dot11MeshHWMPactivePathTimeout) ||
4556 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4557 cur_params.dot11MeshHWMPpreqMinInterval) ||
4558 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4559 cur_params.dot11MeshHWMPperrMinInterval) ||
4560 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4561 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4562 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4563 cur_params.dot11MeshHWMPRootMode) ||
4564 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4565 cur_params.dot11MeshHWMPRannInterval) ||
4566 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4567 cur_params.dot11MeshGateAnnouncementProtocol) ||
4568 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4569 cur_params.dot11MeshForwarding) ||
4570 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004571 cur_params.rssi_threshold) ||
4572 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004573 cur_params.ht_opmode) ||
4574 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4575 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4576 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004577 cur_params.dot11MeshHWMProotInterval) ||
4578 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004579 cur_params.dot11MeshHWMPconfirmationInterval) ||
4580 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4581 cur_params.power_mode) ||
4582 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004583 cur_params.dot11MeshAwakeWindowDuration) ||
4584 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4585 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004586 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587 nla_nest_end(msg, pinfoattr);
4588 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004589 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004590
Johannes Berg3b858752009-03-12 09:55:09 +01004591 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004592 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004593 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004594 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004595 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004596}
4597
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004598static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004599 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4600 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4601 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4602 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4603 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4604 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004605 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004606 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004607 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004608 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4609 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4610 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4611 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4612 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004613 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004614 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004615 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004616 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004617 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004618 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004619 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4620 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004621 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4622 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004623 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004624 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4625 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004626 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004627};
4628
Javier Cardonac80d5452010-12-16 17:37:49 -08004629static const struct nla_policy
4630 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004631 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004632 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4633 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004634 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004635 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004636 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004637 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004638 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004639 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004640};
4641
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004642static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004643 struct mesh_config *cfg,
4644 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004645{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004646 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004647 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004648
Marco Porschea54fba2013-01-07 16:04:48 +01004649#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4650do { \
4651 if (tb[attr]) { \
4652 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4653 return -EINVAL; \
4654 cfg->param = fn(tb[attr]); \
4655 mask |= (1 << (attr - 1)); \
4656 } \
4657} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004658
4659
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004660 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004661 return -EINVAL;
4662 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004663 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004664 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004665 return -EINVAL;
4666
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004667 /* This makes sure that there aren't more than 32 mesh config
4668 * parameters (otherwise our bitfield scheme would not work.) */
4669 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4670
4671 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004672 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4674 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004676 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4677 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004678 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004679 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4680 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4683 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_MAX_RETRIES,
4686 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004688 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004689 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004690 mask, NL80211_MESHCONF_ELEMENT_TTL,
4691 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004692 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004693 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4694 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004695 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4696 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004697 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4698 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004699 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004700 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4701 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004702 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004703 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4704 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004705 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004706 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4707 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4709 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004710 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4711 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004713 1, 65535, mask,
4714 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004715 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004717 1, 65535, mask,
4718 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004719 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004721 dot11MeshHWMPnetDiameterTraversalTime,
4722 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004723 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4724 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004725 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4726 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4727 nla_get_u8);
4728 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4729 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004730 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004731 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004732 dot11MeshGateAnnouncementProtocol, 0, 1,
4733 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004734 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004735 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004736 mask, NL80211_MESHCONF_FORWARDING,
4737 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004738 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004739 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4740 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004741 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004742 mask, NL80211_MESHCONF_HT_OPMODE,
4743 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004744 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004745 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004746 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4747 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004749 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4750 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004752 dot11MeshHWMPconfirmationInterval,
4753 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004754 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4755 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004756 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4757 NL80211_MESH_POWER_ACTIVE,
4758 NL80211_MESH_POWER_MAX,
4759 mask, NL80211_MESHCONF_POWER_MODE,
4760 nla_get_u32);
4761 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4762 0, 65535, mask,
4763 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004764 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4765 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4766 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004767 if (mask_out)
4768 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004769
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004770 return 0;
4771
4772#undef FILL_IN_MESH_PARAM_IF_SET
4773}
4774
Javier Cardonac80d5452010-12-16 17:37:49 -08004775static int nl80211_parse_mesh_setup(struct genl_info *info,
4776 struct mesh_setup *setup)
4777{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004779 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4780
4781 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4782 return -EINVAL;
4783 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4784 info->attrs[NL80211_ATTR_MESH_SETUP],
4785 nl80211_mesh_setup_params_policy))
4786 return -EINVAL;
4787
Javier Cardonad299a1f2012-03-31 11:31:33 -07004788 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4789 setup->sync_method =
4790 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4791 IEEE80211_SYNC_METHOD_VENDOR :
4792 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4793
Javier Cardonac80d5452010-12-16 17:37:49 -08004794 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4795 setup->path_sel_proto =
4796 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4797 IEEE80211_PATH_PROTOCOL_VENDOR :
4798 IEEE80211_PATH_PROTOCOL_HWMP;
4799
4800 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4801 setup->path_metric =
4802 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4803 IEEE80211_PATH_METRIC_VENDOR :
4804 IEEE80211_PATH_METRIC_AIRTIME;
4805
Javier Cardona581a8b02011-04-07 15:08:27 -07004806
4807 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004808 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004809 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004810 if (!is_valid_ie_attr(ieattr))
4811 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004812 setup->ie = nla_data(ieattr);
4813 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004814 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004815 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4816 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4817 return -EINVAL;
4818 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004819 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4820 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004821 if (setup->is_secure)
4822 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004823
Colleen Twitty6e16d902013-05-08 11:45:59 -07004824 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4825 if (!setup->user_mpm)
4826 return -EINVAL;
4827 setup->auth_id =
4828 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4829 }
4830
Javier Cardonac80d5452010-12-16 17:37:49 -08004831 return 0;
4832}
4833
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004834static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004835 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004836{
4837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4838 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004839 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840 struct mesh_config cfg;
4841 u32 mask;
4842 int err;
4843
Johannes Berg29cbe682010-12-03 09:20:44 +01004844 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4845 return -EOPNOTSUPP;
4846
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004847 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004848 return -EOPNOTSUPP;
4849
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004850 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004851 if (err)
4852 return err;
4853
Johannes Berg29cbe682010-12-03 09:20:44 +01004854 wdev_lock(wdev);
4855 if (!wdev->mesh_id_len)
4856 err = -ENOLINK;
4857
4858 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004859 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004860
4861 wdev_unlock(wdev);
4862
4863 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004864}
4865
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004866static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4867{
Johannes Berg458f4f92012-12-06 15:47:38 +01004868 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004869 struct sk_buff *msg;
4870 void *hdr = NULL;
4871 struct nlattr *nl_reg_rules;
4872 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004873
4874 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004875 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004876
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004877 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004878 if (!msg)
4879 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004880
Eric W. Biederman15e47302012-09-07 20:12:54 +00004881 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004882 NL80211_CMD_GET_REG);
4883 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004884 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004885
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004886 if (reg_last_request_cell_base() &&
4887 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4888 NL80211_USER_REG_HINT_CELL_BASE))
4889 goto nla_put_failure;
4890
Johannes Berg458f4f92012-12-06 15:47:38 +01004891 rcu_read_lock();
4892 regdom = rcu_dereference(cfg80211_regdomain);
4893
4894 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4895 (regdom->dfs_region &&
4896 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4897 goto nla_put_failure_rcu;
4898
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004899 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4900 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004901 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004902
Johannes Berg458f4f92012-12-06 15:47:38 +01004903 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004904 struct nlattr *nl_reg_rule;
4905 const struct ieee80211_reg_rule *reg_rule;
4906 const struct ieee80211_freq_range *freq_range;
4907 const struct ieee80211_power_rule *power_rule;
4908
Johannes Berg458f4f92012-12-06 15:47:38 +01004909 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004910 freq_range = &reg_rule->freq_range;
4911 power_rule = &reg_rule->power_rule;
4912
4913 nl_reg_rule = nla_nest_start(msg, i);
4914 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004915 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004916
David S. Miller9360ffd2012-03-29 04:41:26 -04004917 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4918 reg_rule->flags) ||
4919 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4920 freq_range->start_freq_khz) ||
4921 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4922 freq_range->end_freq_khz) ||
4923 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4924 freq_range->max_bandwidth_khz) ||
4925 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4926 power_rule->max_antenna_gain) ||
4927 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4928 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004929 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004930
4931 nla_nest_end(msg, nl_reg_rule);
4932 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004933 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004934
4935 nla_nest_end(msg, nl_reg_rules);
4936
4937 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004938 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939
Johannes Berg458f4f92012-12-06 15:47:38 +01004940nla_put_failure_rcu:
4941 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004942nla_put_failure:
4943 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004944put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004945 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004946 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004947}
4948
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004949static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4950{
4951 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4952 struct nlattr *nl_reg_rule;
4953 char *alpha2 = NULL;
4954 int rem_reg_rules = 0, r = 0;
4955 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004956 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004957 struct ieee80211_regdomain *rd = NULL;
4958
4959 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4960 return -EINVAL;
4961
4962 if (!info->attrs[NL80211_ATTR_REG_RULES])
4963 return -EINVAL;
4964
4965 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4966
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004967 if (info->attrs[NL80211_ATTR_DFS_REGION])
4968 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4969
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004970 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004971 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 num_rules++;
4973 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004974 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004975 }
4976
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004977 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004978 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004979
4980 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004981 if (!rd)
4982 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004983
4984 rd->n_reg_rules = num_rules;
4985 rd->alpha2[0] = alpha2[0];
4986 rd->alpha2[1] = alpha2[1];
4987
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004988 /*
4989 * Disable DFS master mode if the DFS region was
4990 * not supported or known on this kernel.
4991 */
4992 if (reg_supported_dfs_region(dfs_region))
4993 rd->dfs_region = dfs_region;
4994
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004995 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004996 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004997 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004998 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4999 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005000 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5001 if (r)
5002 goto bad_reg;
5003
5004 rule_idx++;
5005
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005006 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5007 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005008 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005009 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005010 }
5011
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005012 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005013 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005014 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005015
Johannes Bergd2372b32008-10-24 20:32:20 +02005016 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005017 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005018 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005019}
5020
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005021static int validate_scan_freqs(struct nlattr *freqs)
5022{
5023 struct nlattr *attr1, *attr2;
5024 int n_channels = 0, tmp1, tmp2;
5025
5026 nla_for_each_nested(attr1, freqs, tmp1) {
5027 n_channels++;
5028 /*
5029 * Some hardware has a limited channel list for
5030 * scanning, and it is pretty much nonsensical
5031 * to scan for a channel twice, so disallow that
5032 * and don't require drivers to check that the
5033 * channel list they get isn't longer than what
5034 * they can scan, as long as they can scan all
5035 * the channels they registered at once.
5036 */
5037 nla_for_each_nested(attr2, freqs, tmp2)
5038 if (attr1 != attr2 &&
5039 nla_get_u32(attr1) == nla_get_u32(attr2))
5040 return 0;
5041 }
5042
5043 return n_channels;
5044}
5045
Johannes Berg2a519312009-02-10 21:25:55 +01005046static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5047{
Johannes Berg4c476992010-10-04 21:36:35 +02005048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005049 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005050 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005051 struct nlattr *attr;
5052 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005053 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005054 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005055
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005056 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5057 return -EINVAL;
5058
Johannes Berg79c97e92009-07-07 03:56:12 +02005059 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005060
Johannes Berg4c476992010-10-04 21:36:35 +02005061 if (!rdev->ops->scan)
5062 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005063
Johannes Bergf9f47522013-03-19 15:04:07 +01005064 if (rdev->scan_req) {
5065 err = -EBUSY;
5066 goto unlock;
5067 }
Johannes Berg2a519312009-02-10 21:25:55 +01005068
5069 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005070 n_channels = validate_scan_freqs(
5071 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005072 if (!n_channels) {
5073 err = -EINVAL;
5074 goto unlock;
5075 }
Johannes Berg2a519312009-02-10 21:25:55 +01005076 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005077 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005078 n_channels = 0;
5079
Johannes Berg2a519312009-02-10 21:25:55 +01005080 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5081 if (wiphy->bands[band])
5082 n_channels += wiphy->bands[band]->n_channels;
5083 }
5084
5085 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5086 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5087 n_ssids++;
5088
Johannes Bergf9f47522013-03-19 15:04:07 +01005089 if (n_ssids > wiphy->max_scan_ssids) {
5090 err = -EINVAL;
5091 goto unlock;
5092 }
Johannes Berg2a519312009-02-10 21:25:55 +01005093
Jouni Malinen70692ad2009-02-16 19:39:13 +02005094 if (info->attrs[NL80211_ATTR_IE])
5095 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5096 else
5097 ie_len = 0;
5098
Johannes Bergf9f47522013-03-19 15:04:07 +01005099 if (ie_len > wiphy->max_scan_ie_len) {
5100 err = -EINVAL;
5101 goto unlock;
5102 }
Johannes Berg18a83652009-03-31 12:12:05 +02005103
Johannes Berg2a519312009-02-10 21:25:55 +01005104 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005105 + sizeof(*request->ssids) * n_ssids
5106 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005107 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005108 if (!request) {
5109 err = -ENOMEM;
5110 goto unlock;
5111 }
Johannes Berg2a519312009-02-10 21:25:55 +01005112
Johannes Berg2a519312009-02-10 21:25:55 +01005113 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005114 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005115 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005116 if (ie_len) {
5117 if (request->ssids)
5118 request->ie = (void *)(request->ssids + n_ssids);
5119 else
5120 request->ie = (void *)(request->channels + n_channels);
5121 }
Johannes Berg2a519312009-02-10 21:25:55 +01005122
Johannes Berg584991d2009-11-02 13:32:03 +01005123 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005124 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5125 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005126 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005127 struct ieee80211_channel *chan;
5128
5129 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5130
5131 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005132 err = -EINVAL;
5133 goto out_free;
5134 }
Johannes Berg584991d2009-11-02 13:32:03 +01005135
5136 /* ignore disabled channels */
5137 if (chan->flags & IEEE80211_CHAN_DISABLED)
5138 continue;
5139
5140 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005141 i++;
5142 }
5143 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005144 enum ieee80211_band band;
5145
Johannes Berg2a519312009-02-10 21:25:55 +01005146 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005147 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5148 int j;
5149 if (!wiphy->bands[band])
5150 continue;
5151 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005152 struct ieee80211_channel *chan;
5153
5154 chan = &wiphy->bands[band]->channels[j];
5155
5156 if (chan->flags & IEEE80211_CHAN_DISABLED)
5157 continue;
5158
5159 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005160 i++;
5161 }
5162 }
5163 }
5164
Johannes Berg584991d2009-11-02 13:32:03 +01005165 if (!i) {
5166 err = -EINVAL;
5167 goto out_free;
5168 }
5169
5170 request->n_channels = i;
5171
Johannes Berg2a519312009-02-10 21:25:55 +01005172 i = 0;
5173 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5174 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005175 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005176 err = -EINVAL;
5177 goto out_free;
5178 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005179 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005180 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005181 i++;
5182 }
5183 }
5184
Jouni Malinen70692ad2009-02-16 19:39:13 +02005185 if (info->attrs[NL80211_ATTR_IE]) {
5186 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005187 memcpy((void *)request->ie,
5188 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005189 request->ie_len);
5190 }
5191
Johannes Berg34850ab2011-07-18 18:08:35 +02005192 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005193 if (wiphy->bands[i])
5194 request->rates[i] =
5195 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005196
5197 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5198 nla_for_each_nested(attr,
5199 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5200 tmp) {
5201 enum ieee80211_band band = nla_type(attr);
5202
Dan Carpenter84404622011-07-29 11:52:18 +03005203 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005204 err = -EINVAL;
5205 goto out_free;
5206 }
5207 err = ieee80211_get_ratemask(wiphy->bands[band],
5208 nla_data(attr),
5209 nla_len(attr),
5210 &request->rates[band]);
5211 if (err)
5212 goto out_free;
5213 }
5214 }
5215
Sam Leffler46856bb2012-10-11 21:03:32 -07005216 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005217 request->flags = nla_get_u32(
5218 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005219 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5220 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5221 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5222 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005223 err = -EOPNOTSUPP;
5224 goto out_free;
5225 }
5226 }
Sam Lefflered4737712012-10-11 21:03:31 -07005227
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305228 request->no_cck =
5229 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5230
Johannes Bergfd014282012-06-18 19:17:03 +02005231 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005232 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005233 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005234
Johannes Berg79c97e92009-07-07 03:56:12 +02005235 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005236 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005237
Johannes Berg463d0182009-07-14 00:33:35 +02005238 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005239 nl80211_send_scan_start(rdev, wdev);
5240 if (wdev->netdev)
5241 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005242 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005243 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005244 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005245 kfree(request);
5246 }
Johannes Berg3b858752009-03-12 09:55:09 +01005247
Johannes Bergf9f47522013-03-19 15:04:07 +01005248 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005249 return err;
5250}
5251
Luciano Coelho807f8a82011-05-11 17:09:35 +03005252static int nl80211_start_sched_scan(struct sk_buff *skb,
5253 struct genl_info *info)
5254{
5255 struct cfg80211_sched_scan_request *request;
5256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5257 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005258 struct nlattr *attr;
5259 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005260 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005261 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005262 enum ieee80211_band band;
5263 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005264 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005265
5266 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5267 !rdev->ops->sched_scan_start)
5268 return -EOPNOTSUPP;
5269
5270 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5271 return -EINVAL;
5272
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005273 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5274 return -EINVAL;
5275
5276 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5277 if (interval == 0)
5278 return -EINVAL;
5279
Luciano Coelho807f8a82011-05-11 17:09:35 +03005280 wiphy = &rdev->wiphy;
5281
5282 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5283 n_channels = validate_scan_freqs(
5284 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5285 if (!n_channels)
5286 return -EINVAL;
5287 } else {
5288 n_channels = 0;
5289
5290 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5291 if (wiphy->bands[band])
5292 n_channels += wiphy->bands[band]->n_channels;
5293 }
5294
5295 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5296 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5297 tmp)
5298 n_ssids++;
5299
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005300 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005301 return -EINVAL;
5302
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005303 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5304 nla_for_each_nested(attr,
5305 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5306 tmp)
5307 n_match_sets++;
5308
5309 if (n_match_sets > wiphy->max_match_sets)
5310 return -EINVAL;
5311
Luciano Coelho807f8a82011-05-11 17:09:35 +03005312 if (info->attrs[NL80211_ATTR_IE])
5313 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5314 else
5315 ie_len = 0;
5316
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005317 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005318 return -EINVAL;
5319
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005320 if (rdev->sched_scan_req) {
5321 err = -EINPROGRESS;
5322 goto out;
5323 }
5324
Luciano Coelho807f8a82011-05-11 17:09:35 +03005325 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005326 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005327 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005328 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005329 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005330 if (!request) {
5331 err = -ENOMEM;
5332 goto out;
5333 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005334
5335 if (n_ssids)
5336 request->ssids = (void *)&request->channels[n_channels];
5337 request->n_ssids = n_ssids;
5338 if (ie_len) {
5339 if (request->ssids)
5340 request->ie = (void *)(request->ssids + n_ssids);
5341 else
5342 request->ie = (void *)(request->channels + n_channels);
5343 }
5344
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005345 if (n_match_sets) {
5346 if (request->ie)
5347 request->match_sets = (void *)(request->ie + ie_len);
5348 else if (request->ssids)
5349 request->match_sets =
5350 (void *)(request->ssids + n_ssids);
5351 else
5352 request->match_sets =
5353 (void *)(request->channels + n_channels);
5354 }
5355 request->n_match_sets = n_match_sets;
5356
Luciano Coelho807f8a82011-05-11 17:09:35 +03005357 i = 0;
5358 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5359 /* user specified, bail out if channel not found */
5360 nla_for_each_nested(attr,
5361 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5362 tmp) {
5363 struct ieee80211_channel *chan;
5364
5365 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5366
5367 if (!chan) {
5368 err = -EINVAL;
5369 goto out_free;
5370 }
5371
5372 /* ignore disabled channels */
5373 if (chan->flags & IEEE80211_CHAN_DISABLED)
5374 continue;
5375
5376 request->channels[i] = chan;
5377 i++;
5378 }
5379 } else {
5380 /* all channels */
5381 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5382 int j;
5383 if (!wiphy->bands[band])
5384 continue;
5385 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5386 struct ieee80211_channel *chan;
5387
5388 chan = &wiphy->bands[band]->channels[j];
5389
5390 if (chan->flags & IEEE80211_CHAN_DISABLED)
5391 continue;
5392
5393 request->channels[i] = chan;
5394 i++;
5395 }
5396 }
5397 }
5398
5399 if (!i) {
5400 err = -EINVAL;
5401 goto out_free;
5402 }
5403
5404 request->n_channels = i;
5405
5406 i = 0;
5407 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5408 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5409 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005410 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005411 err = -EINVAL;
5412 goto out_free;
5413 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005414 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005415 memcpy(request->ssids[i].ssid, nla_data(attr),
5416 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005417 i++;
5418 }
5419 }
5420
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005421 i = 0;
5422 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5423 nla_for_each_nested(attr,
5424 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5425 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005426 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005427
5428 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5429 nla_data(attr), nla_len(attr),
5430 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005431 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005432 if (ssid) {
5433 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5434 err = -EINVAL;
5435 goto out_free;
5436 }
5437 memcpy(request->match_sets[i].ssid.ssid,
5438 nla_data(ssid), nla_len(ssid));
5439 request->match_sets[i].ssid.ssid_len =
5440 nla_len(ssid);
5441 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005442 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5443 if (rssi)
5444 request->rssi_thold = nla_get_u32(rssi);
5445 else
5446 request->rssi_thold =
5447 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005448 i++;
5449 }
5450 }
5451
Luciano Coelho807f8a82011-05-11 17:09:35 +03005452 if (info->attrs[NL80211_ATTR_IE]) {
5453 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5454 memcpy((void *)request->ie,
5455 nla_data(info->attrs[NL80211_ATTR_IE]),
5456 request->ie_len);
5457 }
5458
Sam Leffler46856bb2012-10-11 21:03:32 -07005459 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005460 request->flags = nla_get_u32(
5461 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005462 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5463 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5464 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5465 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005466 err = -EOPNOTSUPP;
5467 goto out_free;
5468 }
5469 }
Sam Lefflered4737712012-10-11 21:03:31 -07005470
Luciano Coelho807f8a82011-05-11 17:09:35 +03005471 request->dev = dev;
5472 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005473 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005474 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005475
Hila Gonene35e4d22012-06-27 17:19:42 +03005476 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005477 if (!err) {
5478 rdev->sched_scan_req = request;
5479 nl80211_send_sched_scan(rdev, dev,
5480 NL80211_CMD_START_SCHED_SCAN);
5481 goto out;
5482 }
5483
5484out_free:
5485 kfree(request);
5486out:
5487 return err;
5488}
5489
5490static int nl80211_stop_sched_scan(struct sk_buff *skb,
5491 struct genl_info *info)
5492{
5493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5494
5495 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5496 !rdev->ops->sched_scan_stop)
5497 return -EOPNOTSUPP;
5498
Johannes Berg5fe231e2013-05-08 21:45:15 +02005499 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005500}
5501
Simon Wunderlich04f39042013-02-08 18:16:19 +01005502static int nl80211_start_radar_detection(struct sk_buff *skb,
5503 struct genl_info *info)
5504{
5505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5506 struct net_device *dev = info->user_ptr[1];
5507 struct wireless_dev *wdev = dev->ieee80211_ptr;
5508 struct cfg80211_chan_def chandef;
5509 int err;
5510
5511 err = nl80211_parse_chandef(rdev, info, &chandef);
5512 if (err)
5513 return err;
5514
5515 if (wdev->cac_started)
5516 return -EBUSY;
5517
5518 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5519 if (err < 0)
5520 return err;
5521
5522 if (err == 0)
5523 return -EINVAL;
5524
5525 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5526 return -EINVAL;
5527
5528 if (!rdev->ops->start_radar_detection)
5529 return -EOPNOTSUPP;
5530
Simon Wunderlich04f39042013-02-08 18:16:19 +01005531 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5532 chandef.chan, CHAN_MODE_SHARED,
5533 BIT(chandef.width));
5534 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005535 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005536
5537 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5538 if (!err) {
5539 wdev->channel = chandef.chan;
5540 wdev->cac_started = true;
5541 wdev->cac_start_time = jiffies;
5542 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005543 return err;
5544}
5545
Johannes Berg9720bb32011-06-21 09:45:33 +02005546static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5547 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005548 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005549 struct wireless_dev *wdev,
5550 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005551{
Johannes Berg48ab9052009-07-10 18:42:31 +02005552 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005553 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005554 void *hdr;
5555 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005556 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005557
5558 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005559
Eric W. Biederman15e47302012-09-07 20:12:54 +00005560 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005561 NL80211_CMD_NEW_SCAN_RESULTS);
5562 if (!hdr)
5563 return -1;
5564
Johannes Berg9720bb32011-06-21 09:45:33 +02005565 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5566
Johannes Berg97990a02013-04-19 01:02:55 +02005567 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5568 goto nla_put_failure;
5569 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005570 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5571 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005572 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5573 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005574
5575 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5576 if (!bss)
5577 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005578 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005579 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005580 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005581
5582 rcu_read_lock();
5583 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005584 if (ies) {
5585 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5586 goto fail_unlock_rcu;
5587 tsf = true;
5588 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5589 ies->len, ies->data))
5590 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005591 }
5592 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005593 if (ies) {
5594 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5595 goto fail_unlock_rcu;
5596 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5597 ies->len, ies->data))
5598 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005599 }
5600 rcu_read_unlock();
5601
David S. Miller9360ffd2012-03-29 04:41:26 -04005602 if (res->beacon_interval &&
5603 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5604 goto nla_put_failure;
5605 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5606 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5607 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5608 jiffies_to_msecs(jiffies - intbss->ts)))
5609 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005610
Johannes Berg77965c92009-02-18 18:45:06 +01005611 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005612 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005613 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5614 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005615 break;
5616 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005617 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5618 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005619 break;
5620 default:
5621 break;
5622 }
5623
Johannes Berg48ab9052009-07-10 18:42:31 +02005624 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005625 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005626 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005627 if (intbss == wdev->current_bss &&
5628 nla_put_u32(msg, NL80211_BSS_STATUS,
5629 NL80211_BSS_STATUS_ASSOCIATED))
5630 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005631 break;
5632 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005633 if (intbss == wdev->current_bss &&
5634 nla_put_u32(msg, NL80211_BSS_STATUS,
5635 NL80211_BSS_STATUS_IBSS_JOINED))
5636 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005637 break;
5638 default:
5639 break;
5640 }
5641
Johannes Berg2a519312009-02-10 21:25:55 +01005642 nla_nest_end(msg, bss);
5643
5644 return genlmsg_end(msg, hdr);
5645
Johannes Berg8cef2c92013-02-05 16:54:31 +01005646 fail_unlock_rcu:
5647 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005648 nla_put_failure:
5649 genlmsg_cancel(msg, hdr);
5650 return -EMSGSIZE;
5651}
5652
Johannes Berg97990a02013-04-19 01:02:55 +02005653static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005654{
Johannes Berg48ab9052009-07-10 18:42:31 +02005655 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005656 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005657 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005658 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005659 int err;
5660
Johannes Berg97990a02013-04-19 01:02:55 +02005661 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005662 if (err)
5663 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005664
Johannes Berg48ab9052009-07-10 18:42:31 +02005665 wdev_lock(wdev);
5666 spin_lock_bh(&rdev->bss_lock);
5667 cfg80211_bss_expire(rdev);
5668
Johannes Berg9720bb32011-06-21 09:45:33 +02005669 cb->seq = rdev->bss_generation;
5670
Johannes Berg48ab9052009-07-10 18:42:31 +02005671 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005672 if (++idx <= start)
5673 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005674 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005675 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005676 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005677 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005678 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005679 }
5680 }
5681
Johannes Berg48ab9052009-07-10 18:42:31 +02005682 spin_unlock_bh(&rdev->bss_lock);
5683 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005684
Johannes Berg97990a02013-04-19 01:02:55 +02005685 cb->args[2] = idx;
5686 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005687
Johannes Berg67748892010-10-04 21:14:06 +02005688 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005689}
5690
Eric W. Biederman15e47302012-09-07 20:12:54 +00005691static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005692 int flags, struct net_device *dev,
5693 struct survey_info *survey)
5694{
5695 void *hdr;
5696 struct nlattr *infoattr;
5697
Eric W. Biederman15e47302012-09-07 20:12:54 +00005698 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005699 NL80211_CMD_NEW_SURVEY_RESULTS);
5700 if (!hdr)
5701 return -ENOMEM;
5702
David S. Miller9360ffd2012-03-29 04:41:26 -04005703 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5704 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005705
5706 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5707 if (!infoattr)
5708 goto nla_put_failure;
5709
David S. Miller9360ffd2012-03-29 04:41:26 -04005710 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5711 survey->channel->center_freq))
5712 goto nla_put_failure;
5713
5714 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5715 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5716 goto nla_put_failure;
5717 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5718 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5719 goto nla_put_failure;
5720 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5721 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5722 survey->channel_time))
5723 goto nla_put_failure;
5724 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5725 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5726 survey->channel_time_busy))
5727 goto nla_put_failure;
5728 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5729 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5730 survey->channel_time_ext_busy))
5731 goto nla_put_failure;
5732 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5733 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5734 survey->channel_time_rx))
5735 goto nla_put_failure;
5736 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5737 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5738 survey->channel_time_tx))
5739 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005740
5741 nla_nest_end(msg, infoattr);
5742
5743 return genlmsg_end(msg, hdr);
5744
5745 nla_put_failure:
5746 genlmsg_cancel(msg, hdr);
5747 return -EMSGSIZE;
5748}
5749
5750static int nl80211_dump_survey(struct sk_buff *skb,
5751 struct netlink_callback *cb)
5752{
5753 struct survey_info survey;
5754 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005755 struct wireless_dev *wdev;
5756 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005757 int res;
5758
Johannes Berg97990a02013-04-19 01:02:55 +02005759 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005760 if (res)
5761 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005762
Johannes Berg97990a02013-04-19 01:02:55 +02005763 if (!wdev->netdev) {
5764 res = -EINVAL;
5765 goto out_err;
5766 }
5767
Holger Schurig61fa7132009-11-11 12:25:40 +01005768 if (!dev->ops->dump_survey) {
5769 res = -EOPNOTSUPP;
5770 goto out_err;
5771 }
5772
5773 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005774 struct ieee80211_channel *chan;
5775
Johannes Berg97990a02013-04-19 01:02:55 +02005776 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005777 if (res == -ENOENT)
5778 break;
5779 if (res)
5780 goto out_err;
5781
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005782 /* Survey without a channel doesn't make sense */
5783 if (!survey.channel) {
5784 res = -EINVAL;
5785 goto out;
5786 }
5787
5788 chan = ieee80211_get_channel(&dev->wiphy,
5789 survey.channel->center_freq);
5790 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5791 survey_idx++;
5792 continue;
5793 }
5794
Holger Schurig61fa7132009-11-11 12:25:40 +01005795 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005796 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005797 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005798 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005799 goto out;
5800 survey_idx++;
5801 }
5802
5803 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005804 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005805 res = skb->len;
5806 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005807 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005808 return res;
5809}
5810
Samuel Ortizb23aa672009-07-01 21:26:54 +02005811static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5812{
5813 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5814 NL80211_WPA_VERSION_2));
5815}
5816
Jouni Malinen636a5d32009-03-19 13:39:22 +02005817static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5818{
Johannes Berg4c476992010-10-04 21:36:35 +02005819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5820 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005821 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005822 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5823 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005824 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005825 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005826 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005827
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005828 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5829 return -EINVAL;
5830
5831 if (!info->attrs[NL80211_ATTR_MAC])
5832 return -EINVAL;
5833
Jouni Malinen17780922009-03-27 20:52:47 +02005834 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5835 return -EINVAL;
5836
Johannes Berg19957bb2009-07-02 17:20:43 +02005837 if (!info->attrs[NL80211_ATTR_SSID])
5838 return -EINVAL;
5839
5840 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5841 return -EINVAL;
5842
Johannes Bergfffd0932009-07-08 14:22:54 +02005843 err = nl80211_parse_key(info, &key);
5844 if (err)
5845 return err;
5846
5847 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005848 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5849 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005850 if (!key.p.key || !key.p.key_len)
5851 return -EINVAL;
5852 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5853 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5854 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5855 key.p.key_len != WLAN_KEY_LEN_WEP104))
5856 return -EINVAL;
5857 if (key.idx > 4)
5858 return -EINVAL;
5859 } else {
5860 key.p.key_len = 0;
5861 key.p.key = NULL;
5862 }
5863
Johannes Bergafea0b72010-08-10 09:46:42 +02005864 if (key.idx >= 0) {
5865 int i;
5866 bool ok = false;
5867 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5868 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5869 ok = true;
5870 break;
5871 }
5872 }
Johannes Berg4c476992010-10-04 21:36:35 +02005873 if (!ok)
5874 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005875 }
5876
Johannes Berg4c476992010-10-04 21:36:35 +02005877 if (!rdev->ops->auth)
5878 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005879
Johannes Berg074ac8d2010-09-16 14:58:22 +02005880 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005881 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5882 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005883
Johannes Berg19957bb2009-07-02 17:20:43 +02005884 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005885 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005886 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005887 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5888 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005889
Johannes Berg19957bb2009-07-02 17:20:43 +02005890 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5891 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5892
5893 if (info->attrs[NL80211_ATTR_IE]) {
5894 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5895 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5896 }
5897
5898 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005899 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005900 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005901
Jouni Malinene39e5b52012-09-30 19:29:39 +03005902 if (auth_type == NL80211_AUTHTYPE_SAE &&
5903 !info->attrs[NL80211_ATTR_SAE_DATA])
5904 return -EINVAL;
5905
5906 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5907 if (auth_type != NL80211_AUTHTYPE_SAE)
5908 return -EINVAL;
5909 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5910 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5911 /* need to include at least Auth Transaction and Status Code */
5912 if (sae_data_len < 4)
5913 return -EINVAL;
5914 }
5915
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005916 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5917
Johannes Berg95de8172012-01-20 13:55:25 +01005918 /*
5919 * Since we no longer track auth state, ignore
5920 * requests to only change local state.
5921 */
5922 if (local_state_change)
5923 return 0;
5924
Johannes Berg91bf9b22013-05-15 17:44:01 +02005925 wdev_lock(dev->ieee80211_ptr);
5926 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5927 ssid, ssid_len, ie, ie_len,
5928 key.p.key, key.p.key_len, key.idx,
5929 sae_data, sae_data_len);
5930 wdev_unlock(dev->ieee80211_ptr);
5931 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005932}
5933
Johannes Bergc0692b82010-08-27 14:26:53 +03005934static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5935 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005936 struct cfg80211_crypto_settings *settings,
5937 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005938{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005939 memset(settings, 0, sizeof(*settings));
5940
Samuel Ortizb23aa672009-07-01 21:26:54 +02005941 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5942
Johannes Bergc0692b82010-08-27 14:26:53 +03005943 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5944 u16 proto;
5945 proto = nla_get_u16(
5946 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5947 settings->control_port_ethertype = cpu_to_be16(proto);
5948 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5949 proto != ETH_P_PAE)
5950 return -EINVAL;
5951 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5952 settings->control_port_no_encrypt = true;
5953 } else
5954 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5955
Samuel Ortizb23aa672009-07-01 21:26:54 +02005956 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5957 void *data;
5958 int len, i;
5959
5960 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5961 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5962 settings->n_ciphers_pairwise = len / sizeof(u32);
5963
5964 if (len % sizeof(u32))
5965 return -EINVAL;
5966
Johannes Berg3dc27d22009-07-02 21:36:37 +02005967 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005968 return -EINVAL;
5969
5970 memcpy(settings->ciphers_pairwise, data, len);
5971
5972 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005973 if (!cfg80211_supported_cipher_suite(
5974 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005975 settings->ciphers_pairwise[i]))
5976 return -EINVAL;
5977 }
5978
5979 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5980 settings->cipher_group =
5981 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005982 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5983 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005984 return -EINVAL;
5985 }
5986
5987 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5988 settings->wpa_versions =
5989 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5990 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5991 return -EINVAL;
5992 }
5993
5994 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5995 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005996 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005997
5998 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5999 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6000 settings->n_akm_suites = len / sizeof(u32);
6001
6002 if (len % sizeof(u32))
6003 return -EINVAL;
6004
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006005 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6006 return -EINVAL;
6007
Samuel Ortizb23aa672009-07-01 21:26:54 +02006008 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006009 }
6010
6011 return 0;
6012}
6013
Jouni Malinen636a5d32009-03-19 13:39:22 +02006014static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6015{
Johannes Berg4c476992010-10-04 21:36:35 +02006016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6017 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006018 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006019 struct cfg80211_assoc_request req = {};
6020 const u8 *bssid, *ssid;
6021 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006022
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006023 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6024 return -EINVAL;
6025
6026 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006027 !info->attrs[NL80211_ATTR_SSID] ||
6028 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006029 return -EINVAL;
6030
Johannes Berg4c476992010-10-04 21:36:35 +02006031 if (!rdev->ops->assoc)
6032 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006033
Johannes Berg074ac8d2010-09-16 14:58:22 +02006034 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006035 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6036 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006037
Johannes Berg19957bb2009-07-02 17:20:43 +02006038 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006039
Johannes Berg19957bb2009-07-02 17:20:43 +02006040 chan = ieee80211_get_channel(&rdev->wiphy,
6041 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006042 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6043 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006044
Johannes Berg19957bb2009-07-02 17:20:43 +02006045 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6046 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006047
6048 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006049 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6050 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006051 }
6052
Jouni Malinendc6382c2009-05-06 22:09:37 +03006053 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006054 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006055 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006056 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006057 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006058 else if (mfp != NL80211_MFP_NO)
6059 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006060 }
6061
Johannes Berg3e5d7642009-07-07 14:37:26 +02006062 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006063 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006064
Ben Greear7e7c8922011-11-18 11:31:59 -08006065 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006066 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006067
6068 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006069 memcpy(&req.ht_capa_mask,
6070 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6071 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006072
6073 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006074 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006075 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006076 memcpy(&req.ht_capa,
6077 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6078 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006079 }
6080
Johannes Bergee2aca32013-02-21 17:36:01 +01006081 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006082 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006083
6084 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006085 memcpy(&req.vht_capa_mask,
6086 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6087 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006088
6089 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006090 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006091 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006092 memcpy(&req.vht_capa,
6093 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6094 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006095 }
6096
Johannes Bergf62fab72013-02-21 20:09:09 +01006097 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006098 if (!err) {
6099 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006100 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6101 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006102 wdev_unlock(dev->ieee80211_ptr);
6103 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006104
Jouni Malinen636a5d32009-03-19 13:39:22 +02006105 return err;
6106}
6107
6108static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6109{
Johannes Berg4c476992010-10-04 21:36:35 +02006110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6111 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006112 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006113 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006114 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006115 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006116
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006117 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6118 return -EINVAL;
6119
6120 if (!info->attrs[NL80211_ATTR_MAC])
6121 return -EINVAL;
6122
6123 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6124 return -EINVAL;
6125
Johannes Berg4c476992010-10-04 21:36:35 +02006126 if (!rdev->ops->deauth)
6127 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006128
Johannes Berg074ac8d2010-09-16 14:58:22 +02006129 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006130 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6131 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006132
Johannes Berg19957bb2009-07-02 17:20:43 +02006133 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006134
Johannes Berg19957bb2009-07-02 17:20:43 +02006135 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6136 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006137 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006138 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006139 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006140
6141 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006142 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6143 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006144 }
6145
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006146 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6147
Johannes Berg91bf9b22013-05-15 17:44:01 +02006148 wdev_lock(dev->ieee80211_ptr);
6149 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6150 local_state_change);
6151 wdev_unlock(dev->ieee80211_ptr);
6152 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006153}
6154
6155static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6156{
Johannes Berg4c476992010-10-04 21:36:35 +02006157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6158 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006159 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006160 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006161 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006162 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006163
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006164 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6165 return -EINVAL;
6166
6167 if (!info->attrs[NL80211_ATTR_MAC])
6168 return -EINVAL;
6169
6170 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6171 return -EINVAL;
6172
Johannes Berg4c476992010-10-04 21:36:35 +02006173 if (!rdev->ops->disassoc)
6174 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006175
Johannes Berg074ac8d2010-09-16 14:58:22 +02006176 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006177 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6178 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006179
Johannes Berg19957bb2009-07-02 17:20:43 +02006180 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006181
Johannes Berg19957bb2009-07-02 17:20:43 +02006182 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6183 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006184 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006185 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006186 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006187
6188 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006189 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6190 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006191 }
6192
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006193 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6194
Johannes Berg91bf9b22013-05-15 17:44:01 +02006195 wdev_lock(dev->ieee80211_ptr);
6196 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6197 local_state_change);
6198 wdev_unlock(dev->ieee80211_ptr);
6199 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006200}
6201
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006202static bool
6203nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6204 int mcast_rate[IEEE80211_NUM_BANDS],
6205 int rateval)
6206{
6207 struct wiphy *wiphy = &rdev->wiphy;
6208 bool found = false;
6209 int band, i;
6210
6211 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6212 struct ieee80211_supported_band *sband;
6213
6214 sband = wiphy->bands[band];
6215 if (!sband)
6216 continue;
6217
6218 for (i = 0; i < sband->n_bitrates; i++) {
6219 if (sband->bitrates[i].bitrate == rateval) {
6220 mcast_rate[band] = i + 1;
6221 found = true;
6222 break;
6223 }
6224 }
6225 }
6226
6227 return found;
6228}
6229
Johannes Berg04a773a2009-04-19 21:24:32 +02006230static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6231{
Johannes Berg4c476992010-10-04 21:36:35 +02006232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6233 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006234 struct cfg80211_ibss_params ibss;
6235 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006236 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006237 int err;
6238
Johannes Berg8e30bc52009-04-22 17:45:38 +02006239 memset(&ibss, 0, sizeof(ibss));
6240
Johannes Berg04a773a2009-04-19 21:24:32 +02006241 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6242 return -EINVAL;
6243
Johannes Berg683b6d32012-11-08 21:25:48 +01006244 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006245 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6246 return -EINVAL;
6247
Johannes Berg8e30bc52009-04-22 17:45:38 +02006248 ibss.beacon_interval = 100;
6249
6250 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6251 ibss.beacon_interval =
6252 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6253 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6254 return -EINVAL;
6255 }
6256
Johannes Berg4c476992010-10-04 21:36:35 +02006257 if (!rdev->ops->join_ibss)
6258 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006259
Johannes Berg4c476992010-10-04 21:36:35 +02006260 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6261 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006262
Johannes Berg79c97e92009-07-07 03:56:12 +02006263 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006264
Johannes Berg39193492011-09-16 13:45:25 +02006265 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006266 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006267
6268 if (!is_valid_ether_addr(ibss.bssid))
6269 return -EINVAL;
6270 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006271 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6272 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6273
6274 if (info->attrs[NL80211_ATTR_IE]) {
6275 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6276 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6277 }
6278
Johannes Berg683b6d32012-11-08 21:25:48 +01006279 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6280 if (err)
6281 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01006282
Johannes Berg683b6d32012-11-08 21:25:48 +01006283 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01006284 return -EINVAL;
6285
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006286 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6287 return -EINVAL;
6288 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6289 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006290 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006291
Johannes Berg04a773a2009-04-19 21:24:32 +02006292 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006293 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006294
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006295 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6296 u8 *rates =
6297 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6298 int n_rates =
6299 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6300 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006301 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006302
Johannes Berg34850ab2011-07-18 18:08:35 +02006303 err = ieee80211_get_ratemask(sband, rates, n_rates,
6304 &ibss.basic_rates);
6305 if (err)
6306 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006307 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006308
6309 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6310 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6311 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6312 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006313
Johannes Berg4c476992010-10-04 21:36:35 +02006314 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306315 bool no_ht = false;
6316
Johannes Berg4c476992010-10-04 21:36:35 +02006317 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306318 info->attrs[NL80211_ATTR_KEYS],
6319 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006320 if (IS_ERR(connkeys))
6321 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306322
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006323 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6324 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306325 kfree(connkeys);
6326 return -EINVAL;
6327 }
Johannes Berg4c476992010-10-04 21:36:35 +02006328 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006329
Antonio Quartulli267335d2012-01-31 20:25:47 +01006330 ibss.control_port =
6331 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6332
Johannes Berg4c476992010-10-04 21:36:35 +02006333 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006334 if (err)
6335 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006336 return err;
6337}
6338
6339static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6340{
Johannes Berg4c476992010-10-04 21:36:35 +02006341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6342 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006343
Johannes Berg4c476992010-10-04 21:36:35 +02006344 if (!rdev->ops->leave_ibss)
6345 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006346
Johannes Berg4c476992010-10-04 21:36:35 +02006347 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6348 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006349
Johannes Berg4c476992010-10-04 21:36:35 +02006350 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006351}
6352
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006353static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6354{
6355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6356 struct net_device *dev = info->user_ptr[1];
6357 int mcast_rate[IEEE80211_NUM_BANDS];
6358 u32 nla_rate;
6359 int err;
6360
6361 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6362 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6363 return -EOPNOTSUPP;
6364
6365 if (!rdev->ops->set_mcast_rate)
6366 return -EOPNOTSUPP;
6367
6368 memset(mcast_rate, 0, sizeof(mcast_rate));
6369
6370 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6371 return -EINVAL;
6372
6373 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6374 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6375 return -EINVAL;
6376
6377 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6378
6379 return err;
6380}
6381
6382
Johannes Bergaff89a92009-07-01 21:26:51 +02006383#ifdef CONFIG_NL80211_TESTMODE
6384static struct genl_multicast_group nl80211_testmode_mcgrp = {
6385 .name = "testmode",
6386};
6387
6388static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6389{
Johannes Berg4c476992010-10-04 21:36:35 +02006390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006391 int err;
6392
6393 if (!info->attrs[NL80211_ATTR_TESTDATA])
6394 return -EINVAL;
6395
Johannes Bergaff89a92009-07-01 21:26:51 +02006396 err = -EOPNOTSUPP;
6397 if (rdev->ops->testmode_cmd) {
6398 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006399 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006400 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6401 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6402 rdev->testmode_info = NULL;
6403 }
6404
Johannes Bergaff89a92009-07-01 21:26:51 +02006405 return err;
6406}
6407
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006408static int nl80211_testmode_dump(struct sk_buff *skb,
6409 struct netlink_callback *cb)
6410{
Johannes Berg00918d32011-12-13 17:22:05 +01006411 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006412 int err;
6413 long phy_idx;
6414 void *data = NULL;
6415 int data_len = 0;
6416
Johannes Berg5fe231e2013-05-08 21:45:15 +02006417 rtnl_lock();
6418
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006419 if (cb->args[0]) {
6420 /*
6421 * 0 is a valid index, but not valid for args[0],
6422 * so we need to offset by 1.
6423 */
6424 phy_idx = cb->args[0] - 1;
6425 } else {
6426 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6427 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6428 nl80211_policy);
6429 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006430 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006431
Johannes Berg2bd7e352012-06-15 14:23:16 +02006432 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6433 nl80211_fam.attrbuf);
6434 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006435 err = PTR_ERR(rdev);
6436 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006437 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006438 phy_idx = rdev->wiphy_idx;
6439 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006440
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006441 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6442 cb->args[1] =
6443 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6444 }
6445
6446 if (cb->args[1]) {
6447 data = nla_data((void *)cb->args[1]);
6448 data_len = nla_len((void *)cb->args[1]);
6449 }
6450
Johannes Berg00918d32011-12-13 17:22:05 +01006451 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6452 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006453 err = -ENOENT;
6454 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006455 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006456
Johannes Berg00918d32011-12-13 17:22:05 +01006457 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006458 err = -EOPNOTSUPP;
6459 goto out_err;
6460 }
6461
6462 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006463 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006464 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6465 NL80211_CMD_TESTMODE);
6466 struct nlattr *tmdata;
6467
David S. Miller9360ffd2012-03-29 04:41:26 -04006468 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006469 genlmsg_cancel(skb, hdr);
6470 break;
6471 }
6472
6473 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6474 if (!tmdata) {
6475 genlmsg_cancel(skb, hdr);
6476 break;
6477 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006478 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006479 nla_nest_end(skb, tmdata);
6480
6481 if (err == -ENOBUFS || err == -ENOENT) {
6482 genlmsg_cancel(skb, hdr);
6483 break;
6484 } else if (err) {
6485 genlmsg_cancel(skb, hdr);
6486 goto out_err;
6487 }
6488
6489 genlmsg_end(skb, hdr);
6490 }
6491
6492 err = skb->len;
6493 /* see above */
6494 cb->args[0] = phy_idx + 1;
6495 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006496 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006497 return err;
6498}
6499
Johannes Bergaff89a92009-07-01 21:26:51 +02006500static struct sk_buff *
6501__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006502 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006503{
6504 struct sk_buff *skb;
6505 void *hdr;
6506 struct nlattr *data;
6507
6508 skb = nlmsg_new(approxlen + 100, gfp);
6509 if (!skb)
6510 return NULL;
6511
Eric W. Biederman15e47302012-09-07 20:12:54 +00006512 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006513 if (!hdr) {
6514 kfree_skb(skb);
6515 return NULL;
6516 }
6517
David S. Miller9360ffd2012-03-29 04:41:26 -04006518 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6519 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006520 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6521
6522 ((void **)skb->cb)[0] = rdev;
6523 ((void **)skb->cb)[1] = hdr;
6524 ((void **)skb->cb)[2] = data;
6525
6526 return skb;
6527
6528 nla_put_failure:
6529 kfree_skb(skb);
6530 return NULL;
6531}
6532
6533struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6534 int approxlen)
6535{
6536 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6537
6538 if (WARN_ON(!rdev->testmode_info))
6539 return NULL;
6540
6541 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006542 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006543 rdev->testmode_info->snd_seq,
6544 GFP_KERNEL);
6545}
6546EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6547
6548int cfg80211_testmode_reply(struct sk_buff *skb)
6549{
6550 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6551 void *hdr = ((void **)skb->cb)[1];
6552 struct nlattr *data = ((void **)skb->cb)[2];
6553
6554 if (WARN_ON(!rdev->testmode_info)) {
6555 kfree_skb(skb);
6556 return -EINVAL;
6557 }
6558
6559 nla_nest_end(skb, data);
6560 genlmsg_end(skb, hdr);
6561 return genlmsg_reply(skb, rdev->testmode_info);
6562}
6563EXPORT_SYMBOL(cfg80211_testmode_reply);
6564
6565struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6566 int approxlen, gfp_t gfp)
6567{
6568 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6569
6570 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6571}
6572EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6573
6574void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6575{
6576 void *hdr = ((void **)skb->cb)[1];
6577 struct nlattr *data = ((void **)skb->cb)[2];
6578
6579 nla_nest_end(skb, data);
6580 genlmsg_end(skb, hdr);
6581 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6582}
6583EXPORT_SYMBOL(cfg80211_testmode_event);
6584#endif
6585
Samuel Ortizb23aa672009-07-01 21:26:54 +02006586static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6587{
Johannes Berg4c476992010-10-04 21:36:35 +02006588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6589 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006590 struct cfg80211_connect_params connect;
6591 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006592 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006593 int err;
6594
6595 memset(&connect, 0, sizeof(connect));
6596
6597 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6598 return -EINVAL;
6599
6600 if (!info->attrs[NL80211_ATTR_SSID] ||
6601 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6602 return -EINVAL;
6603
6604 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6605 connect.auth_type =
6606 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006607 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6608 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006609 return -EINVAL;
6610 } else
6611 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6612
6613 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6614
Johannes Bergc0692b82010-08-27 14:26:53 +03006615 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006616 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006617 if (err)
6618 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006619
Johannes Berg074ac8d2010-09-16 14:58:22 +02006620 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006621 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6622 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006623
Johannes Berg79c97e92009-07-07 03:56:12 +02006624 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006625
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306626 connect.bg_scan_period = -1;
6627 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6628 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6629 connect.bg_scan_period =
6630 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6631 }
6632
Samuel Ortizb23aa672009-07-01 21:26:54 +02006633 if (info->attrs[NL80211_ATTR_MAC])
6634 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6635 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6636 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6637
6638 if (info->attrs[NL80211_ATTR_IE]) {
6639 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6640 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6641 }
6642
Jouni Malinencee00a92013-01-15 17:15:57 +02006643 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6644 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6645 if (connect.mfp != NL80211_MFP_REQUIRED &&
6646 connect.mfp != NL80211_MFP_NO)
6647 return -EINVAL;
6648 } else {
6649 connect.mfp = NL80211_MFP_NO;
6650 }
6651
Samuel Ortizb23aa672009-07-01 21:26:54 +02006652 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6653 connect.channel =
6654 ieee80211_get_channel(wiphy,
6655 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6656 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006657 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6658 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006659 }
6660
Johannes Bergfffd0932009-07-08 14:22:54 +02006661 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6662 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306663 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006664 if (IS_ERR(connkeys))
6665 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006666 }
6667
Ben Greear7e7c8922011-11-18 11:31:59 -08006668 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6669 connect.flags |= ASSOC_REQ_DISABLE_HT;
6670
6671 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6672 memcpy(&connect.ht_capa_mask,
6673 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6674 sizeof(connect.ht_capa_mask));
6675
6676 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006677 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6678 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006679 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006680 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006681 memcpy(&connect.ht_capa,
6682 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6683 sizeof(connect.ht_capa));
6684 }
6685
Johannes Bergee2aca32013-02-21 17:36:01 +01006686 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6687 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6688
6689 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6690 memcpy(&connect.vht_capa_mask,
6691 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6692 sizeof(connect.vht_capa_mask));
6693
6694 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6695 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6696 kfree(connkeys);
6697 return -EINVAL;
6698 }
6699 memcpy(&connect.vht_capa,
6700 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6701 sizeof(connect.vht_capa));
6702 }
6703
Johannes Berg83739b02013-05-15 17:44:01 +02006704 wdev_lock(dev->ieee80211_ptr);
6705 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6706 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006707 if (err)
6708 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006709 return err;
6710}
6711
6712static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6713{
Johannes Berg4c476992010-10-04 21:36:35 +02006714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6715 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006716 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006717 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006718
6719 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6720 reason = WLAN_REASON_DEAUTH_LEAVING;
6721 else
6722 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6723
6724 if (reason == 0)
6725 return -EINVAL;
6726
Johannes Berg074ac8d2010-09-16 14:58:22 +02006727 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006728 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6729 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006730
Johannes Berg83739b02013-05-15 17:44:01 +02006731 wdev_lock(dev->ieee80211_ptr);
6732 ret = cfg80211_disconnect(rdev, dev, reason, true);
6733 wdev_unlock(dev->ieee80211_ptr);
6734 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006735}
6736
Johannes Berg463d0182009-07-14 00:33:35 +02006737static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6738{
Johannes Berg4c476992010-10-04 21:36:35 +02006739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006740 struct net *net;
6741 int err;
6742 u32 pid;
6743
6744 if (!info->attrs[NL80211_ATTR_PID])
6745 return -EINVAL;
6746
6747 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6748
Johannes Berg463d0182009-07-14 00:33:35 +02006749 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006750 if (IS_ERR(net))
6751 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006752
6753 err = 0;
6754
6755 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006756 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6757 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006758
Johannes Berg463d0182009-07-14 00:33:35 +02006759 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006760 return err;
6761}
6762
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006763static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6764{
Johannes Berg4c476992010-10-04 21:36:35 +02006765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006766 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6767 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006768 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006769 struct cfg80211_pmksa pmksa;
6770
6771 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6772
6773 if (!info->attrs[NL80211_ATTR_MAC])
6774 return -EINVAL;
6775
6776 if (!info->attrs[NL80211_ATTR_PMKID])
6777 return -EINVAL;
6778
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006779 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6780 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6781
Johannes Berg074ac8d2010-09-16 14:58:22 +02006782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006783 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6784 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006785
6786 switch (info->genlhdr->cmd) {
6787 case NL80211_CMD_SET_PMKSA:
6788 rdev_ops = rdev->ops->set_pmksa;
6789 break;
6790 case NL80211_CMD_DEL_PMKSA:
6791 rdev_ops = rdev->ops->del_pmksa;
6792 break;
6793 default:
6794 WARN_ON(1);
6795 break;
6796 }
6797
Johannes Berg4c476992010-10-04 21:36:35 +02006798 if (!rdev_ops)
6799 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006800
Johannes Berg4c476992010-10-04 21:36:35 +02006801 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006802}
6803
6804static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6805{
Johannes Berg4c476992010-10-04 21:36:35 +02006806 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6807 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006808
Johannes Berg074ac8d2010-09-16 14:58:22 +02006809 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006810 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6811 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006812
Johannes Berg4c476992010-10-04 21:36:35 +02006813 if (!rdev->ops->flush_pmksa)
6814 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006815
Hila Gonene35e4d22012-06-27 17:19:42 +03006816 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006817}
6818
Arik Nemtsov109086c2011-09-28 14:12:50 +03006819static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6820{
6821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6822 struct net_device *dev = info->user_ptr[1];
6823 u8 action_code, dialog_token;
6824 u16 status_code;
6825 u8 *peer;
6826
6827 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6828 !rdev->ops->tdls_mgmt)
6829 return -EOPNOTSUPP;
6830
6831 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6832 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6833 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6834 !info->attrs[NL80211_ATTR_IE] ||
6835 !info->attrs[NL80211_ATTR_MAC])
6836 return -EINVAL;
6837
6838 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6839 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6840 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6841 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6842
Hila Gonene35e4d22012-06-27 17:19:42 +03006843 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6844 dialog_token, status_code,
6845 nla_data(info->attrs[NL80211_ATTR_IE]),
6846 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006847}
6848
6849static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6850{
6851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6852 struct net_device *dev = info->user_ptr[1];
6853 enum nl80211_tdls_operation operation;
6854 u8 *peer;
6855
6856 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6857 !rdev->ops->tdls_oper)
6858 return -EOPNOTSUPP;
6859
6860 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6861 !info->attrs[NL80211_ATTR_MAC])
6862 return -EINVAL;
6863
6864 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6865 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6866
Hila Gonene35e4d22012-06-27 17:19:42 +03006867 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006868}
6869
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006870static int nl80211_remain_on_channel(struct sk_buff *skb,
6871 struct genl_info *info)
6872{
Johannes Berg4c476992010-10-04 21:36:35 +02006873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006874 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006875 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006876 struct sk_buff *msg;
6877 void *hdr;
6878 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006879 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006880 int err;
6881
6882 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6883 !info->attrs[NL80211_ATTR_DURATION])
6884 return -EINVAL;
6885
6886 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6887
Johannes Berg7c4ef712011-11-18 15:33:48 +01006888 if (!rdev->ops->remain_on_channel ||
6889 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006890 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006891
Johannes Bergebf348f2012-06-01 12:50:54 +02006892 /*
6893 * We should be on that channel for at least a minimum amount of
6894 * time (10ms) but no longer than the driver supports.
6895 */
6896 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6897 duration > rdev->wiphy.max_remain_on_channel_duration)
6898 return -EINVAL;
6899
Johannes Berg683b6d32012-11-08 21:25:48 +01006900 err = nl80211_parse_chandef(rdev, info, &chandef);
6901 if (err)
6902 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006903
6904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006905 if (!msg)
6906 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006907
Eric W. Biederman15e47302012-09-07 20:12:54 +00006908 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006909 NL80211_CMD_REMAIN_ON_CHANNEL);
6910
6911 if (IS_ERR(hdr)) {
6912 err = PTR_ERR(hdr);
6913 goto free_msg;
6914 }
6915
Johannes Berg683b6d32012-11-08 21:25:48 +01006916 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6917 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006918
6919 if (err)
6920 goto free_msg;
6921
David S. Miller9360ffd2012-03-29 04:41:26 -04006922 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6923 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006924
6925 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006926
6927 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006928
6929 nla_put_failure:
6930 err = -ENOBUFS;
6931 free_msg:
6932 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006933 return err;
6934}
6935
6936static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6937 struct genl_info *info)
6938{
Johannes Berg4c476992010-10-04 21:36:35 +02006939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006940 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006941 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006942
6943 if (!info->attrs[NL80211_ATTR_COOKIE])
6944 return -EINVAL;
6945
Johannes Berg4c476992010-10-04 21:36:35 +02006946 if (!rdev->ops->cancel_remain_on_channel)
6947 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006948
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006949 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6950
Hila Gonene35e4d22012-06-27 17:19:42 +03006951 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006952}
6953
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006954static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6955 u8 *rates, u8 rates_len)
6956{
6957 u8 i;
6958 u32 mask = 0;
6959
6960 for (i = 0; i < rates_len; i++) {
6961 int rate = (rates[i] & 0x7f) * 5;
6962 int ridx;
6963 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6964 struct ieee80211_rate *srate =
6965 &sband->bitrates[ridx];
6966 if (rate == srate->bitrate) {
6967 mask |= 1 << ridx;
6968 break;
6969 }
6970 }
6971 if (ridx == sband->n_bitrates)
6972 return 0; /* rate not found */
6973 }
6974
6975 return mask;
6976}
6977
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006978static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6979 u8 *rates, u8 rates_len,
6980 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6981{
6982 u8 i;
6983
6984 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6985
6986 for (i = 0; i < rates_len; i++) {
6987 int ridx, rbit;
6988
6989 ridx = rates[i] / 8;
6990 rbit = BIT(rates[i] % 8);
6991
6992 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006993 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006994 return false;
6995
6996 /* check availability */
6997 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6998 mcs[ridx] |= rbit;
6999 else
7000 return false;
7001 }
7002
7003 return true;
7004}
7005
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007006static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007007 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7008 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007009 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7010 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007011};
7012
7013static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7014 struct genl_info *info)
7015{
7016 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007017 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007018 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007019 int rem, i;
7020 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007021 struct nlattr *tx_rates;
7022 struct ieee80211_supported_band *sband;
7023
7024 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7025 return -EINVAL;
7026
Johannes Berg4c476992010-10-04 21:36:35 +02007027 if (!rdev->ops->set_bitrate_mask)
7028 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007029
7030 memset(&mask, 0, sizeof(mask));
7031 /* Default to all rates enabled */
7032 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7033 sband = rdev->wiphy.bands[i];
7034 mask.control[i].legacy =
7035 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007036 if (sband)
7037 memcpy(mask.control[i].mcs,
7038 sband->ht_cap.mcs.rx_mask,
7039 sizeof(mask.control[i].mcs));
7040 else
7041 memset(mask.control[i].mcs, 0,
7042 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007043 }
7044
7045 /*
7046 * The nested attribute uses enum nl80211_band as the index. This maps
7047 * directly to the enum ieee80211_band values used in cfg80211.
7048 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007049 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007050 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7051 {
7052 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007053 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7054 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007055 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007056 if (sband == NULL)
7057 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007058 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7059 nla_len(tx_rates), nl80211_txattr_policy);
7060 if (tb[NL80211_TXRATE_LEGACY]) {
7061 mask.control[band].legacy = rateset_to_mask(
7062 sband,
7063 nla_data(tb[NL80211_TXRATE_LEGACY]),
7064 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307065 if ((mask.control[band].legacy == 0) &&
7066 nla_len(tb[NL80211_TXRATE_LEGACY]))
7067 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007068 }
7069 if (tb[NL80211_TXRATE_MCS]) {
7070 if (!ht_rateset_to_mask(
7071 sband,
7072 nla_data(tb[NL80211_TXRATE_MCS]),
7073 nla_len(tb[NL80211_TXRATE_MCS]),
7074 mask.control[band].mcs))
7075 return -EINVAL;
7076 }
7077
7078 if (mask.control[band].legacy == 0) {
7079 /* don't allow empty legacy rates if HT
7080 * is not even supported. */
7081 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7082 return -EINVAL;
7083
7084 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7085 if (mask.control[band].mcs[i])
7086 break;
7087
7088 /* legacy and mcs rates may not be both empty */
7089 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007090 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007091 }
7092 }
7093
Hila Gonene35e4d22012-06-27 17:19:42 +03007094 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007095}
7096
Johannes Berg2e161f72010-08-12 15:38:38 +02007097static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007098{
Johannes Berg4c476992010-10-04 21:36:35 +02007099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007100 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007101 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007102
7103 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7104 return -EINVAL;
7105
Johannes Berg2e161f72010-08-12 15:38:38 +02007106 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7107 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007108
Johannes Berg71bbc992012-06-15 15:30:18 +02007109 switch (wdev->iftype) {
7110 case NL80211_IFTYPE_STATION:
7111 case NL80211_IFTYPE_ADHOC:
7112 case NL80211_IFTYPE_P2P_CLIENT:
7113 case NL80211_IFTYPE_AP:
7114 case NL80211_IFTYPE_AP_VLAN:
7115 case NL80211_IFTYPE_MESH_POINT:
7116 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007117 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007118 break;
7119 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007120 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007121 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007122
7123 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007124 if (!rdev->ops->mgmt_tx)
7125 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007126
Eric W. Biederman15e47302012-09-07 20:12:54 +00007127 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007128 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7129 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007130}
7131
Johannes Berg2e161f72010-08-12 15:38:38 +02007132static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007133{
Johannes Berg4c476992010-10-04 21:36:35 +02007134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007135 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007136 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007137 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007138 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007139 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007140 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007141 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007142 bool offchan, no_cck, dont_wait_for_ack;
7143
7144 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007145
Johannes Berg683b6d32012-11-08 21:25:48 +01007146 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007147 return -EINVAL;
7148
Johannes Berg4c476992010-10-04 21:36:35 +02007149 if (!rdev->ops->mgmt_tx)
7150 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007151
Johannes Berg71bbc992012-06-15 15:30:18 +02007152 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007153 case NL80211_IFTYPE_P2P_DEVICE:
7154 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7155 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007156 case NL80211_IFTYPE_STATION:
7157 case NL80211_IFTYPE_ADHOC:
7158 case NL80211_IFTYPE_P2P_CLIENT:
7159 case NL80211_IFTYPE_AP:
7160 case NL80211_IFTYPE_AP_VLAN:
7161 case NL80211_IFTYPE_MESH_POINT:
7162 case NL80211_IFTYPE_P2P_GO:
7163 break;
7164 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007165 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007166 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007167
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007168 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007169 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007170 return -EINVAL;
7171 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007172
7173 /*
7174 * We should wait on the channel for at least a minimum amount
7175 * of time (10ms) but no longer than the driver supports.
7176 */
7177 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7178 wait > rdev->wiphy.max_remain_on_channel_duration)
7179 return -EINVAL;
7180
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007181 }
7182
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007183 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7184
Johannes Berg7c4ef712011-11-18 15:33:48 +01007185 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7186 return -EINVAL;
7187
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307188 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7189
Antonio Quartulliea141b752013-06-11 14:20:03 +02007190 /* get the channel if any has been specified, otherwise pass NULL to
7191 * the driver. The latter will use the current one
7192 */
7193 chandef.chan = NULL;
7194 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7195 err = nl80211_parse_chandef(rdev, info, &chandef);
7196 if (err)
7197 return err;
7198 }
7199
7200 if (!chandef.chan && offchan)
7201 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007202
Johannes Berge247bd902011-11-04 11:18:21 +01007203 if (!dont_wait_for_ack) {
7204 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7205 if (!msg)
7206 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007207
Eric W. Biederman15e47302012-09-07 20:12:54 +00007208 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007209 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007210
Johannes Berge247bd902011-11-04 11:18:21 +01007211 if (IS_ERR(hdr)) {
7212 err = PTR_ERR(hdr);
7213 goto free_msg;
7214 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007215 }
Johannes Berge247bd902011-11-04 11:18:21 +01007216
Johannes Berg683b6d32012-11-08 21:25:48 +01007217 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007218 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7219 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007220 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007221 if (err)
7222 goto free_msg;
7223
Johannes Berge247bd902011-11-04 11:18:21 +01007224 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007225 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7226 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007227
Johannes Berge247bd902011-11-04 11:18:21 +01007228 genlmsg_end(msg, hdr);
7229 return genlmsg_reply(msg, info);
7230 }
7231
7232 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007233
7234 nla_put_failure:
7235 err = -ENOBUFS;
7236 free_msg:
7237 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007238 return err;
7239}
7240
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007241static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7242{
7243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007244 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007245 u64 cookie;
7246
7247 if (!info->attrs[NL80211_ATTR_COOKIE])
7248 return -EINVAL;
7249
7250 if (!rdev->ops->mgmt_tx_cancel_wait)
7251 return -EOPNOTSUPP;
7252
Johannes Berg71bbc992012-06-15 15:30:18 +02007253 switch (wdev->iftype) {
7254 case NL80211_IFTYPE_STATION:
7255 case NL80211_IFTYPE_ADHOC:
7256 case NL80211_IFTYPE_P2P_CLIENT:
7257 case NL80211_IFTYPE_AP:
7258 case NL80211_IFTYPE_AP_VLAN:
7259 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007260 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007261 break;
7262 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007263 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007264 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007265
7266 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7267
Hila Gonene35e4d22012-06-27 17:19:42 +03007268 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007269}
7270
Kalle Valoffb9eb32010-02-17 17:58:10 +02007271static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7272{
Johannes Berg4c476992010-10-04 21:36:35 +02007273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007274 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007275 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007276 u8 ps_state;
7277 bool state;
7278 int err;
7279
Johannes Berg4c476992010-10-04 21:36:35 +02007280 if (!info->attrs[NL80211_ATTR_PS_STATE])
7281 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007282
7283 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7284
Johannes Berg4c476992010-10-04 21:36:35 +02007285 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7286 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007287
7288 wdev = dev->ieee80211_ptr;
7289
Johannes Berg4c476992010-10-04 21:36:35 +02007290 if (!rdev->ops->set_power_mgmt)
7291 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007292
7293 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7294
7295 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007296 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007297
Hila Gonene35e4d22012-06-27 17:19:42 +03007298 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007299 if (!err)
7300 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007301 return err;
7302}
7303
7304static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7305{
Johannes Berg4c476992010-10-04 21:36:35 +02007306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007307 enum nl80211_ps_state ps_state;
7308 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007309 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007310 struct sk_buff *msg;
7311 void *hdr;
7312 int err;
7313
Kalle Valoffb9eb32010-02-17 17:58:10 +02007314 wdev = dev->ieee80211_ptr;
7315
Johannes Berg4c476992010-10-04 21:36:35 +02007316 if (!rdev->ops->set_power_mgmt)
7317 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007318
7319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007320 if (!msg)
7321 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007322
Eric W. Biederman15e47302012-09-07 20:12:54 +00007323 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007324 NL80211_CMD_GET_POWER_SAVE);
7325 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007326 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007327 goto free_msg;
7328 }
7329
7330 if (wdev->ps)
7331 ps_state = NL80211_PS_ENABLED;
7332 else
7333 ps_state = NL80211_PS_DISABLED;
7334
David S. Miller9360ffd2012-03-29 04:41:26 -04007335 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7336 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007337
7338 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007339 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007340
Johannes Berg4c476992010-10-04 21:36:35 +02007341 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007342 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007343 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007344 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007345 return err;
7346}
7347
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007348static struct nla_policy
7349nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7350 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7351 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7352 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007353 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7354 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7355 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007356};
7357
Thomas Pedersen84f10702012-07-12 16:17:33 -07007358static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007359 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007360{
7361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct wireless_dev *wdev;
7363 struct net_device *dev = info->user_ptr[1];
7364
Johannes Bergd9d8b012012-11-26 12:51:52 +01007365 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007366 return -EINVAL;
7367
7368 wdev = dev->ieee80211_ptr;
7369
7370 if (!rdev->ops->set_cqm_txe_config)
7371 return -EOPNOTSUPP;
7372
7373 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7374 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7375 return -EOPNOTSUPP;
7376
Hila Gonene35e4d22012-06-27 17:19:42 +03007377 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007378}
7379
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007380static int nl80211_set_cqm_rssi(struct genl_info *info,
7381 s32 threshold, u32 hysteresis)
7382{
Johannes Berg4c476992010-10-04 21:36:35 +02007383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007384 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007385 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007386
7387 if (threshold > 0)
7388 return -EINVAL;
7389
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007390 wdev = dev->ieee80211_ptr;
7391
Johannes Berg4c476992010-10-04 21:36:35 +02007392 if (!rdev->ops->set_cqm_rssi_config)
7393 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007394
Johannes Berg074ac8d2010-09-16 14:58:22 +02007395 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007396 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7397 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007398
Hila Gonene35e4d22012-06-27 17:19:42 +03007399 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007400}
7401
7402static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7403{
7404 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7405 struct nlattr *cqm;
7406 int err;
7407
7408 cqm = info->attrs[NL80211_ATTR_CQM];
7409 if (!cqm) {
7410 err = -EINVAL;
7411 goto out;
7412 }
7413
7414 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7415 nl80211_attr_cqm_policy);
7416 if (err)
7417 goto out;
7418
7419 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7420 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7421 s32 threshold;
7422 u32 hysteresis;
7423 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7424 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7425 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007426 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7427 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7428 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7429 u32 rate, pkts, intvl;
7430 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7431 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7432 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7433 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007434 } else
7435 err = -EINVAL;
7436
7437out:
7438 return err;
7439}
7440
Johannes Berg29cbe682010-12-03 09:20:44 +01007441static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7442{
7443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7444 struct net_device *dev = info->user_ptr[1];
7445 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007446 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007447 int err;
7448
7449 /* start with default */
7450 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007451 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007452
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007453 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007454 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007455 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007456 if (err)
7457 return err;
7458 }
7459
7460 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7461 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7462 return -EINVAL;
7463
Javier Cardonac80d5452010-12-16 17:37:49 -08007464 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7465 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7466
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007467 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7468 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7469 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7470 return -EINVAL;
7471
Marco Porsch9bdbf042013-01-07 16:04:51 +01007472 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7473 setup.beacon_interval =
7474 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7475 if (setup.beacon_interval < 10 ||
7476 setup.beacon_interval > 10000)
7477 return -EINVAL;
7478 }
7479
7480 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7481 setup.dtim_period =
7482 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7483 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7484 return -EINVAL;
7485 }
7486
Javier Cardonac80d5452010-12-16 17:37:49 -08007487 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7488 /* parse additional setup parameters if given */
7489 err = nl80211_parse_mesh_setup(info, &setup);
7490 if (err)
7491 return err;
7492 }
7493
Thomas Pedersend37bb182013-03-04 13:06:13 -08007494 if (setup.user_mpm)
7495 cfg.auto_open_plinks = false;
7496
Johannes Bergcc1d2802012-05-16 23:50:20 +02007497 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007498 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7499 if (err)
7500 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007501 } else {
7502 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007503 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007504 }
7505
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007506 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7507 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7508 int n_rates =
7509 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7510 struct ieee80211_supported_band *sband;
7511
7512 if (!setup.chandef.chan)
7513 return -EINVAL;
7514
7515 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7516
7517 err = ieee80211_get_ratemask(sband, rates, n_rates,
7518 &setup.basic_rates);
7519 if (err)
7520 return err;
7521 }
7522
Javier Cardonac80d5452010-12-16 17:37:49 -08007523 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007524}
7525
7526static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7527{
7528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7529 struct net_device *dev = info->user_ptr[1];
7530
7531 return cfg80211_leave_mesh(rdev, dev);
7532}
7533
Johannes Bergdfb89c52012-06-27 09:23:48 +02007534#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007535static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7536 struct cfg80211_registered_device *rdev)
7537{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007538 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007539 struct nlattr *nl_pats, *nl_pat;
7540 int i, pat_len;
7541
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007542 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007543 return 0;
7544
7545 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7546 if (!nl_pats)
7547 return -ENOBUFS;
7548
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007549 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007550 nl_pat = nla_nest_start(msg, i + 1);
7551 if (!nl_pat)
7552 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007553 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007554 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7555 DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007556 wowlan->patterns[i].mask) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007557 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007558 pat_len, wowlan->patterns[i].pattern) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007559 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007560 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007561 return -ENOBUFS;
7562 nla_nest_end(msg, nl_pat);
7563 }
7564 nla_nest_end(msg, nl_pats);
7565
7566 return 0;
7567}
7568
Johannes Berg2a0e0472013-01-23 22:57:40 +01007569static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7570 struct cfg80211_wowlan_tcp *tcp)
7571{
7572 struct nlattr *nl_tcp;
7573
7574 if (!tcp)
7575 return 0;
7576
7577 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7578 if (!nl_tcp)
7579 return -ENOBUFS;
7580
7581 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7582 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7583 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7584 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7585 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7586 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7587 tcp->payload_len, tcp->payload) ||
7588 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7589 tcp->data_interval) ||
7590 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7591 tcp->wake_len, tcp->wake_data) ||
7592 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7593 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7594 return -ENOBUFS;
7595
7596 if (tcp->payload_seq.len &&
7597 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7598 sizeof(tcp->payload_seq), &tcp->payload_seq))
7599 return -ENOBUFS;
7600
7601 if (tcp->payload_tok.len &&
7602 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7603 sizeof(tcp->payload_tok) + tcp->tokens_size,
7604 &tcp->payload_tok))
7605 return -ENOBUFS;
7606
Johannes Berge248ad32013-05-16 10:24:28 +02007607 nla_nest_end(msg, nl_tcp);
7608
Johannes Berg2a0e0472013-01-23 22:57:40 +01007609 return 0;
7610}
7611
Johannes Bergff1b6e62011-05-04 15:37:28 +02007612static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7613{
7614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7615 struct sk_buff *msg;
7616 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007617 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007618
Johannes Berg964dc9e2013-06-03 17:25:34 +02007619 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007620 return -EOPNOTSUPP;
7621
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007622 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007623 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007624 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7625 rdev->wiphy.wowlan_config->tcp->payload_len +
7626 rdev->wiphy.wowlan_config->tcp->wake_len +
7627 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007628 }
7629
7630 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007631 if (!msg)
7632 return -ENOMEM;
7633
Eric W. Biederman15e47302012-09-07 20:12:54 +00007634 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007635 NL80211_CMD_GET_WOWLAN);
7636 if (!hdr)
7637 goto nla_put_failure;
7638
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007639 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007640 struct nlattr *nl_wowlan;
7641
7642 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7643 if (!nl_wowlan)
7644 goto nla_put_failure;
7645
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007646 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007647 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007648 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007649 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007650 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007651 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007652 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007653 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007654 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007655 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007656 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007657 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007658 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007659 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7660 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007661
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007662 if (nl80211_send_wowlan_patterns(msg, rdev))
7663 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007664
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007665 if (nl80211_send_wowlan_tcp(msg,
7666 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007667 goto nla_put_failure;
7668
Johannes Bergff1b6e62011-05-04 15:37:28 +02007669 nla_nest_end(msg, nl_wowlan);
7670 }
7671
7672 genlmsg_end(msg, hdr);
7673 return genlmsg_reply(msg, info);
7674
7675nla_put_failure:
7676 nlmsg_free(msg);
7677 return -ENOBUFS;
7678}
7679
Johannes Berg2a0e0472013-01-23 22:57:40 +01007680static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7681 struct nlattr *attr,
7682 struct cfg80211_wowlan *trig)
7683{
7684 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7685 struct cfg80211_wowlan_tcp *cfg;
7686 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7687 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7688 u32 size;
7689 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7690 int err, port;
7691
Johannes Berg964dc9e2013-06-03 17:25:34 +02007692 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007693 return -EINVAL;
7694
7695 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7696 nla_data(attr), nla_len(attr),
7697 nl80211_wowlan_tcp_policy);
7698 if (err)
7699 return err;
7700
7701 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7702 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7703 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7704 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7705 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7706 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7707 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7708 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7709 return -EINVAL;
7710
7711 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007712 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007713 return -EINVAL;
7714
7715 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007716 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007717 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007718 return -EINVAL;
7719
7720 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007721 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007722 return -EINVAL;
7723
7724 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7725 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7726 return -EINVAL;
7727
7728 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7729 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7730
7731 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7732 tokens_size = tokln - sizeof(*tok);
7733
7734 if (!tok->len || tokens_size % tok->len)
7735 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007736 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007737 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007738 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007739 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007740 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007741 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007742 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007743 return -EINVAL;
7744 if (tok->offset + tok->len > data_size)
7745 return -EINVAL;
7746 }
7747
7748 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7749 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007750 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007751 return -EINVAL;
7752 if (seq->len == 0 || seq->len > 4)
7753 return -EINVAL;
7754 if (seq->len + seq->offset > data_size)
7755 return -EINVAL;
7756 }
7757
7758 size = sizeof(*cfg);
7759 size += data_size;
7760 size += wake_size + wake_mask_size;
7761 size += tokens_size;
7762
7763 cfg = kzalloc(size, GFP_KERNEL);
7764 if (!cfg)
7765 return -ENOMEM;
7766 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7767 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7768 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7769 ETH_ALEN);
7770 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7771 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7772 else
7773 port = 0;
7774#ifdef CONFIG_INET
7775 /* allocate a socket and port for it and use it */
7776 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7777 IPPROTO_TCP, &cfg->sock, 1);
7778 if (err) {
7779 kfree(cfg);
7780 return err;
7781 }
7782 if (inet_csk_get_port(cfg->sock->sk, port)) {
7783 sock_release(cfg->sock);
7784 kfree(cfg);
7785 return -EADDRINUSE;
7786 }
7787 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7788#else
7789 if (!port) {
7790 kfree(cfg);
7791 return -EINVAL;
7792 }
7793 cfg->src_port = port;
7794#endif
7795
7796 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7797 cfg->payload_len = data_size;
7798 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7799 memcpy((void *)cfg->payload,
7800 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7801 data_size);
7802 if (seq)
7803 cfg->payload_seq = *seq;
7804 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7805 cfg->wake_len = wake_size;
7806 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7807 memcpy((void *)cfg->wake_data,
7808 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7809 wake_size);
7810 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7811 data_size + wake_size;
7812 memcpy((void *)cfg->wake_mask,
7813 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7814 wake_mask_size);
7815 if (tok) {
7816 cfg->tokens_size = tokens_size;
7817 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7818 }
7819
7820 trig->tcp = cfg;
7821
7822 return 0;
7823}
7824
Johannes Bergff1b6e62011-05-04 15:37:28 +02007825static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7826{
7827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7828 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007829 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007830 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007831 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007832 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007833 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007834
Johannes Berg964dc9e2013-06-03 17:25:34 +02007835 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007836 return -EOPNOTSUPP;
7837
Johannes Bergae33bd82012-07-12 16:25:02 +02007838 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7839 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007840 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007841 goto set_wakeup;
7842 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007843
7844 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7845 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7846 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7847 nl80211_wowlan_policy);
7848 if (err)
7849 return err;
7850
7851 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7852 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7853 return -EINVAL;
7854 new_triggers.any = true;
7855 }
7856
7857 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7858 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7859 return -EINVAL;
7860 new_triggers.disconnect = true;
7861 }
7862
7863 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7864 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7865 return -EINVAL;
7866 new_triggers.magic_pkt = true;
7867 }
7868
Johannes Berg77dbbb132011-07-13 10:48:55 +02007869 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7870 return -EINVAL;
7871
7872 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7873 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7874 return -EINVAL;
7875 new_triggers.gtk_rekey_failure = true;
7876 }
7877
7878 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7879 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7880 return -EINVAL;
7881 new_triggers.eap_identity_req = true;
7882 }
7883
7884 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7885 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7886 return -EINVAL;
7887 new_triggers.four_way_handshake = true;
7888 }
7889
7890 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7891 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7892 return -EINVAL;
7893 new_triggers.rfkill_release = true;
7894 }
7895
Johannes Bergff1b6e62011-05-04 15:37:28 +02007896 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7897 struct nlattr *pat;
7898 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007899 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007900 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7901
7902 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7903 rem)
7904 n_patterns++;
7905 if (n_patterns > wowlan->n_patterns)
7906 return -EINVAL;
7907
7908 new_triggers.patterns = kcalloc(n_patterns,
7909 sizeof(new_triggers.patterns[0]),
7910 GFP_KERNEL);
7911 if (!new_triggers.patterns)
7912 return -ENOMEM;
7913
7914 new_triggers.n_patterns = n_patterns;
7915 i = 0;
7916
7917 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7918 rem) {
7919 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7920 nla_data(pat), nla_len(pat), NULL);
7921 err = -EINVAL;
7922 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7923 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7924 goto error;
7925 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7926 mask_len = DIV_ROUND_UP(pat_len, 8);
7927 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7928 mask_len)
7929 goto error;
7930 if (pat_len > wowlan->pattern_max_len ||
7931 pat_len < wowlan->pattern_min_len)
7932 goto error;
7933
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007934 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7935 pkt_offset = 0;
7936 else
7937 pkt_offset = nla_get_u32(
7938 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7939 if (pkt_offset > wowlan->max_pkt_offset)
7940 goto error;
7941 new_triggers.patterns[i].pkt_offset = pkt_offset;
7942
Johannes Bergff1b6e62011-05-04 15:37:28 +02007943 new_triggers.patterns[i].mask =
7944 kmalloc(mask_len + pat_len, GFP_KERNEL);
7945 if (!new_triggers.patterns[i].mask) {
7946 err = -ENOMEM;
7947 goto error;
7948 }
7949 new_triggers.patterns[i].pattern =
7950 new_triggers.patterns[i].mask + mask_len;
7951 memcpy(new_triggers.patterns[i].mask,
7952 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7953 mask_len);
7954 new_triggers.patterns[i].pattern_len = pat_len;
7955 memcpy(new_triggers.patterns[i].pattern,
7956 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7957 pat_len);
7958 i++;
7959 }
7960 }
7961
Johannes Berg2a0e0472013-01-23 22:57:40 +01007962 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7963 err = nl80211_parse_wowlan_tcp(
7964 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7965 &new_triggers);
7966 if (err)
7967 goto error;
7968 }
7969
Johannes Bergae33bd82012-07-12 16:25:02 +02007970 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7971 if (!ntrig) {
7972 err = -ENOMEM;
7973 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007974 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007975 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007976 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007977
Johannes Bergae33bd82012-07-12 16:25:02 +02007978 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007979 if (rdev->ops->set_wakeup &&
7980 prev_enabled != !!rdev->wiphy.wowlan_config)
7981 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02007982
Johannes Bergff1b6e62011-05-04 15:37:28 +02007983 return 0;
7984 error:
7985 for (i = 0; i < new_triggers.n_patterns; i++)
7986 kfree(new_triggers.patterns[i].mask);
7987 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007988 if (new_triggers.tcp && new_triggers.tcp->sock)
7989 sock_release(new_triggers.tcp->sock);
7990 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007991 return err;
7992}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007993#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007994
Johannes Berge5497d72011-07-05 16:35:40 +02007995static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7996{
7997 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7998 struct net_device *dev = info->user_ptr[1];
7999 struct wireless_dev *wdev = dev->ieee80211_ptr;
8000 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8001 struct cfg80211_gtk_rekey_data rekey_data;
8002 int err;
8003
8004 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8005 return -EINVAL;
8006
8007 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8008 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8009 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8010 nl80211_rekey_policy);
8011 if (err)
8012 return err;
8013
8014 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8015 return -ERANGE;
8016 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8017 return -ERANGE;
8018 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8019 return -ERANGE;
8020
8021 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8022 NL80211_KEK_LEN);
8023 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8024 NL80211_KCK_LEN);
8025 memcpy(rekey_data.replay_ctr,
8026 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8027 NL80211_REPLAY_CTR_LEN);
8028
8029 wdev_lock(wdev);
8030 if (!wdev->current_bss) {
8031 err = -ENOTCONN;
8032 goto out;
8033 }
8034
8035 if (!rdev->ops->set_rekey_data) {
8036 err = -EOPNOTSUPP;
8037 goto out;
8038 }
8039
Hila Gonene35e4d22012-06-27 17:19:42 +03008040 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008041 out:
8042 wdev_unlock(wdev);
8043 return err;
8044}
8045
Johannes Berg28946da2011-11-04 11:18:12 +01008046static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8047 struct genl_info *info)
8048{
8049 struct net_device *dev = info->user_ptr[1];
8050 struct wireless_dev *wdev = dev->ieee80211_ptr;
8051
8052 if (wdev->iftype != NL80211_IFTYPE_AP &&
8053 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8054 return -EINVAL;
8055
Eric W. Biederman15e47302012-09-07 20:12:54 +00008056 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008057 return -EBUSY;
8058
Eric W. Biederman15e47302012-09-07 20:12:54 +00008059 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008060 return 0;
8061}
8062
Johannes Berg7f6cf312011-11-04 11:18:15 +01008063static int nl80211_probe_client(struct sk_buff *skb,
8064 struct genl_info *info)
8065{
8066 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8067 struct net_device *dev = info->user_ptr[1];
8068 struct wireless_dev *wdev = dev->ieee80211_ptr;
8069 struct sk_buff *msg;
8070 void *hdr;
8071 const u8 *addr;
8072 u64 cookie;
8073 int err;
8074
8075 if (wdev->iftype != NL80211_IFTYPE_AP &&
8076 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8077 return -EOPNOTSUPP;
8078
8079 if (!info->attrs[NL80211_ATTR_MAC])
8080 return -EINVAL;
8081
8082 if (!rdev->ops->probe_client)
8083 return -EOPNOTSUPP;
8084
8085 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8086 if (!msg)
8087 return -ENOMEM;
8088
Eric W. Biederman15e47302012-09-07 20:12:54 +00008089 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008090 NL80211_CMD_PROBE_CLIENT);
8091
8092 if (IS_ERR(hdr)) {
8093 err = PTR_ERR(hdr);
8094 goto free_msg;
8095 }
8096
8097 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8098
Hila Gonene35e4d22012-06-27 17:19:42 +03008099 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008100 if (err)
8101 goto free_msg;
8102
David S. Miller9360ffd2012-03-29 04:41:26 -04008103 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8104 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008105
8106 genlmsg_end(msg, hdr);
8107
8108 return genlmsg_reply(msg, info);
8109
8110 nla_put_failure:
8111 err = -ENOBUFS;
8112 free_msg:
8113 nlmsg_free(msg);
8114 return err;
8115}
8116
Johannes Berg5e760232011-11-04 11:18:17 +01008117static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8118{
8119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008120 struct cfg80211_beacon_registration *reg, *nreg;
8121 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008122
8123 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8124 return -EOPNOTSUPP;
8125
Ben Greear37c73b52012-10-26 14:49:25 -07008126 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8127 if (!nreg)
8128 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008129
Ben Greear37c73b52012-10-26 14:49:25 -07008130 /* First, check if already registered. */
8131 spin_lock_bh(&rdev->beacon_registrations_lock);
8132 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8133 if (reg->nlportid == info->snd_portid) {
8134 rv = -EALREADY;
8135 goto out_err;
8136 }
8137 }
8138 /* Add it to the list */
8139 nreg->nlportid = info->snd_portid;
8140 list_add(&nreg->list, &rdev->beacon_registrations);
8141
8142 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008143
8144 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008145out_err:
8146 spin_unlock_bh(&rdev->beacon_registrations_lock);
8147 kfree(nreg);
8148 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008149}
8150
Johannes Berg98104fde2012-06-16 00:19:54 +02008151static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8152{
8153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8154 struct wireless_dev *wdev = info->user_ptr[1];
8155 int err;
8156
8157 if (!rdev->ops->start_p2p_device)
8158 return -EOPNOTSUPP;
8159
8160 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8161 return -EOPNOTSUPP;
8162
8163 if (wdev->p2p_started)
8164 return 0;
8165
Johannes Berg98104fde2012-06-16 00:19:54 +02008166 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008167 if (err)
8168 return err;
8169
Johannes Bergeeb126e2012-10-23 15:16:50 +02008170 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008171 if (err)
8172 return err;
8173
8174 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008175 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008176
8177 return 0;
8178}
8179
8180static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8181{
8182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8183 struct wireless_dev *wdev = info->user_ptr[1];
8184
8185 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8186 return -EOPNOTSUPP;
8187
8188 if (!rdev->ops->stop_p2p_device)
8189 return -EOPNOTSUPP;
8190
Johannes Bergf9f47522013-03-19 15:04:07 +01008191 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008192
8193 return 0;
8194}
8195
Johannes Berg3713b4e2013-02-14 16:19:38 +01008196static int nl80211_get_protocol_features(struct sk_buff *skb,
8197 struct genl_info *info)
8198{
8199 void *hdr;
8200 struct sk_buff *msg;
8201
8202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8203 if (!msg)
8204 return -ENOMEM;
8205
8206 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8207 NL80211_CMD_GET_PROTOCOL_FEATURES);
8208 if (!hdr)
8209 goto nla_put_failure;
8210
8211 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8212 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8213 goto nla_put_failure;
8214
8215 genlmsg_end(msg, hdr);
8216 return genlmsg_reply(msg, info);
8217
8218 nla_put_failure:
8219 kfree_skb(msg);
8220 return -ENOBUFS;
8221}
8222
Jouni Malinen355199e2013-02-27 17:14:27 +02008223static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8224{
8225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8226 struct cfg80211_update_ft_ies_params ft_params;
8227 struct net_device *dev = info->user_ptr[1];
8228
8229 if (!rdev->ops->update_ft_ies)
8230 return -EOPNOTSUPP;
8231
8232 if (!info->attrs[NL80211_ATTR_MDID] ||
8233 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8234 return -EINVAL;
8235
8236 memset(&ft_params, 0, sizeof(ft_params));
8237 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8238 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8239 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8240
8241 return rdev_update_ft_ies(rdev, dev, &ft_params);
8242}
8243
Arend van Spriel5de17982013-04-18 15:49:00 +02008244static int nl80211_crit_protocol_start(struct sk_buff *skb,
8245 struct genl_info *info)
8246{
8247 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8248 struct wireless_dev *wdev = info->user_ptr[1];
8249 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8250 u16 duration;
8251 int ret;
8252
8253 if (!rdev->ops->crit_proto_start)
8254 return -EOPNOTSUPP;
8255
8256 if (WARN_ON(!rdev->ops->crit_proto_stop))
8257 return -EINVAL;
8258
8259 if (rdev->crit_proto_nlportid)
8260 return -EBUSY;
8261
8262 /* determine protocol if provided */
8263 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8264 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8265
8266 if (proto >= NUM_NL80211_CRIT_PROTO)
8267 return -EINVAL;
8268
8269 /* timeout must be provided */
8270 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8271 return -EINVAL;
8272
8273 duration =
8274 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8275
8276 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8277 return -ERANGE;
8278
8279 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8280 if (!ret)
8281 rdev->crit_proto_nlportid = info->snd_portid;
8282
8283 return ret;
8284}
8285
8286static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8287 struct genl_info *info)
8288{
8289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8290 struct wireless_dev *wdev = info->user_ptr[1];
8291
8292 if (!rdev->ops->crit_proto_stop)
8293 return -EOPNOTSUPP;
8294
8295 if (rdev->crit_proto_nlportid) {
8296 rdev->crit_proto_nlportid = 0;
8297 rdev_crit_proto_stop(rdev, wdev);
8298 }
8299 return 0;
8300}
8301
Johannes Berg4c476992010-10-04 21:36:35 +02008302#define NL80211_FLAG_NEED_WIPHY 0x01
8303#define NL80211_FLAG_NEED_NETDEV 0x02
8304#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008305#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8306#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8307 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008308#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008309/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008310#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8311 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008312
8313static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8314 struct genl_info *info)
8315{
8316 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008317 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008318 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008319 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8320
8321 if (rtnl)
8322 rtnl_lock();
8323
8324 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008325 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008326 if (IS_ERR(rdev)) {
8327 if (rtnl)
8328 rtnl_unlock();
8329 return PTR_ERR(rdev);
8330 }
8331 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008332 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8333 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008334 ASSERT_RTNL();
8335
Johannes Berg89a54e42012-06-15 14:33:17 +02008336 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8337 info->attrs);
8338 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008339 if (rtnl)
8340 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008341 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008342 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008343
Johannes Berg89a54e42012-06-15 14:33:17 +02008344 dev = wdev->netdev;
8345 rdev = wiphy_to_dev(wdev->wiphy);
8346
Johannes Berg1bf614e2012-06-15 15:23:36 +02008347 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8348 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008349 if (rtnl)
8350 rtnl_unlock();
8351 return -EINVAL;
8352 }
8353
8354 info->user_ptr[1] = dev;
8355 } else {
8356 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008357 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008358
Johannes Berg1bf614e2012-06-15 15:23:36 +02008359 if (dev) {
8360 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8361 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008362 if (rtnl)
8363 rtnl_unlock();
8364 return -ENETDOWN;
8365 }
8366
8367 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008368 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8369 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008370 if (rtnl)
8371 rtnl_unlock();
8372 return -ENETDOWN;
8373 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008374 }
8375
Johannes Berg4c476992010-10-04 21:36:35 +02008376 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008377 }
8378
8379 return 0;
8380}
8381
8382static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8383 struct genl_info *info)
8384{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008385 if (info->user_ptr[1]) {
8386 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8387 struct wireless_dev *wdev = info->user_ptr[1];
8388
8389 if (wdev->netdev)
8390 dev_put(wdev->netdev);
8391 } else {
8392 dev_put(info->user_ptr[1]);
8393 }
8394 }
Johannes Berg4c476992010-10-04 21:36:35 +02008395 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8396 rtnl_unlock();
8397}
8398
Johannes Berg55682962007-09-20 13:09:35 -04008399static struct genl_ops nl80211_ops[] = {
8400 {
8401 .cmd = NL80211_CMD_GET_WIPHY,
8402 .doit = nl80211_get_wiphy,
8403 .dumpit = nl80211_dump_wiphy,
8404 .policy = nl80211_policy,
8405 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008406 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8407 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008408 },
8409 {
8410 .cmd = NL80211_CMD_SET_WIPHY,
8411 .doit = nl80211_set_wiphy,
8412 .policy = nl80211_policy,
8413 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008414 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008415 },
8416 {
8417 .cmd = NL80211_CMD_GET_INTERFACE,
8418 .doit = nl80211_get_interface,
8419 .dumpit = nl80211_dump_interface,
8420 .policy = nl80211_policy,
8421 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008422 .internal_flags = NL80211_FLAG_NEED_WDEV |
8423 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008424 },
8425 {
8426 .cmd = NL80211_CMD_SET_INTERFACE,
8427 .doit = nl80211_set_interface,
8428 .policy = nl80211_policy,
8429 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008430 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8431 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008432 },
8433 {
8434 .cmd = NL80211_CMD_NEW_INTERFACE,
8435 .doit = nl80211_new_interface,
8436 .policy = nl80211_policy,
8437 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008438 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8439 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008440 },
8441 {
8442 .cmd = NL80211_CMD_DEL_INTERFACE,
8443 .doit = nl80211_del_interface,
8444 .policy = nl80211_policy,
8445 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008446 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008447 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008448 },
Johannes Berg41ade002007-12-19 02:03:29 +01008449 {
8450 .cmd = NL80211_CMD_GET_KEY,
8451 .doit = nl80211_get_key,
8452 .policy = nl80211_policy,
8453 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008454 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008455 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008456 },
8457 {
8458 .cmd = NL80211_CMD_SET_KEY,
8459 .doit = nl80211_set_key,
8460 .policy = nl80211_policy,
8461 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008462 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008463 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008464 },
8465 {
8466 .cmd = NL80211_CMD_NEW_KEY,
8467 .doit = nl80211_new_key,
8468 .policy = nl80211_policy,
8469 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008470 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008471 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008472 },
8473 {
8474 .cmd = NL80211_CMD_DEL_KEY,
8475 .doit = nl80211_del_key,
8476 .policy = nl80211_policy,
8477 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008479 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008480 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008481 {
8482 .cmd = NL80211_CMD_SET_BEACON,
8483 .policy = nl80211_policy,
8484 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008485 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008486 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008487 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008488 },
8489 {
Johannes Berg88600202012-02-13 15:17:18 +01008490 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008491 .policy = nl80211_policy,
8492 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008493 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008494 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008495 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008496 },
8497 {
Johannes Berg88600202012-02-13 15:17:18 +01008498 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008501 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008502 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008503 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008504 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008505 {
8506 .cmd = NL80211_CMD_GET_STATION,
8507 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008508 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008509 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008510 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8511 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008512 },
8513 {
8514 .cmd = NL80211_CMD_SET_STATION,
8515 .doit = nl80211_set_station,
8516 .policy = nl80211_policy,
8517 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008518 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008519 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008520 },
8521 {
8522 .cmd = NL80211_CMD_NEW_STATION,
8523 .doit = nl80211_new_station,
8524 .policy = nl80211_policy,
8525 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008526 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008527 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008528 },
8529 {
8530 .cmd = NL80211_CMD_DEL_STATION,
8531 .doit = nl80211_del_station,
8532 .policy = nl80211_policy,
8533 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008534 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008535 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008536 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008537 {
8538 .cmd = NL80211_CMD_GET_MPATH,
8539 .doit = nl80211_get_mpath,
8540 .dumpit = nl80211_dump_mpath,
8541 .policy = nl80211_policy,
8542 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008543 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008544 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008545 },
8546 {
8547 .cmd = NL80211_CMD_SET_MPATH,
8548 .doit = nl80211_set_mpath,
8549 .policy = nl80211_policy,
8550 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008551 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008552 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008553 },
8554 {
8555 .cmd = NL80211_CMD_NEW_MPATH,
8556 .doit = nl80211_new_mpath,
8557 .policy = nl80211_policy,
8558 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008559 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008560 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008561 },
8562 {
8563 .cmd = NL80211_CMD_DEL_MPATH,
8564 .doit = nl80211_del_mpath,
8565 .policy = nl80211_policy,
8566 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008567 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008568 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008569 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008570 {
8571 .cmd = NL80211_CMD_SET_BSS,
8572 .doit = nl80211_set_bss,
8573 .policy = nl80211_policy,
8574 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008575 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008576 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008577 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008578 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008579 .cmd = NL80211_CMD_GET_REG,
8580 .doit = nl80211_get_reg,
8581 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008582 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008583 /* can be retrieved by unprivileged users */
8584 },
8585 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008586 .cmd = NL80211_CMD_SET_REG,
8587 .doit = nl80211_set_reg,
8588 .policy = nl80211_policy,
8589 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008590 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008591 },
8592 {
8593 .cmd = NL80211_CMD_REQ_SET_REG,
8594 .doit = nl80211_req_set_reg,
8595 .policy = nl80211_policy,
8596 .flags = GENL_ADMIN_PERM,
8597 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008598 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008599 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8600 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008601 .policy = nl80211_policy,
8602 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008604 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008605 },
8606 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008607 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8608 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008609 .policy = nl80211_policy,
8610 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008612 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008613 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008614 {
Johannes Berg2a519312009-02-10 21:25:55 +01008615 .cmd = NL80211_CMD_TRIGGER_SCAN,
8616 .doit = nl80211_trigger_scan,
8617 .policy = nl80211_policy,
8618 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008619 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008620 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008621 },
8622 {
8623 .cmd = NL80211_CMD_GET_SCAN,
8624 .policy = nl80211_policy,
8625 .dumpit = nl80211_dump_scan,
8626 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008627 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008628 .cmd = NL80211_CMD_START_SCHED_SCAN,
8629 .doit = nl80211_start_sched_scan,
8630 .policy = nl80211_policy,
8631 .flags = GENL_ADMIN_PERM,
8632 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8633 NL80211_FLAG_NEED_RTNL,
8634 },
8635 {
8636 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8637 .doit = nl80211_stop_sched_scan,
8638 .policy = nl80211_policy,
8639 .flags = GENL_ADMIN_PERM,
8640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8641 NL80211_FLAG_NEED_RTNL,
8642 },
8643 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008644 .cmd = NL80211_CMD_AUTHENTICATE,
8645 .doit = nl80211_authenticate,
8646 .policy = nl80211_policy,
8647 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008648 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008649 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008650 },
8651 {
8652 .cmd = NL80211_CMD_ASSOCIATE,
8653 .doit = nl80211_associate,
8654 .policy = nl80211_policy,
8655 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008656 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008657 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008658 },
8659 {
8660 .cmd = NL80211_CMD_DEAUTHENTICATE,
8661 .doit = nl80211_deauthenticate,
8662 .policy = nl80211_policy,
8663 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008665 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008666 },
8667 {
8668 .cmd = NL80211_CMD_DISASSOCIATE,
8669 .doit = nl80211_disassociate,
8670 .policy = nl80211_policy,
8671 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008673 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008674 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008675 {
8676 .cmd = NL80211_CMD_JOIN_IBSS,
8677 .doit = nl80211_join_ibss,
8678 .policy = nl80211_policy,
8679 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008680 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008681 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008682 },
8683 {
8684 .cmd = NL80211_CMD_LEAVE_IBSS,
8685 .doit = nl80211_leave_ibss,
8686 .policy = nl80211_policy,
8687 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008689 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008690 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008691#ifdef CONFIG_NL80211_TESTMODE
8692 {
8693 .cmd = NL80211_CMD_TESTMODE,
8694 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008695 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008696 .policy = nl80211_policy,
8697 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008698 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8699 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008700 },
8701#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008702 {
8703 .cmd = NL80211_CMD_CONNECT,
8704 .doit = nl80211_connect,
8705 .policy = nl80211_policy,
8706 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008708 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008709 },
8710 {
8711 .cmd = NL80211_CMD_DISCONNECT,
8712 .doit = nl80211_disconnect,
8713 .policy = nl80211_policy,
8714 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008715 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008716 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008717 },
Johannes Berg463d0182009-07-14 00:33:35 +02008718 {
8719 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8720 .doit = nl80211_wiphy_netns,
8721 .policy = nl80211_policy,
8722 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008723 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8724 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008725 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008726 {
8727 .cmd = NL80211_CMD_GET_SURVEY,
8728 .policy = nl80211_policy,
8729 .dumpit = nl80211_dump_survey,
8730 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008731 {
8732 .cmd = NL80211_CMD_SET_PMKSA,
8733 .doit = nl80211_setdel_pmksa,
8734 .policy = nl80211_policy,
8735 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008737 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008738 },
8739 {
8740 .cmd = NL80211_CMD_DEL_PMKSA,
8741 .doit = nl80211_setdel_pmksa,
8742 .policy = nl80211_policy,
8743 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008745 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008746 },
8747 {
8748 .cmd = NL80211_CMD_FLUSH_PMKSA,
8749 .doit = nl80211_flush_pmksa,
8750 .policy = nl80211_policy,
8751 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008753 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008754 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008755 {
8756 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8757 .doit = nl80211_remain_on_channel,
8758 .policy = nl80211_policy,
8759 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008760 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008761 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008762 },
8763 {
8764 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8765 .doit = nl80211_cancel_remain_on_channel,
8766 .policy = nl80211_policy,
8767 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008768 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008769 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008770 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008771 {
8772 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8773 .doit = nl80211_set_tx_bitrate_mask,
8774 .policy = nl80211_policy,
8775 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008776 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8777 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008778 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008779 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008780 .cmd = NL80211_CMD_REGISTER_FRAME,
8781 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008782 .policy = nl80211_policy,
8783 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008784 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008785 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008786 },
8787 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008788 .cmd = NL80211_CMD_FRAME,
8789 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008790 .policy = nl80211_policy,
8791 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008792 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008793 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008794 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008795 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008796 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8797 .doit = nl80211_tx_mgmt_cancel_wait,
8798 .policy = nl80211_policy,
8799 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008800 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008801 NL80211_FLAG_NEED_RTNL,
8802 },
8803 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008804 .cmd = NL80211_CMD_SET_POWER_SAVE,
8805 .doit = nl80211_set_power_save,
8806 .policy = nl80211_policy,
8807 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008808 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8809 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008810 },
8811 {
8812 .cmd = NL80211_CMD_GET_POWER_SAVE,
8813 .doit = nl80211_get_power_save,
8814 .policy = nl80211_policy,
8815 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008816 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8817 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008818 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008819 {
8820 .cmd = NL80211_CMD_SET_CQM,
8821 .doit = nl80211_set_cqm,
8822 .policy = nl80211_policy,
8823 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008824 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8825 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008826 },
Johannes Bergf444de02010-05-05 15:25:02 +02008827 {
8828 .cmd = NL80211_CMD_SET_CHANNEL,
8829 .doit = nl80211_set_channel,
8830 .policy = nl80211_policy,
8831 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008832 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8833 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008834 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008835 {
8836 .cmd = NL80211_CMD_SET_WDS_PEER,
8837 .doit = nl80211_set_wds_peer,
8838 .policy = nl80211_policy,
8839 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008840 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8841 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008842 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008843 {
8844 .cmd = NL80211_CMD_JOIN_MESH,
8845 .doit = nl80211_join_mesh,
8846 .policy = nl80211_policy,
8847 .flags = GENL_ADMIN_PERM,
8848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8849 NL80211_FLAG_NEED_RTNL,
8850 },
8851 {
8852 .cmd = NL80211_CMD_LEAVE_MESH,
8853 .doit = nl80211_leave_mesh,
8854 .policy = nl80211_policy,
8855 .flags = GENL_ADMIN_PERM,
8856 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8857 NL80211_FLAG_NEED_RTNL,
8858 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008859#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008860 {
8861 .cmd = NL80211_CMD_GET_WOWLAN,
8862 .doit = nl80211_get_wowlan,
8863 .policy = nl80211_policy,
8864 /* can be retrieved by unprivileged users */
8865 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8866 NL80211_FLAG_NEED_RTNL,
8867 },
8868 {
8869 .cmd = NL80211_CMD_SET_WOWLAN,
8870 .doit = nl80211_set_wowlan,
8871 .policy = nl80211_policy,
8872 .flags = GENL_ADMIN_PERM,
8873 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8874 NL80211_FLAG_NEED_RTNL,
8875 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008876#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008877 {
8878 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8879 .doit = nl80211_set_rekey_data,
8880 .policy = nl80211_policy,
8881 .flags = GENL_ADMIN_PERM,
8882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8883 NL80211_FLAG_NEED_RTNL,
8884 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008885 {
8886 .cmd = NL80211_CMD_TDLS_MGMT,
8887 .doit = nl80211_tdls_mgmt,
8888 .policy = nl80211_policy,
8889 .flags = GENL_ADMIN_PERM,
8890 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8891 NL80211_FLAG_NEED_RTNL,
8892 },
8893 {
8894 .cmd = NL80211_CMD_TDLS_OPER,
8895 .doit = nl80211_tdls_oper,
8896 .policy = nl80211_policy,
8897 .flags = GENL_ADMIN_PERM,
8898 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8899 NL80211_FLAG_NEED_RTNL,
8900 },
Johannes Berg28946da2011-11-04 11:18:12 +01008901 {
8902 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8903 .doit = nl80211_register_unexpected_frame,
8904 .policy = nl80211_policy,
8905 .flags = GENL_ADMIN_PERM,
8906 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8907 NL80211_FLAG_NEED_RTNL,
8908 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008909 {
8910 .cmd = NL80211_CMD_PROBE_CLIENT,
8911 .doit = nl80211_probe_client,
8912 .policy = nl80211_policy,
8913 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008914 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008915 NL80211_FLAG_NEED_RTNL,
8916 },
Johannes Berg5e760232011-11-04 11:18:17 +01008917 {
8918 .cmd = NL80211_CMD_REGISTER_BEACONS,
8919 .doit = nl80211_register_beacons,
8920 .policy = nl80211_policy,
8921 .flags = GENL_ADMIN_PERM,
8922 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8923 NL80211_FLAG_NEED_RTNL,
8924 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008925 {
8926 .cmd = NL80211_CMD_SET_NOACK_MAP,
8927 .doit = nl80211_set_noack_map,
8928 .policy = nl80211_policy,
8929 .flags = GENL_ADMIN_PERM,
8930 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8931 NL80211_FLAG_NEED_RTNL,
8932 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008933 {
8934 .cmd = NL80211_CMD_START_P2P_DEVICE,
8935 .doit = nl80211_start_p2p_device,
8936 .policy = nl80211_policy,
8937 .flags = GENL_ADMIN_PERM,
8938 .internal_flags = NL80211_FLAG_NEED_WDEV |
8939 NL80211_FLAG_NEED_RTNL,
8940 },
8941 {
8942 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8943 .doit = nl80211_stop_p2p_device,
8944 .policy = nl80211_policy,
8945 .flags = GENL_ADMIN_PERM,
8946 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8947 NL80211_FLAG_NEED_RTNL,
8948 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008949 {
8950 .cmd = NL80211_CMD_SET_MCAST_RATE,
8951 .doit = nl80211_set_mcast_rate,
8952 .policy = nl80211_policy,
8953 .flags = GENL_ADMIN_PERM,
8954 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8955 NL80211_FLAG_NEED_RTNL,
8956 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308957 {
8958 .cmd = NL80211_CMD_SET_MAC_ACL,
8959 .doit = nl80211_set_mac_acl,
8960 .policy = nl80211_policy,
8961 .flags = GENL_ADMIN_PERM,
8962 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8963 NL80211_FLAG_NEED_RTNL,
8964 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008965 {
8966 .cmd = NL80211_CMD_RADAR_DETECT,
8967 .doit = nl80211_start_radar_detection,
8968 .policy = nl80211_policy,
8969 .flags = GENL_ADMIN_PERM,
8970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8971 NL80211_FLAG_NEED_RTNL,
8972 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008973 {
8974 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8975 .doit = nl80211_get_protocol_features,
8976 .policy = nl80211_policy,
8977 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008978 {
8979 .cmd = NL80211_CMD_UPDATE_FT_IES,
8980 .doit = nl80211_update_ft_ies,
8981 .policy = nl80211_policy,
8982 .flags = GENL_ADMIN_PERM,
8983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8984 NL80211_FLAG_NEED_RTNL,
8985 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008986 {
8987 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8988 .doit = nl80211_crit_protocol_start,
8989 .policy = nl80211_policy,
8990 .flags = GENL_ADMIN_PERM,
8991 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8992 NL80211_FLAG_NEED_RTNL,
8993 },
8994 {
8995 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
8996 .doit = nl80211_crit_protocol_stop,
8997 .policy = nl80211_policy,
8998 .flags = GENL_ADMIN_PERM,
8999 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9000 NL80211_FLAG_NEED_RTNL,
9001 }
Johannes Berg55682962007-09-20 13:09:35 -04009002};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009003
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009004static struct genl_multicast_group nl80211_mlme_mcgrp = {
9005 .name = "mlme",
9006};
Johannes Berg55682962007-09-20 13:09:35 -04009007
9008/* multicast groups */
9009static struct genl_multicast_group nl80211_config_mcgrp = {
9010 .name = "config",
9011};
Johannes Berg2a519312009-02-10 21:25:55 +01009012static struct genl_multicast_group nl80211_scan_mcgrp = {
9013 .name = "scan",
9014};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009015static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9016 .name = "regulatory",
9017};
Johannes Berg55682962007-09-20 13:09:35 -04009018
9019/* notification functions */
9020
9021void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9022{
9023 struct sk_buff *msg;
9024
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009025 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009026 if (!msg)
9027 return;
9028
Johannes Berg3713b4e2013-02-14 16:19:38 +01009029 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
9030 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009031 nlmsg_free(msg);
9032 return;
9033 }
9034
Johannes Berg463d0182009-07-14 00:33:35 +02009035 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9036 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009037}
9038
Johannes Berg362a4152009-05-24 16:43:15 +02009039static int nl80211_add_scan_req(struct sk_buff *msg,
9040 struct cfg80211_registered_device *rdev)
9041{
9042 struct cfg80211_scan_request *req = rdev->scan_req;
9043 struct nlattr *nest;
9044 int i;
9045
9046 if (WARN_ON(!req))
9047 return 0;
9048
9049 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9050 if (!nest)
9051 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009052 for (i = 0; i < req->n_ssids; i++) {
9053 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9054 goto nla_put_failure;
9055 }
Johannes Berg362a4152009-05-24 16:43:15 +02009056 nla_nest_end(msg, nest);
9057
9058 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9059 if (!nest)
9060 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009061 for (i = 0; i < req->n_channels; i++) {
9062 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9063 goto nla_put_failure;
9064 }
Johannes Berg362a4152009-05-24 16:43:15 +02009065 nla_nest_end(msg, nest);
9066
David S. Miller9360ffd2012-03-29 04:41:26 -04009067 if (req->ie &&
9068 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9069 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009070
Sam Lefflered4737712012-10-11 21:03:31 -07009071 if (req->flags)
9072 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9073
Johannes Berg362a4152009-05-24 16:43:15 +02009074 return 0;
9075 nla_put_failure:
9076 return -ENOBUFS;
9077}
9078
Johannes Berga538e2d2009-06-16 19:56:42 +02009079static int nl80211_send_scan_msg(struct sk_buff *msg,
9080 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009081 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009082 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009083 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009084{
9085 void *hdr;
9086
Eric W. Biederman15e47302012-09-07 20:12:54 +00009087 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009088 if (!hdr)
9089 return -1;
9090
David S. Miller9360ffd2012-03-29 04:41:26 -04009091 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009092 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9093 wdev->netdev->ifindex)) ||
9094 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009095 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009096
Johannes Berg362a4152009-05-24 16:43:15 +02009097 /* ignore errors and send incomplete event anyway */
9098 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009099
9100 return genlmsg_end(msg, hdr);
9101
9102 nla_put_failure:
9103 genlmsg_cancel(msg, hdr);
9104 return -EMSGSIZE;
9105}
9106
Luciano Coelho807f8a82011-05-11 17:09:35 +03009107static int
9108nl80211_send_sched_scan_msg(struct sk_buff *msg,
9109 struct cfg80211_registered_device *rdev,
9110 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009111 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009112{
9113 void *hdr;
9114
Eric W. Biederman15e47302012-09-07 20:12:54 +00009115 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009116 if (!hdr)
9117 return -1;
9118
David S. Miller9360ffd2012-03-29 04:41:26 -04009119 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9120 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9121 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009122
9123 return genlmsg_end(msg, hdr);
9124
9125 nla_put_failure:
9126 genlmsg_cancel(msg, hdr);
9127 return -EMSGSIZE;
9128}
9129
Johannes Berga538e2d2009-06-16 19:56:42 +02009130void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009131 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009132{
9133 struct sk_buff *msg;
9134
Thomas Graf58050fc2012-06-28 03:57:45 +00009135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009136 if (!msg)
9137 return;
9138
Johannes Bergfd014282012-06-18 19:17:03 +02009139 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009140 NL80211_CMD_TRIGGER_SCAN) < 0) {
9141 nlmsg_free(msg);
9142 return;
9143 }
9144
Johannes Berg463d0182009-07-14 00:33:35 +02009145 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9146 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009147}
9148
Johannes Berg2a519312009-02-10 21:25:55 +01009149void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009150 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009151{
9152 struct sk_buff *msg;
9153
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009155 if (!msg)
9156 return;
9157
Johannes Bergfd014282012-06-18 19:17:03 +02009158 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009159 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009160 nlmsg_free(msg);
9161 return;
9162 }
9163
Johannes Berg463d0182009-07-14 00:33:35 +02009164 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9165 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009166}
9167
9168void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009169 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009170{
9171 struct sk_buff *msg;
9172
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009173 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009174 if (!msg)
9175 return;
9176
Johannes Bergfd014282012-06-18 19:17:03 +02009177 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009178 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009179 nlmsg_free(msg);
9180 return;
9181 }
9182
Johannes Berg463d0182009-07-14 00:33:35 +02009183 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9184 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009185}
9186
Luciano Coelho807f8a82011-05-11 17:09:35 +03009187void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9188 struct net_device *netdev)
9189{
9190 struct sk_buff *msg;
9191
9192 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9193 if (!msg)
9194 return;
9195
9196 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9197 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9198 nlmsg_free(msg);
9199 return;
9200 }
9201
9202 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9203 nl80211_scan_mcgrp.id, GFP_KERNEL);
9204}
9205
9206void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9207 struct net_device *netdev, u32 cmd)
9208{
9209 struct sk_buff *msg;
9210
Thomas Graf58050fc2012-06-28 03:57:45 +00009211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009212 if (!msg)
9213 return;
9214
9215 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9216 nlmsg_free(msg);
9217 return;
9218 }
9219
9220 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9221 nl80211_scan_mcgrp.id, GFP_KERNEL);
9222}
9223
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009224/*
9225 * This can happen on global regulatory changes or device specific settings
9226 * based on custom world regulatory domains.
9227 */
9228void nl80211_send_reg_change_event(struct regulatory_request *request)
9229{
9230 struct sk_buff *msg;
9231 void *hdr;
9232
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009233 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009234 if (!msg)
9235 return;
9236
9237 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9238 if (!hdr) {
9239 nlmsg_free(msg);
9240 return;
9241 }
9242
9243 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009244 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9245 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009246
David S. Miller9360ffd2012-03-29 04:41:26 -04009247 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9248 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9249 NL80211_REGDOM_TYPE_WORLD))
9250 goto nla_put_failure;
9251 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9252 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9253 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9254 goto nla_put_failure;
9255 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9256 request->intersect) {
9257 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9258 NL80211_REGDOM_TYPE_INTERSECTION))
9259 goto nla_put_failure;
9260 } else {
9261 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9262 NL80211_REGDOM_TYPE_COUNTRY) ||
9263 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9264 request->alpha2))
9265 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009266 }
9267
Johannes Bergf4173762012-12-03 18:23:37 +01009268 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009269 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9270 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009271
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009272 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009273
Johannes Bergbc43b282009-07-25 10:54:13 +02009274 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009275 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009276 GFP_ATOMIC);
9277 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009278
9279 return;
9280
9281nla_put_failure:
9282 genlmsg_cancel(msg, hdr);
9283 nlmsg_free(msg);
9284}
9285
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009286static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9287 struct net_device *netdev,
9288 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009289 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009290{
9291 struct sk_buff *msg;
9292 void *hdr;
9293
Johannes Berge6d6e342009-07-01 21:26:47 +02009294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009295 if (!msg)
9296 return;
9297
9298 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9299 if (!hdr) {
9300 nlmsg_free(msg);
9301 return;
9302 }
9303
David S. Miller9360ffd2012-03-29 04:41:26 -04009304 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9305 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9306 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9307 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009308
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009309 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009310
Johannes Berg463d0182009-07-14 00:33:35 +02009311 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9312 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009313 return;
9314
9315 nla_put_failure:
9316 genlmsg_cancel(msg, hdr);
9317 nlmsg_free(msg);
9318}
9319
9320void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009321 struct net_device *netdev, const u8 *buf,
9322 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009323{
9324 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009325 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009326}
9327
9328void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9329 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009330 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009331{
Johannes Berge6d6e342009-07-01 21:26:47 +02009332 nl80211_send_mlme_event(rdev, netdev, buf, len,
9333 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009334}
9335
Jouni Malinen53b46b82009-03-27 20:53:56 +02009336void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009337 struct net_device *netdev, const u8 *buf,
9338 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009339{
9340 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009341 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009342}
9343
Jouni Malinen53b46b82009-03-27 20:53:56 +02009344void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9345 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009346 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009347{
9348 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009349 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009350}
9351
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009352void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9353 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009354{
Johannes Berg947add32013-02-22 22:05:20 +01009355 struct wireless_dev *wdev = dev->ieee80211_ptr;
9356 struct wiphy *wiphy = wdev->wiphy;
9357 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009358 const struct ieee80211_mgmt *mgmt = (void *)buf;
9359 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009360
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009361 if (WARN_ON(len < 2))
9362 return;
9363
9364 if (ieee80211_is_deauth(mgmt->frame_control))
9365 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9366 else
9367 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9368
9369 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9370 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009371}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009372EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009373
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009374static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9375 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009376 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009377{
9378 struct sk_buff *msg;
9379 void *hdr;
9380
Johannes Berge6d6e342009-07-01 21:26:47 +02009381 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009382 if (!msg)
9383 return;
9384
9385 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9386 if (!hdr) {
9387 nlmsg_free(msg);
9388 return;
9389 }
9390
David S. Miller9360ffd2012-03-29 04:41:26 -04009391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9392 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9393 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9394 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9395 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009396
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009397 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009398
Johannes Berg463d0182009-07-14 00:33:35 +02009399 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9400 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009401 return;
9402
9403 nla_put_failure:
9404 genlmsg_cancel(msg, hdr);
9405 nlmsg_free(msg);
9406}
9407
9408void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009409 struct net_device *netdev, const u8 *addr,
9410 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009411{
9412 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009413 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009414}
9415
9416void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009417 struct net_device *netdev, const u8 *addr,
9418 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009419{
Johannes Berge6d6e342009-07-01 21:26:47 +02009420 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9421 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009422}
9423
Samuel Ortizb23aa672009-07-01 21:26:54 +02009424void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9425 struct net_device *netdev, const u8 *bssid,
9426 const u8 *req_ie, size_t req_ie_len,
9427 const u8 *resp_ie, size_t resp_ie_len,
9428 u16 status, gfp_t gfp)
9429{
9430 struct sk_buff *msg;
9431 void *hdr;
9432
Thomas Graf58050fc2012-06-28 03:57:45 +00009433 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009434 if (!msg)
9435 return;
9436
9437 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9438 if (!hdr) {
9439 nlmsg_free(msg);
9440 return;
9441 }
9442
David S. Miller9360ffd2012-03-29 04:41:26 -04009443 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9444 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9445 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9446 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9447 (req_ie &&
9448 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9449 (resp_ie &&
9450 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9451 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009452
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009453 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009454
Johannes Berg463d0182009-07-14 00:33:35 +02009455 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9456 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009457 return;
9458
9459 nla_put_failure:
9460 genlmsg_cancel(msg, hdr);
9461 nlmsg_free(msg);
9462
9463}
9464
9465void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9466 struct net_device *netdev, const u8 *bssid,
9467 const u8 *req_ie, size_t req_ie_len,
9468 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9469{
9470 struct sk_buff *msg;
9471 void *hdr;
9472
Thomas Graf58050fc2012-06-28 03:57:45 +00009473 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009474 if (!msg)
9475 return;
9476
9477 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9478 if (!hdr) {
9479 nlmsg_free(msg);
9480 return;
9481 }
9482
David S. Miller9360ffd2012-03-29 04:41:26 -04009483 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9485 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9486 (req_ie &&
9487 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9488 (resp_ie &&
9489 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9490 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009491
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009492 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009493
Johannes Berg463d0182009-07-14 00:33:35 +02009494 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9495 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009496 return;
9497
9498 nla_put_failure:
9499 genlmsg_cancel(msg, hdr);
9500 nlmsg_free(msg);
9501
9502}
9503
9504void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9505 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009506 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009507{
9508 struct sk_buff *msg;
9509 void *hdr;
9510
Thomas Graf58050fc2012-06-28 03:57:45 +00009511 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009512 if (!msg)
9513 return;
9514
9515 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9516 if (!hdr) {
9517 nlmsg_free(msg);
9518 return;
9519 }
9520
David S. Miller9360ffd2012-03-29 04:41:26 -04009521 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9522 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9523 (from_ap && reason &&
9524 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9525 (from_ap &&
9526 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9527 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9528 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009529
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009530 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009531
Johannes Berg463d0182009-07-14 00:33:35 +02009532 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9533 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009534 return;
9535
9536 nla_put_failure:
9537 genlmsg_cancel(msg, hdr);
9538 nlmsg_free(msg);
9539
9540}
9541
Johannes Berg04a773a2009-04-19 21:24:32 +02009542void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9543 struct net_device *netdev, const u8 *bssid,
9544 gfp_t gfp)
9545{
9546 struct sk_buff *msg;
9547 void *hdr;
9548
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009550 if (!msg)
9551 return;
9552
9553 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9554 if (!hdr) {
9555 nlmsg_free(msg);
9556 return;
9557 }
9558
David S. Miller9360ffd2012-03-29 04:41:26 -04009559 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9561 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9562 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009563
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009564 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009565
Johannes Berg463d0182009-07-14 00:33:35 +02009566 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9567 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009568 return;
9569
9570 nla_put_failure:
9571 genlmsg_cancel(msg, hdr);
9572 nlmsg_free(msg);
9573}
9574
Johannes Berg947add32013-02-22 22:05:20 +01009575void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9576 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009577{
Johannes Berg947add32013-02-22 22:05:20 +01009578 struct wireless_dev *wdev = dev->ieee80211_ptr;
9579 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009580 struct sk_buff *msg;
9581 void *hdr;
9582
Johannes Berg947add32013-02-22 22:05:20 +01009583 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9584 return;
9585
9586 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9587
Javier Cardonac93b5e72011-04-07 15:08:34 -07009588 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9589 if (!msg)
9590 return;
9591
9592 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9593 if (!hdr) {
9594 nlmsg_free(msg);
9595 return;
9596 }
9597
David S. Miller9360ffd2012-03-29 04:41:26 -04009598 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009599 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9600 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009601 (ie_len && ie &&
9602 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9603 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009604
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009605 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009606
9607 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9608 nl80211_mlme_mcgrp.id, gfp);
9609 return;
9610
9611 nla_put_failure:
9612 genlmsg_cancel(msg, hdr);
9613 nlmsg_free(msg);
9614}
Johannes Berg947add32013-02-22 22:05:20 +01009615EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009616
Jouni Malinena3b8b052009-03-27 21:59:49 +02009617void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9618 struct net_device *netdev, const u8 *addr,
9619 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009620 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009621{
9622 struct sk_buff *msg;
9623 void *hdr;
9624
Johannes Berge6d6e342009-07-01 21:26:47 +02009625 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009626 if (!msg)
9627 return;
9628
9629 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9630 if (!hdr) {
9631 nlmsg_free(msg);
9632 return;
9633 }
9634
David S. Miller9360ffd2012-03-29 04:41:26 -04009635 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9636 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9637 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9638 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9639 (key_id != -1 &&
9640 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9641 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9642 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009643
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009644 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009645
Johannes Berg463d0182009-07-14 00:33:35 +02009646 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9647 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009648 return;
9649
9650 nla_put_failure:
9651 genlmsg_cancel(msg, hdr);
9652 nlmsg_free(msg);
9653}
9654
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009655void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9656 struct ieee80211_channel *channel_before,
9657 struct ieee80211_channel *channel_after)
9658{
9659 struct sk_buff *msg;
9660 void *hdr;
9661 struct nlattr *nl_freq;
9662
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009663 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009664 if (!msg)
9665 return;
9666
9667 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9668 if (!hdr) {
9669 nlmsg_free(msg);
9670 return;
9671 }
9672
9673 /*
9674 * Since we are applying the beacon hint to a wiphy we know its
9675 * wiphy_idx is valid
9676 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9678 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009679
9680 /* Before */
9681 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9682 if (!nl_freq)
9683 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009684 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009685 goto nla_put_failure;
9686 nla_nest_end(msg, nl_freq);
9687
9688 /* After */
9689 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9690 if (!nl_freq)
9691 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009692 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009693 goto nla_put_failure;
9694 nla_nest_end(msg, nl_freq);
9695
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009696 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009697
Johannes Berg463d0182009-07-14 00:33:35 +02009698 rcu_read_lock();
9699 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9700 GFP_ATOMIC);
9701 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009702
9703 return;
9704
9705nla_put_failure:
9706 genlmsg_cancel(msg, hdr);
9707 nlmsg_free(msg);
9708}
9709
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009710static void nl80211_send_remain_on_chan_event(
9711 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009712 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009713 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009714 unsigned int duration, gfp_t gfp)
9715{
9716 struct sk_buff *msg;
9717 void *hdr;
9718
9719 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9720 if (!msg)
9721 return;
9722
9723 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9724 if (!hdr) {
9725 nlmsg_free(msg);
9726 return;
9727 }
9728
David S. Miller9360ffd2012-03-29 04:41:26 -04009729 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009730 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9731 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009732 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009733 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009734 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9735 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009736 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9737 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009738
David S. Miller9360ffd2012-03-29 04:41:26 -04009739 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9740 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9741 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009742
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009743 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009744
9745 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9746 nl80211_mlme_mcgrp.id, gfp);
9747 return;
9748
9749 nla_put_failure:
9750 genlmsg_cancel(msg, hdr);
9751 nlmsg_free(msg);
9752}
9753
Johannes Berg947add32013-02-22 22:05:20 +01009754void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9755 struct ieee80211_channel *chan,
9756 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009757{
Johannes Berg947add32013-02-22 22:05:20 +01009758 struct wiphy *wiphy = wdev->wiphy;
9759 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9760
9761 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009762 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009763 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009764 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009765}
Johannes Berg947add32013-02-22 22:05:20 +01009766EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009767
Johannes Berg947add32013-02-22 22:05:20 +01009768void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9769 struct ieee80211_channel *chan,
9770 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009771{
Johannes Berg947add32013-02-22 22:05:20 +01009772 struct wiphy *wiphy = wdev->wiphy;
9773 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9774
9775 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009776 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009777 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009778}
Johannes Berg947add32013-02-22 22:05:20 +01009779EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009780
Johannes Berg947add32013-02-22 22:05:20 +01009781void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9782 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009783{
Johannes Berg947add32013-02-22 22:05:20 +01009784 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9785 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009786 struct sk_buff *msg;
9787
Johannes Berg947add32013-02-22 22:05:20 +01009788 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9789
Thomas Graf58050fc2012-06-28 03:57:45 +00009790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009791 if (!msg)
9792 return;
9793
John W. Linville66266b32012-03-15 13:25:41 -04009794 if (nl80211_send_station(msg, 0, 0, 0,
9795 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009796 nlmsg_free(msg);
9797 return;
9798 }
9799
9800 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9801 nl80211_mlme_mcgrp.id, gfp);
9802}
Johannes Berg947add32013-02-22 22:05:20 +01009803EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009804
Johannes Berg947add32013-02-22 22:05:20 +01009805void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009806{
Johannes Berg947add32013-02-22 22:05:20 +01009807 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9808 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009809 struct sk_buff *msg;
9810 void *hdr;
9811
Johannes Berg947add32013-02-22 22:05:20 +01009812 trace_cfg80211_del_sta(dev, mac_addr);
9813
Thomas Graf58050fc2012-06-28 03:57:45 +00009814 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009815 if (!msg)
9816 return;
9817
9818 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9819 if (!hdr) {
9820 nlmsg_free(msg);
9821 return;
9822 }
9823
David S. Miller9360ffd2012-03-29 04:41:26 -04009824 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9825 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9826 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009827
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009828 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009829
9830 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9831 nl80211_mlme_mcgrp.id, gfp);
9832 return;
9833
9834 nla_put_failure:
9835 genlmsg_cancel(msg, hdr);
9836 nlmsg_free(msg);
9837}
Johannes Berg947add32013-02-22 22:05:20 +01009838EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009839
Johannes Berg947add32013-02-22 22:05:20 +01009840void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9841 enum nl80211_connect_failed_reason reason,
9842 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309843{
Johannes Berg947add32013-02-22 22:05:20 +01009844 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9845 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309846 struct sk_buff *msg;
9847 void *hdr;
9848
9849 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9850 if (!msg)
9851 return;
9852
9853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9854 if (!hdr) {
9855 nlmsg_free(msg);
9856 return;
9857 }
9858
9859 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9860 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9861 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9862 goto nla_put_failure;
9863
9864 genlmsg_end(msg, hdr);
9865
9866 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9867 nl80211_mlme_mcgrp.id, gfp);
9868 return;
9869
9870 nla_put_failure:
9871 genlmsg_cancel(msg, hdr);
9872 nlmsg_free(msg);
9873}
Johannes Berg947add32013-02-22 22:05:20 +01009874EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309875
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009876static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9877 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009878{
9879 struct wireless_dev *wdev = dev->ieee80211_ptr;
9880 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9881 struct sk_buff *msg;
9882 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009883 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009884
Eric W. Biederman15e47302012-09-07 20:12:54 +00009885 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009886 return false;
9887
9888 msg = nlmsg_new(100, gfp);
9889 if (!msg)
9890 return true;
9891
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009892 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009893 if (!hdr) {
9894 nlmsg_free(msg);
9895 return true;
9896 }
9897
David S. Miller9360ffd2012-03-29 04:41:26 -04009898 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9899 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9900 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9901 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009902
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009903 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009904 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009905 return true;
9906
9907 nla_put_failure:
9908 genlmsg_cancel(msg, hdr);
9909 nlmsg_free(msg);
9910 return true;
9911}
9912
Johannes Berg947add32013-02-22 22:05:20 +01009913bool cfg80211_rx_spurious_frame(struct net_device *dev,
9914 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009915{
Johannes Berg947add32013-02-22 22:05:20 +01009916 struct wireless_dev *wdev = dev->ieee80211_ptr;
9917 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009918
Johannes Berg947add32013-02-22 22:05:20 +01009919 trace_cfg80211_rx_spurious_frame(dev, addr);
9920
9921 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9922 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9923 trace_cfg80211_return_bool(false);
9924 return false;
9925 }
9926 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9927 addr, gfp);
9928 trace_cfg80211_return_bool(ret);
9929 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009930}
Johannes Berg947add32013-02-22 22:05:20 +01009931EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9932
9933bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9934 const u8 *addr, gfp_t gfp)
9935{
9936 struct wireless_dev *wdev = dev->ieee80211_ptr;
9937 bool ret;
9938
9939 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9940
9941 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9942 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9943 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9944 trace_cfg80211_return_bool(false);
9945 return false;
9946 }
9947 ret = __nl80211_unexpected_frame(dev,
9948 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9949 addr, gfp);
9950 trace_cfg80211_return_bool(ret);
9951 return ret;
9952}
9953EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009954
Johannes Berg2e161f72010-08-12 15:38:38 +02009955int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009956 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009957 int freq, int sig_dbm,
9958 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009959{
Johannes Berg71bbc992012-06-15 15:30:18 +02009960 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009961 struct sk_buff *msg;
9962 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009963
9964 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9965 if (!msg)
9966 return -ENOMEM;
9967
Johannes Berg2e161f72010-08-12 15:38:38 +02009968 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009969 if (!hdr) {
9970 nlmsg_free(msg);
9971 return -ENOMEM;
9972 }
9973
David S. Miller9360ffd2012-03-29 04:41:26 -04009974 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009975 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9976 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009977 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009978 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9979 (sig_dbm &&
9980 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9981 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9982 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009983
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009984 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009985
Eric W. Biederman15e47302012-09-07 20:12:54 +00009986 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009987
9988 nla_put_failure:
9989 genlmsg_cancel(msg, hdr);
9990 nlmsg_free(msg);
9991 return -ENOBUFS;
9992}
9993
Johannes Berg947add32013-02-22 22:05:20 +01009994void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9995 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009996{
Johannes Berg947add32013-02-22 22:05:20 +01009997 struct wiphy *wiphy = wdev->wiphy;
9998 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02009999 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010000 struct sk_buff *msg;
10001 void *hdr;
10002
Johannes Berg947add32013-02-22 22:05:20 +010010003 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10004
Jouni Malinen026331c2010-02-15 12:53:10 +020010005 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10006 if (!msg)
10007 return;
10008
Johannes Berg2e161f72010-08-12 15:38:38 +020010009 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010010 if (!hdr) {
10011 nlmsg_free(msg);
10012 return;
10013 }
10014
David S. Miller9360ffd2012-03-29 04:41:26 -040010015 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010016 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10017 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010018 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010019 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10020 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10021 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10022 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010023
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010024 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010025
10026 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10027 return;
10028
10029 nla_put_failure:
10030 genlmsg_cancel(msg, hdr);
10031 nlmsg_free(msg);
10032}
Johannes Berg947add32013-02-22 22:05:20 +010010033EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010034
Johannes Berg947add32013-02-22 22:05:20 +010010035void cfg80211_cqm_rssi_notify(struct net_device *dev,
10036 enum nl80211_cqm_rssi_threshold_event rssi_event,
10037 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010038{
Johannes Berg947add32013-02-22 22:05:20 +010010039 struct wireless_dev *wdev = dev->ieee80211_ptr;
10040 struct wiphy *wiphy = wdev->wiphy;
10041 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010042 struct sk_buff *msg;
10043 struct nlattr *pinfoattr;
10044 void *hdr;
10045
Johannes Berg947add32013-02-22 22:05:20 +010010046 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10047
Thomas Graf58050fc2012-06-28 03:57:45 +000010048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010049 if (!msg)
10050 return;
10051
10052 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10053 if (!hdr) {
10054 nlmsg_free(msg);
10055 return;
10056 }
10057
David S. Miller9360ffd2012-03-29 04:41:26 -040010058 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010059 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010060 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010061
10062 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10063 if (!pinfoattr)
10064 goto nla_put_failure;
10065
David S. Miller9360ffd2012-03-29 04:41:26 -040010066 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10067 rssi_event))
10068 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010069
10070 nla_nest_end(msg, pinfoattr);
10071
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010072 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010073
10074 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10075 nl80211_mlme_mcgrp.id, gfp);
10076 return;
10077
10078 nla_put_failure:
10079 genlmsg_cancel(msg, hdr);
10080 nlmsg_free(msg);
10081}
Johannes Berg947add32013-02-22 22:05:20 +010010082EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010083
Johannes Berg947add32013-02-22 22:05:20 +010010084static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10085 struct net_device *netdev, const u8 *bssid,
10086 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010087{
10088 struct sk_buff *msg;
10089 struct nlattr *rekey_attr;
10090 void *hdr;
10091
Thomas Graf58050fc2012-06-28 03:57:45 +000010092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010093 if (!msg)
10094 return;
10095
10096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10097 if (!hdr) {
10098 nlmsg_free(msg);
10099 return;
10100 }
10101
David S. Miller9360ffd2012-03-29 04:41:26 -040010102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10103 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10104 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10105 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010106
10107 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10108 if (!rekey_attr)
10109 goto nla_put_failure;
10110
David S. Miller9360ffd2012-03-29 04:41:26 -040010111 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10112 NL80211_REPLAY_CTR_LEN, replay_ctr))
10113 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010114
10115 nla_nest_end(msg, rekey_attr);
10116
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010117 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010118
10119 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10120 nl80211_mlme_mcgrp.id, gfp);
10121 return;
10122
10123 nla_put_failure:
10124 genlmsg_cancel(msg, hdr);
10125 nlmsg_free(msg);
10126}
10127
Johannes Berg947add32013-02-22 22:05:20 +010010128void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10129 const u8 *replay_ctr, gfp_t gfp)
10130{
10131 struct wireless_dev *wdev = dev->ieee80211_ptr;
10132 struct wiphy *wiphy = wdev->wiphy;
10133 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10134
10135 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10136 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10137}
10138EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10139
10140static void
10141nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10142 struct net_device *netdev, int index,
10143 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010144{
10145 struct sk_buff *msg;
10146 struct nlattr *attr;
10147 void *hdr;
10148
Thomas Graf58050fc2012-06-28 03:57:45 +000010149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010150 if (!msg)
10151 return;
10152
10153 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10154 if (!hdr) {
10155 nlmsg_free(msg);
10156 return;
10157 }
10158
David S. Miller9360ffd2012-03-29 04:41:26 -040010159 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10160 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10161 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010162
10163 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10164 if (!attr)
10165 goto nla_put_failure;
10166
David S. Miller9360ffd2012-03-29 04:41:26 -040010167 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10168 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10169 (preauth &&
10170 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10171 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010172
10173 nla_nest_end(msg, attr);
10174
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010175 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010176
10177 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10178 nl80211_mlme_mcgrp.id, gfp);
10179 return;
10180
10181 nla_put_failure:
10182 genlmsg_cancel(msg, hdr);
10183 nlmsg_free(msg);
10184}
10185
Johannes Berg947add32013-02-22 22:05:20 +010010186void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10187 const u8 *bssid, bool preauth, gfp_t gfp)
10188{
10189 struct wireless_dev *wdev = dev->ieee80211_ptr;
10190 struct wiphy *wiphy = wdev->wiphy;
10191 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10192
10193 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10194 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10195}
10196EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10197
10198static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10199 struct net_device *netdev,
10200 struct cfg80211_chan_def *chandef,
10201 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010202{
10203 struct sk_buff *msg;
10204 void *hdr;
10205
Thomas Graf58050fc2012-06-28 03:57:45 +000010206 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010207 if (!msg)
10208 return;
10209
10210 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10211 if (!hdr) {
10212 nlmsg_free(msg);
10213 return;
10214 }
10215
Johannes Berg683b6d32012-11-08 21:25:48 +010010216 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10217 goto nla_put_failure;
10218
10219 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010220 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010221
10222 genlmsg_end(msg, hdr);
10223
10224 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10225 nl80211_mlme_mcgrp.id, gfp);
10226 return;
10227
10228 nla_put_failure:
10229 genlmsg_cancel(msg, hdr);
10230 nlmsg_free(msg);
10231}
10232
Johannes Berg947add32013-02-22 22:05:20 +010010233void cfg80211_ch_switch_notify(struct net_device *dev,
10234 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010235{
Johannes Berg947add32013-02-22 22:05:20 +010010236 struct wireless_dev *wdev = dev->ieee80211_ptr;
10237 struct wiphy *wiphy = wdev->wiphy;
10238 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10239
10240 trace_cfg80211_ch_switch_notify(dev, chandef);
10241
10242 wdev_lock(wdev);
10243
10244 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10245 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10246 goto out;
10247
10248 wdev->channel = chandef->chan;
10249 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10250out:
10251 wdev_unlock(wdev);
10252 return;
10253}
10254EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10255
10256void cfg80211_cqm_txe_notify(struct net_device *dev,
10257 const u8 *peer, u32 num_packets,
10258 u32 rate, u32 intvl, gfp_t gfp)
10259{
10260 struct wireless_dev *wdev = dev->ieee80211_ptr;
10261 struct wiphy *wiphy = wdev->wiphy;
10262 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010263 struct sk_buff *msg;
10264 struct nlattr *pinfoattr;
10265 void *hdr;
10266
10267 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10268 if (!msg)
10269 return;
10270
10271 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10272 if (!hdr) {
10273 nlmsg_free(msg);
10274 return;
10275 }
10276
10277 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010278 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010279 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10280 goto nla_put_failure;
10281
10282 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10283 if (!pinfoattr)
10284 goto nla_put_failure;
10285
10286 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10287 goto nla_put_failure;
10288
10289 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10290 goto nla_put_failure;
10291
10292 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10293 goto nla_put_failure;
10294
10295 nla_nest_end(msg, pinfoattr);
10296
10297 genlmsg_end(msg, hdr);
10298
10299 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10300 nl80211_mlme_mcgrp.id, gfp);
10301 return;
10302
10303 nla_put_failure:
10304 genlmsg_cancel(msg, hdr);
10305 nlmsg_free(msg);
10306}
Johannes Berg947add32013-02-22 22:05:20 +010010307EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010308
10309void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010310nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10311 struct cfg80211_chan_def *chandef,
10312 enum nl80211_radar_event event,
10313 struct net_device *netdev, gfp_t gfp)
10314{
10315 struct sk_buff *msg;
10316 void *hdr;
10317
10318 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10319 if (!msg)
10320 return;
10321
10322 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10323 if (!hdr) {
10324 nlmsg_free(msg);
10325 return;
10326 }
10327
10328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10329 goto nla_put_failure;
10330
10331 /* NOP and radar events don't need a netdev parameter */
10332 if (netdev) {
10333 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10334
10335 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10336 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10337 goto nla_put_failure;
10338 }
10339
10340 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10341 goto nla_put_failure;
10342
10343 if (nl80211_send_chandef(msg, chandef))
10344 goto nla_put_failure;
10345
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010346 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010347
10348 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10349 nl80211_mlme_mcgrp.id, gfp);
10350 return;
10351
10352 nla_put_failure:
10353 genlmsg_cancel(msg, hdr);
10354 nlmsg_free(msg);
10355}
10356
Johannes Berg947add32013-02-22 22:05:20 +010010357void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10358 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010359{
Johannes Berg947add32013-02-22 22:05:20 +010010360 struct wireless_dev *wdev = dev->ieee80211_ptr;
10361 struct wiphy *wiphy = wdev->wiphy;
10362 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010363 struct sk_buff *msg;
10364 struct nlattr *pinfoattr;
10365 void *hdr;
10366
Johannes Berg947add32013-02-22 22:05:20 +010010367 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10368
Thomas Graf58050fc2012-06-28 03:57:45 +000010369 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010370 if (!msg)
10371 return;
10372
10373 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10374 if (!hdr) {
10375 nlmsg_free(msg);
10376 return;
10377 }
10378
David S. Miller9360ffd2012-03-29 04:41:26 -040010379 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010380 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010381 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10382 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010383
10384 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10385 if (!pinfoattr)
10386 goto nla_put_failure;
10387
David S. Miller9360ffd2012-03-29 04:41:26 -040010388 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10389 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010390
10391 nla_nest_end(msg, pinfoattr);
10392
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010393 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010394
10395 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10396 nl80211_mlme_mcgrp.id, gfp);
10397 return;
10398
10399 nla_put_failure:
10400 genlmsg_cancel(msg, hdr);
10401 nlmsg_free(msg);
10402}
Johannes Berg947add32013-02-22 22:05:20 +010010403EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010404
Johannes Berg7f6cf312011-11-04 11:18:15 +010010405void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10406 u64 cookie, bool acked, gfp_t gfp)
10407{
10408 struct wireless_dev *wdev = dev->ieee80211_ptr;
10409 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10410 struct sk_buff *msg;
10411 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010412
Beni Lev4ee3e062012-08-27 12:49:39 +030010413 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10414
Thomas Graf58050fc2012-06-28 03:57:45 +000010415 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010416
Johannes Berg7f6cf312011-11-04 11:18:15 +010010417 if (!msg)
10418 return;
10419
10420 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10421 if (!hdr) {
10422 nlmsg_free(msg);
10423 return;
10424 }
10425
David S. Miller9360ffd2012-03-29 04:41:26 -040010426 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10427 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10428 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10429 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10430 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10431 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010432
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010433 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010434
10435 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10436 nl80211_mlme_mcgrp.id, gfp);
10437 return;
10438
10439 nla_put_failure:
10440 genlmsg_cancel(msg, hdr);
10441 nlmsg_free(msg);
10442}
10443EXPORT_SYMBOL(cfg80211_probe_status);
10444
Johannes Berg5e760232011-11-04 11:18:17 +010010445void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10446 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010447 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010448{
10449 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10450 struct sk_buff *msg;
10451 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010452 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010453
Beni Lev4ee3e062012-08-27 12:49:39 +030010454 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10455
Ben Greear37c73b52012-10-26 14:49:25 -070010456 spin_lock_bh(&rdev->beacon_registrations_lock);
10457 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10458 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10459 if (!msg) {
10460 spin_unlock_bh(&rdev->beacon_registrations_lock);
10461 return;
10462 }
Johannes Berg5e760232011-11-04 11:18:17 +010010463
Ben Greear37c73b52012-10-26 14:49:25 -070010464 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10465 if (!hdr)
10466 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010467
Ben Greear37c73b52012-10-26 14:49:25 -070010468 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10469 (freq &&
10470 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10471 (sig_dbm &&
10472 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10473 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10474 goto nla_put_failure;
10475
10476 genlmsg_end(msg, hdr);
10477
10478 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010479 }
Ben Greear37c73b52012-10-26 14:49:25 -070010480 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010481 return;
10482
10483 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010484 spin_unlock_bh(&rdev->beacon_registrations_lock);
10485 if (hdr)
10486 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010487 nlmsg_free(msg);
10488}
10489EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10490
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010491#ifdef CONFIG_PM
10492void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10493 struct cfg80211_wowlan_wakeup *wakeup,
10494 gfp_t gfp)
10495{
10496 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10497 struct sk_buff *msg;
10498 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010499 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010500
10501 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10502
10503 if (wakeup)
10504 size += wakeup->packet_present_len;
10505
10506 msg = nlmsg_new(size, gfp);
10507 if (!msg)
10508 return;
10509
10510 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10511 if (!hdr)
10512 goto free_msg;
10513
10514 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10515 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10516 goto free_msg;
10517
10518 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10519 wdev->netdev->ifindex))
10520 goto free_msg;
10521
10522 if (wakeup) {
10523 struct nlattr *reasons;
10524
10525 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10526
10527 if (wakeup->disconnect &&
10528 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10529 goto free_msg;
10530 if (wakeup->magic_pkt &&
10531 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10532 goto free_msg;
10533 if (wakeup->gtk_rekey_failure &&
10534 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10535 goto free_msg;
10536 if (wakeup->eap_identity_req &&
10537 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10538 goto free_msg;
10539 if (wakeup->four_way_handshake &&
10540 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10541 goto free_msg;
10542 if (wakeup->rfkill_release &&
10543 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10544 goto free_msg;
10545
10546 if (wakeup->pattern_idx >= 0 &&
10547 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10548 wakeup->pattern_idx))
10549 goto free_msg;
10550
Johannes Berg2a0e0472013-01-23 22:57:40 +010010551 if (wakeup->tcp_match)
10552 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10553
10554 if (wakeup->tcp_connlost)
10555 nla_put_flag(msg,
10556 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10557
10558 if (wakeup->tcp_nomoretokens)
10559 nla_put_flag(msg,
10560 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10561
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010562 if (wakeup->packet) {
10563 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10564 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10565
10566 if (!wakeup->packet_80211) {
10567 pkt_attr =
10568 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10569 len_attr =
10570 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10571 }
10572
10573 if (wakeup->packet_len &&
10574 nla_put_u32(msg, len_attr, wakeup->packet_len))
10575 goto free_msg;
10576
10577 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10578 wakeup->packet))
10579 goto free_msg;
10580 }
10581
10582 nla_nest_end(msg, reasons);
10583 }
10584
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010585 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010586
10587 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10588 nl80211_mlme_mcgrp.id, gfp);
10589 return;
10590
10591 free_msg:
10592 nlmsg_free(msg);
10593}
10594EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10595#endif
10596
Jouni Malinen3475b092012-11-16 22:49:57 +020010597void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10598 enum nl80211_tdls_operation oper,
10599 u16 reason_code, gfp_t gfp)
10600{
10601 struct wireless_dev *wdev = dev->ieee80211_ptr;
10602 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10603 struct sk_buff *msg;
10604 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010605
10606 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10607 reason_code);
10608
10609 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10610 if (!msg)
10611 return;
10612
10613 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10614 if (!hdr) {
10615 nlmsg_free(msg);
10616 return;
10617 }
10618
10619 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10620 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10621 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10622 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10623 (reason_code > 0 &&
10624 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10625 goto nla_put_failure;
10626
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010627 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010628
10629 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10630 nl80211_mlme_mcgrp.id, gfp);
10631 return;
10632
10633 nla_put_failure:
10634 genlmsg_cancel(msg, hdr);
10635 nlmsg_free(msg);
10636}
10637EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10638
Jouni Malinen026331c2010-02-15 12:53:10 +020010639static int nl80211_netlink_notify(struct notifier_block * nb,
10640 unsigned long state,
10641 void *_notify)
10642{
10643 struct netlink_notify *notify = _notify;
10644 struct cfg80211_registered_device *rdev;
10645 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010646 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010647
10648 if (state != NETLINK_URELEASE)
10649 return NOTIFY_DONE;
10650
10651 rcu_read_lock();
10652
Johannes Berg5e760232011-11-04 11:18:17 +010010653 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010654 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010655 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010656
10657 spin_lock_bh(&rdev->beacon_registrations_lock);
10658 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10659 list) {
10660 if (reg->nlportid == notify->portid) {
10661 list_del(&reg->list);
10662 kfree(reg);
10663 break;
10664 }
10665 }
10666 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010667 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010668
10669 rcu_read_unlock();
10670
10671 return NOTIFY_DONE;
10672}
10673
10674static struct notifier_block nl80211_netlink_notifier = {
10675 .notifier_call = nl80211_netlink_notify,
10676};
10677
Jouni Malinen355199e2013-02-27 17:14:27 +020010678void cfg80211_ft_event(struct net_device *netdev,
10679 struct cfg80211_ft_event_params *ft_event)
10680{
10681 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10682 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10683 struct sk_buff *msg;
10684 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010685
10686 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10687
10688 if (!ft_event->target_ap)
10689 return;
10690
10691 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10692 if (!msg)
10693 return;
10694
10695 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10696 if (!hdr) {
10697 nlmsg_free(msg);
10698 return;
10699 }
10700
10701 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10702 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10703 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10704 if (ft_event->ies)
10705 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10706 if (ft_event->ric_ies)
10707 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10708 ft_event->ric_ies);
10709
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010710 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010711
10712 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10713 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10714}
10715EXPORT_SYMBOL(cfg80211_ft_event);
10716
Arend van Spriel5de17982013-04-18 15:49:00 +020010717void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10718{
10719 struct cfg80211_registered_device *rdev;
10720 struct sk_buff *msg;
10721 void *hdr;
10722 u32 nlportid;
10723
10724 rdev = wiphy_to_dev(wdev->wiphy);
10725 if (!rdev->crit_proto_nlportid)
10726 return;
10727
10728 nlportid = rdev->crit_proto_nlportid;
10729 rdev->crit_proto_nlportid = 0;
10730
10731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10732 if (!msg)
10733 return;
10734
10735 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10736 if (!hdr)
10737 goto nla_put_failure;
10738
10739 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10740 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10741 goto nla_put_failure;
10742
10743 genlmsg_end(msg, hdr);
10744
10745 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10746 return;
10747
10748 nla_put_failure:
10749 if (hdr)
10750 genlmsg_cancel(msg, hdr);
10751 nlmsg_free(msg);
10752
10753}
10754EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10755
Johannes Berg55682962007-09-20 13:09:35 -040010756/* initialisation/exit functions */
10757
10758int nl80211_init(void)
10759{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010760 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010761
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010762 err = genl_register_family_with_ops(&nl80211_fam,
10763 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010764 if (err)
10765 return err;
10766
Johannes Berg55682962007-09-20 13:09:35 -040010767 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10768 if (err)
10769 goto err_out;
10770
Johannes Berg2a519312009-02-10 21:25:55 +010010771 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10772 if (err)
10773 goto err_out;
10774
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010775 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10776 if (err)
10777 goto err_out;
10778
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010779 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10780 if (err)
10781 goto err_out;
10782
Johannes Bergaff89a92009-07-01 21:26:51 +020010783#ifdef CONFIG_NL80211_TESTMODE
10784 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10785 if (err)
10786 goto err_out;
10787#endif
10788
Jouni Malinen026331c2010-02-15 12:53:10 +020010789 err = netlink_register_notifier(&nl80211_netlink_notifier);
10790 if (err)
10791 goto err_out;
10792
Johannes Berg55682962007-09-20 13:09:35 -040010793 return 0;
10794 err_out:
10795 genl_unregister_family(&nl80211_fam);
10796 return err;
10797}
10798
10799void nl80211_exit(void)
10800{
Jouni Malinen026331c2010-02-15 12:53:10 +020010801 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010802 genl_unregister_family(&nl80211_fam);
10803}