blob: 88e820b73674fd82840a0962c28e029cc18381c8 [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 Malinen36aedc902008-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 Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
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 Berg5fe231e2013-05-08 21:45:15 +02001544 if (!netdev)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 return -ENODEV;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 if (netdev->ieee80211_ptr) {
1547 dev = wiphy_to_dev(
1548 netdev->ieee80211_ptr->wiphy);
1549 filter_wiphy = dev->wiphy_idx;
1550 }
1551 dev_put(netdev);
1552 }
1553 }
1554
Johannes Berg79c97e92009-07-07 03:56:12 +02001555 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001556 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1557 continue;
Julius Volzb4637272008-07-08 14:02:19 +02001558 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -04001559 continue;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy)
1561 continue;
1562 /* attempt to fit multiple wiphy data chunks into the skb */
1563 do {
1564 ret = nl80211_send_wiphy(dev, skb,
1565 NETLINK_CB(cb->skb).portid,
1566 cb->nlh->nlmsg_seq,
1567 NLM_F_MULTI,
1568 split, &cb->args[1],
1569 &cb->args[2],
1570 &cb->args[3]);
1571 if (ret < 0) {
1572 /*
1573 * If sending the wiphy data didn't fit (ENOBUFS
1574 * or EMSGSIZE returned), this SKB is still
1575 * empty (so it's not too big because another
1576 * wiphy dataset is already in the skb) and
1577 * we've not tried to adjust the dump allocation
1578 * yet ... then adjust the alloc size to be
1579 * bigger, and return 1 but with the empty skb.
1580 * This results in an empty message being RX'ed
1581 * in userspace, but that is ignored.
1582 *
1583 * We can then retry with the larger buffer.
1584 */
1585 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1586 !skb->len &&
1587 cb->min_dump_alloc < 4096) {
1588 cb->min_dump_alloc = 4096;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 return 1;
1590 }
1591 idx--;
1592 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001593 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 } while (cb->args[1] > 0);
1595 break;
Johannes Berg55682962007-09-20 13:09:35 -04001596 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001597 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001598
1599 cb->args[0] = idx;
1600
1601 return skb->len;
1602}
1603
1604static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1605{
1606 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001607 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg55682962007-09-20 13:09:35 -04001608
Johannes Berg645e77d2013-03-01 14:03:49 +01001609 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001610 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001611 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001612
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
1614 false, NULL, NULL, NULL) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001615 nlmsg_free(msg);
1616 return -ENOBUFS;
1617 }
Johannes Berg55682962007-09-20 13:09:35 -04001618
Johannes Berg134e6372009-07-10 09:51:34 +00001619 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001620}
1621
Jouni Malinen31888482008-10-30 16:59:24 +02001622static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1623 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1624 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1625 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1626 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1627 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1628};
1629
1630static int parse_txq_params(struct nlattr *tb[],
1631 struct ieee80211_txq_params *txq_params)
1632{
Johannes Berga3304b02012-03-28 11:04:24 +02001633 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001634 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1635 !tb[NL80211_TXQ_ATTR_AIFS])
1636 return -EINVAL;
1637
Johannes Berga3304b02012-03-28 11:04:24 +02001638 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001639 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1640 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1641 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1642 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1643
Johannes Berga3304b02012-03-28 11:04:24 +02001644 if (txq_params->ac >= NL80211_NUM_ACS)
1645 return -EINVAL;
1646
Jouni Malinen31888482008-10-30 16:59:24 +02001647 return 0;
1648}
1649
Johannes Bergf444de02010-05-05 15:25:02 +02001650static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1651{
1652 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001653 * You can only set the channel explicitly for WDS interfaces,
1654 * all others have their channel managed via their respective
1655 * "establish a connection" command (connect, join, ...)
1656 *
1657 * For AP/GO and mesh mode, the channel can be set with the
1658 * channel userspace API, but is only stored and passed to the
1659 * low-level driver when the AP starts or the mesh is joined.
1660 * This is for backward compatibility, userspace can also give
1661 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001662 *
1663 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001664 * whatever else is going on, so they have their own special
1665 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001666 */
1667 return !wdev ||
1668 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001669 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001670 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1671 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001672}
1673
Johannes Berg683b6d32012-11-08 21:25:48 +01001674static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1675 struct genl_info *info,
1676 struct cfg80211_chan_def *chandef)
1677{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301678 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001679
1680 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1681 return -EINVAL;
1682
1683 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1684
1685 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001686 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1687 chandef->center_freq1 = control_freq;
1688 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001689
1690 /* Primary channel not allowed */
1691 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1692 return -EINVAL;
1693
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001694 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1695 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001696
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001697 chantype = nla_get_u32(
1698 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1699
1700 switch (chantype) {
1701 case NL80211_CHAN_NO_HT:
1702 case NL80211_CHAN_HT20:
1703 case NL80211_CHAN_HT40PLUS:
1704 case NL80211_CHAN_HT40MINUS:
1705 cfg80211_chandef_create(chandef, chandef->chan,
1706 chantype);
1707 break;
1708 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001709 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001710 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001711 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1712 chandef->width =
1713 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1714 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1715 chandef->center_freq1 =
1716 nla_get_u32(
1717 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1718 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1719 chandef->center_freq2 =
1720 nla_get_u32(
1721 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1722 }
1723
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001724 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001725 return -EINVAL;
1726
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001727 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1728 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001729 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001730
Johannes Berg683b6d32012-11-08 21:25:48 +01001731 return 0;
1732}
1733
Johannes Bergf444de02010-05-05 15:25:02 +02001734static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1735 struct wireless_dev *wdev,
1736 struct genl_info *info)
1737{
Johannes Berg683b6d32012-11-08 21:25:48 +01001738 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001739 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001740 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1741
1742 if (wdev)
1743 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001744
Johannes Bergf444de02010-05-05 15:25:02 +02001745 if (!nl80211_can_set_dev_channel(wdev))
1746 return -EOPNOTSUPP;
1747
Johannes Berg683b6d32012-11-08 21:25:48 +01001748 result = nl80211_parse_chandef(rdev, info, &chandef);
1749 if (result)
1750 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001751
Johannes Berge8c9bd52012-06-06 08:18:22 +02001752 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001753 case NL80211_IFTYPE_AP:
1754 case NL80211_IFTYPE_P2P_GO:
1755 if (wdev->beacon_interval) {
1756 result = -EBUSY;
1757 break;
1758 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001759 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001760 result = -EINVAL;
1761 break;
1762 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001763 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001764 result = 0;
1765 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001766 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001767 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001768 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001769 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001770 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001771 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001772 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001773 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001774 }
Johannes Bergf444de02010-05-05 15:25:02 +02001775
1776 return result;
1777}
1778
1779static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1780{
Johannes Berg4c476992010-10-04 21:36:35 +02001781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1782 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001783
Johannes Berg4c476992010-10-04 21:36:35 +02001784 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001785}
1786
Bill Jordane8347eb2010-10-01 13:54:28 -04001787static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1788{
Johannes Berg43b19952010-10-07 13:10:30 +02001789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1790 struct net_device *dev = info->user_ptr[1];
1791 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001792 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001793
1794 if (!info->attrs[NL80211_ATTR_MAC])
1795 return -EINVAL;
1796
Johannes Berg43b19952010-10-07 13:10:30 +02001797 if (netif_running(dev))
1798 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001799
Johannes Berg43b19952010-10-07 13:10:30 +02001800 if (!rdev->ops->set_wds_peer)
1801 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001802
Johannes Berg43b19952010-10-07 13:10:30 +02001803 if (wdev->iftype != NL80211_IFTYPE_WDS)
1804 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001805
1806 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001807 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001808}
1809
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1812{
1813 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001814 struct net_device *netdev = NULL;
1815 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001816 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001817 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001818 u32 changed;
1819 u8 retry_short = 0, retry_long = 0;
1820 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001821 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001822
Johannes Berg5fe231e2013-05-08 21:45:15 +02001823 ASSERT_RTNL();
1824
Johannes Bergf444de02010-05-05 15:25:02 +02001825 /*
1826 * Try to find the wiphy and netdev. Normally this
1827 * function shouldn't need the netdev, but this is
1828 * done for backward compatibility -- previously
1829 * setting the channel was done per wiphy, but now
1830 * it is per netdev. Previous userland like hostapd
1831 * also passed a netdev to set_wiphy, so that it is
1832 * possible to let that go to the right netdev!
1833 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001834
Johannes Bergf444de02010-05-05 15:25:02 +02001835 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1836 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1837
1838 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001839 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001840 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001841 else
Johannes Bergf444de02010-05-05 15:25:02 +02001842 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001843 }
1844
Johannes Bergf444de02010-05-05 15:25:02 +02001845 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001846 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1847 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001848 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001849 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001850 wdev = NULL;
1851 netdev = NULL;
1852 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001853 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001854 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001855
1856 /*
1857 * end workaround code, by now the rdev is available
1858 * and locked, and wdev may or may not be NULL.
1859 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001860
1861 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001862 result = cfg80211_dev_rename(
1863 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001864
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001865 if (result)
1866 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001867
Jouni Malinen31888482008-10-30 16:59:24 +02001868 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1869 struct ieee80211_txq_params txq_params;
1870 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1871
1872 if (!rdev->ops->set_txq_params) {
1873 result = -EOPNOTSUPP;
1874 goto bad_res;
1875 }
1876
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001877 if (!netdev) {
1878 result = -EINVAL;
1879 goto bad_res;
1880 }
1881
Johannes Berg133a3ff2011-11-03 14:50:13 +01001882 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1883 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1884 result = -EINVAL;
1885 goto bad_res;
1886 }
1887
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001888 if (!netif_running(netdev)) {
1889 result = -ENETDOWN;
1890 goto bad_res;
1891 }
1892
Jouni Malinen31888482008-10-30 16:59:24 +02001893 nla_for_each_nested(nl_txq_params,
1894 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1895 rem_txq_params) {
1896 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1897 nla_data(nl_txq_params),
1898 nla_len(nl_txq_params),
1899 txq_params_policy);
1900 result = parse_txq_params(tb, &txq_params);
1901 if (result)
1902 goto bad_res;
1903
Hila Gonene35e4d22012-06-27 17:19:42 +03001904 result = rdev_set_txq_params(rdev, netdev,
1905 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001906 if (result)
1907 goto bad_res;
1908 }
1909 }
1910
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001911 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001912 result = __nl80211_set_channel(rdev,
1913 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1914 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001915 if (result)
1916 goto bad_res;
1917 }
1918
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001919 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001920 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001921 enum nl80211_tx_power_setting type;
1922 int idx, mbm = 0;
1923
Johannes Bergc8442112012-10-24 10:17:18 +02001924 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1925 txp_wdev = NULL;
1926
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001927 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001928 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001929 goto bad_res;
1930 }
1931
1932 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1933 type = nla_get_u32(info->attrs[idx]);
1934
1935 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1936 (type != NL80211_TX_POWER_AUTOMATIC)) {
1937 result = -EINVAL;
1938 goto bad_res;
1939 }
1940
1941 if (type != NL80211_TX_POWER_AUTOMATIC) {
1942 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1943 mbm = nla_get_u32(info->attrs[idx]);
1944 }
1945
Johannes Bergc8442112012-10-24 10:17:18 +02001946 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001947 if (result)
1948 goto bad_res;
1949 }
1950
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001951 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1952 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1953 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001954 if ((!rdev->wiphy.available_antennas_tx &&
1955 !rdev->wiphy.available_antennas_rx) ||
1956 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001957 result = -EOPNOTSUPP;
1958 goto bad_res;
1959 }
1960
1961 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
1962 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
1963
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001964 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09001965 * available antenna masks, except for the "all" mask */
1966 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
1967 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001968 result = -EINVAL;
1969 goto bad_res;
1970 }
1971
Bruno Randolf7f531e02010-12-16 11:30:22 +09001972 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
1973 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09001974
Hila Gonene35e4d22012-06-27 17:19:42 +03001975 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001976 if (result)
1977 goto bad_res;
1978 }
1979
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001980 changed = 0;
1981
1982 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
1983 retry_short = nla_get_u8(
1984 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
1985 if (retry_short == 0) {
1986 result = -EINVAL;
1987 goto bad_res;
1988 }
1989 changed |= WIPHY_PARAM_RETRY_SHORT;
1990 }
1991
1992 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
1993 retry_long = nla_get_u8(
1994 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
1995 if (retry_long == 0) {
1996 result = -EINVAL;
1997 goto bad_res;
1998 }
1999 changed |= WIPHY_PARAM_RETRY_LONG;
2000 }
2001
2002 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2003 frag_threshold = nla_get_u32(
2004 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2005 if (frag_threshold < 256) {
2006 result = -EINVAL;
2007 goto bad_res;
2008 }
2009 if (frag_threshold != (u32) -1) {
2010 /*
2011 * Fragments (apart from the last one) are required to
2012 * have even length. Make the fragmentation code
2013 * simpler by stripping LSB should someone try to use
2014 * odd threshold value.
2015 */
2016 frag_threshold &= ~0x1;
2017 }
2018 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2019 }
2020
2021 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2022 rts_threshold = nla_get_u32(
2023 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2024 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2025 }
2026
Lukáš Turek81077e82009-12-21 22:50:47 +01002027 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2028 coverage_class = nla_get_u8(
2029 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2030 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2031 }
2032
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002033 if (changed) {
2034 u8 old_retry_short, old_retry_long;
2035 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002036 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002037
2038 if (!rdev->ops->set_wiphy_params) {
2039 result = -EOPNOTSUPP;
2040 goto bad_res;
2041 }
2042
2043 old_retry_short = rdev->wiphy.retry_short;
2044 old_retry_long = rdev->wiphy.retry_long;
2045 old_frag_threshold = rdev->wiphy.frag_threshold;
2046 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002047 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002048
2049 if (changed & WIPHY_PARAM_RETRY_SHORT)
2050 rdev->wiphy.retry_short = retry_short;
2051 if (changed & WIPHY_PARAM_RETRY_LONG)
2052 rdev->wiphy.retry_long = retry_long;
2053 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2054 rdev->wiphy.frag_threshold = frag_threshold;
2055 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2056 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002057 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2058 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002059
Hila Gonene35e4d22012-06-27 17:19:42 +03002060 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002061 if (result) {
2062 rdev->wiphy.retry_short = old_retry_short;
2063 rdev->wiphy.retry_long = old_retry_long;
2064 rdev->wiphy.frag_threshold = old_frag_threshold;
2065 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002066 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002067 }
2068 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002069
Johannes Berg306d6112008-12-08 12:39:04 +01002070 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002071 if (netdev)
2072 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002073 return result;
2074}
2075
Johannes Berg71bbc992012-06-15 15:30:18 +02002076static inline u64 wdev_id(struct wireless_dev *wdev)
2077{
2078 return (u64)wdev->identifier |
2079 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2080}
Johannes Berg55682962007-09-20 13:09:35 -04002081
Johannes Berg683b6d32012-11-08 21:25:48 +01002082static int nl80211_send_chandef(struct sk_buff *msg,
2083 struct cfg80211_chan_def *chandef)
2084{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002085 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002086
Johannes Berg683b6d32012-11-08 21:25:48 +01002087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2088 chandef->chan->center_freq))
2089 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002090 switch (chandef->width) {
2091 case NL80211_CHAN_WIDTH_20_NOHT:
2092 case NL80211_CHAN_WIDTH_20:
2093 case NL80211_CHAN_WIDTH_40:
2094 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2095 cfg80211_get_chandef_type(chandef)))
2096 return -ENOBUFS;
2097 break;
2098 default:
2099 break;
2100 }
2101 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2102 return -ENOBUFS;
2103 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2104 return -ENOBUFS;
2105 if (chandef->center_freq2 &&
2106 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002107 return -ENOBUFS;
2108 return 0;
2109}
2110
Eric W. Biederman15e47302012-09-07 20:12:54 +00002111static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002112 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002113 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002114{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002115 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002116 void *hdr;
2117
Eric W. Biederman15e47302012-09-07 20:12:54 +00002118 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002119 if (!hdr)
2120 return -1;
2121
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002122 if (dev &&
2123 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002124 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002125 goto nla_put_failure;
2126
2127 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2128 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002129 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002130 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002131 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2132 rdev->devlist_generation ^
2133 (cfg80211_rdev_list_generation << 2)))
2134 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002135
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002136 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002137 int ret;
2138 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002139
Johannes Berg683b6d32012-11-08 21:25:48 +01002140 ret = rdev_get_channel(rdev, wdev, &chandef);
2141 if (ret == 0) {
2142 if (nl80211_send_chandef(msg, &chandef))
2143 goto nla_put_failure;
2144 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002145 }
2146
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002147 if (wdev->ssid_len) {
2148 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2149 goto nla_put_failure;
2150 }
2151
Johannes Berg55682962007-09-20 13:09:35 -04002152 return genlmsg_end(msg, hdr);
2153
2154 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002155 genlmsg_cancel(msg, hdr);
2156 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002157}
2158
2159static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2160{
2161 int wp_idx = 0;
2162 int if_idx = 0;
2163 int wp_start = cb->args[0];
2164 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002165 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002166 struct wireless_dev *wdev;
2167
Johannes Berg5fe231e2013-05-08 21:45:15 +02002168 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002169 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2170 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002171 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002172 if (wp_idx < wp_start) {
2173 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002174 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002175 }
Johannes Berg55682962007-09-20 13:09:35 -04002176 if_idx = 0;
2177
Johannes Berg89a54e42012-06-15 14:33:17 +02002178 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002179 if (if_idx < if_start) {
2180 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002181 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002182 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002183 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002184 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002185 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002186 goto out;
2187 }
2188 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002189 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002190
2191 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002192 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002193 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002194 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002195
2196 cb->args[0] = wp_idx;
2197 cb->args[1] = if_idx;
2198
2199 return skb->len;
2200}
2201
2202static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2203{
2204 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002205 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002206 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002207
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002209 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002210 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002211
Eric W. Biederman15e47302012-09-07 20:12:54 +00002212 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002213 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002214 nlmsg_free(msg);
2215 return -ENOBUFS;
2216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217
Johannes Berg134e6372009-07-10 09:51:34 +00002218 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002219}
2220
Michael Wu66f7ac52008-01-31 19:48:22 +01002221static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2222 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2223 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2224 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2225 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2226 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002227 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002228};
2229
2230static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2231{
2232 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2233 int flag;
2234
2235 *mntrflags = 0;
2236
2237 if (!nla)
2238 return -EINVAL;
2239
2240 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2241 nla, mntr_flags_policy))
2242 return -EINVAL;
2243
2244 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2245 if (flags[flag])
2246 *mntrflags |= (1<<flag);
2247
2248 return 0;
2249}
2250
Johannes Berg9bc383d2009-11-19 11:55:19 +01002251static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002252 struct net_device *netdev, u8 use_4addr,
2253 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002254{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002255 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002256 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002257 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002258 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002259 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002260
2261 switch (iftype) {
2262 case NL80211_IFTYPE_AP_VLAN:
2263 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2264 return 0;
2265 break;
2266 case NL80211_IFTYPE_STATION:
2267 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2268 return 0;
2269 break;
2270 default:
2271 break;
2272 }
2273
2274 return -EOPNOTSUPP;
2275}
2276
Johannes Berg55682962007-09-20 13:09:35 -04002277static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2278{
Johannes Berg4c476992010-10-04 21:36:35 +02002279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002280 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002281 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002282 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002283 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002284 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002285 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002286
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002287 memset(&params, 0, sizeof(params));
2288
Johannes Berg04a773a2009-04-19 21:24:32 +02002289 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002290
Johannes Berg723b0382008-09-16 20:22:09 +02002291 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002292 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002293 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002294 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002295 if (ntype > NL80211_IFTYPE_MAX)
2296 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002297 }
2298
Johannes Berg92ffe052008-09-16 20:39:36 +02002299 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002300 struct wireless_dev *wdev = dev->ieee80211_ptr;
2301
Johannes Berg4c476992010-10-04 21:36:35 +02002302 if (ntype != NL80211_IFTYPE_MESH_POINT)
2303 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002304 if (netif_running(dev))
2305 return -EBUSY;
2306
2307 wdev_lock(wdev);
2308 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2309 IEEE80211_MAX_MESH_ID_LEN);
2310 wdev->mesh_id_up_len =
2311 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2312 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2313 wdev->mesh_id_up_len);
2314 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002315 }
2316
Felix Fietkau8b787642009-11-10 18:53:10 +01002317 if (info->attrs[NL80211_ATTR_4ADDR]) {
2318 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2319 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002320 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002322 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002323 } else {
2324 params.use_4addr = -1;
2325 }
2326
Johannes Berg92ffe052008-09-16 20:39:36 +02002327 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002328 if (ntype != NL80211_IFTYPE_MONITOR)
2329 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002330 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2331 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002332 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002333 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002334
2335 flags = &_flags;
2336 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002337 }
Johannes Berg3b858752009-03-12 09:55:09 +01002338
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002339 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2340 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2341 return -EOPNOTSUPP;
2342
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002343 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002344 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002345 else
2346 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002347
Johannes Berg9bc383d2009-11-19 11:55:19 +01002348 if (!err && params.use_4addr != -1)
2349 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2350
Johannes Berg55682962007-09-20 13:09:35 -04002351 return err;
2352}
2353
2354static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2355{
Johannes Berg4c476992010-10-04 21:36:35 +02002356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002357 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002358 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002359 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002360 int err;
2361 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002362 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002363
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002364 memset(&params, 0, sizeof(params));
2365
Johannes Berg55682962007-09-20 13:09:35 -04002366 if (!info->attrs[NL80211_ATTR_IFNAME])
2367 return -EINVAL;
2368
2369 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2370 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2371 if (type > NL80211_IFTYPE_MAX)
2372 return -EINVAL;
2373 }
2374
Johannes Berg79c97e92009-07-07 03:56:12 +02002375 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002376 !(rdev->wiphy.interface_modes & (1 << type)))
2377 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002378
Arend van Spriel1c18f142013-01-08 10:17:27 +01002379 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2380 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2381 ETH_ALEN);
2382 if (!is_valid_ether_addr(params.macaddr))
2383 return -EADDRNOTAVAIL;
2384 }
2385
Johannes Berg9bc383d2009-11-19 11:55:19 +01002386 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002387 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002388 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002389 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002390 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002391 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002392
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2394 if (!msg)
2395 return -ENOMEM;
2396
Michael Wu66f7ac52008-01-31 19:48:22 +01002397 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2398 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2399 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002400
2401 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2402 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2403 return -EOPNOTSUPP;
2404
Hila Gonene35e4d22012-06-27 17:19:42 +03002405 wdev = rdev_add_virtual_intf(rdev,
2406 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2407 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002408 if (IS_ERR(wdev)) {
2409 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002410 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002411 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002412
Johannes Berg98104fde2012-06-16 00:19:54 +02002413 switch (type) {
2414 case NL80211_IFTYPE_MESH_POINT:
2415 if (!info->attrs[NL80211_ATTR_MESH_ID])
2416 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002417 wdev_lock(wdev);
2418 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2419 IEEE80211_MAX_MESH_ID_LEN);
2420 wdev->mesh_id_up_len =
2421 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2422 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2423 wdev->mesh_id_up_len);
2424 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002425 break;
2426 case NL80211_IFTYPE_P2P_DEVICE:
2427 /*
2428 * P2P Device doesn't have a netdev, so doesn't go
2429 * through the netdev notifier and must be added here
2430 */
2431 mutex_init(&wdev->mtx);
2432 INIT_LIST_HEAD(&wdev->event_list);
2433 spin_lock_init(&wdev->event_lock);
2434 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2435 spin_lock_init(&wdev->mgmt_registrations_lock);
2436
Johannes Berg98104fde2012-06-16 00:19:54 +02002437 wdev->identifier = ++rdev->wdev_id;
2438 list_add_rcu(&wdev->list, &rdev->wdev_list);
2439 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002440 break;
2441 default:
2442 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002443 }
2444
Eric W. Biederman15e47302012-09-07 20:12:54 +00002445 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002446 rdev, wdev) < 0) {
2447 nlmsg_free(msg);
2448 return -ENOBUFS;
2449 }
2450
2451 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002452}
2453
2454static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2455{
Johannes Berg4c476992010-10-04 21:36:35 +02002456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002457 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002458
Johannes Berg4c476992010-10-04 21:36:35 +02002459 if (!rdev->ops->del_virtual_intf)
2460 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002461
Johannes Berg84efbb82012-06-16 00:00:26 +02002462 /*
2463 * If we remove a wireless device without a netdev then clear
2464 * user_ptr[1] so that nl80211_post_doit won't dereference it
2465 * to check if it needs to do dev_put(). Otherwise it crashes
2466 * since the wdev has been freed, unlike with a netdev where
2467 * we need the dev_put() for the netdev to really be freed.
2468 */
2469 if (!wdev->netdev)
2470 info->user_ptr[1] = NULL;
2471
Hila Gonene35e4d22012-06-27 17:19:42 +03002472 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002473}
2474
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002475static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2476{
2477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2478 struct net_device *dev = info->user_ptr[1];
2479 u16 noack_map;
2480
2481 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2482 return -EINVAL;
2483
2484 if (!rdev->ops->set_noack_map)
2485 return -EOPNOTSUPP;
2486
2487 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2488
Hila Gonene35e4d22012-06-27 17:19:42 +03002489 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002490}
2491
Johannes Berg41ade002007-12-19 02:03:29 +01002492struct get_key_cookie {
2493 struct sk_buff *msg;
2494 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002495 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002496};
2497
2498static void get_key_callback(void *c, struct key_params *params)
2499{
Johannes Bergb9454e82009-07-08 13:29:08 +02002500 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002501 struct get_key_cookie *cookie = c;
2502
David S. Miller9360ffd2012-03-29 04:41:26 -04002503 if ((params->key &&
2504 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2505 params->key_len, params->key)) ||
2506 (params->seq &&
2507 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2508 params->seq_len, params->seq)) ||
2509 (params->cipher &&
2510 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2511 params->cipher)))
2512 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002513
Johannes Bergb9454e82009-07-08 13:29:08 +02002514 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2515 if (!key)
2516 goto nla_put_failure;
2517
David S. Miller9360ffd2012-03-29 04:41:26 -04002518 if ((params->key &&
2519 nla_put(cookie->msg, NL80211_KEY_DATA,
2520 params->key_len, params->key)) ||
2521 (params->seq &&
2522 nla_put(cookie->msg, NL80211_KEY_SEQ,
2523 params->seq_len, params->seq)) ||
2524 (params->cipher &&
2525 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2526 params->cipher)))
2527 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002528
David S. Miller9360ffd2012-03-29 04:41:26 -04002529 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2530 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002531
2532 nla_nest_end(cookie->msg, key);
2533
Johannes Berg41ade002007-12-19 02:03:29 +01002534 return;
2535 nla_put_failure:
2536 cookie->error = 1;
2537}
2538
2539static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2540{
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002542 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002543 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002544 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002545 const u8 *mac_addr = NULL;
2546 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002547 struct get_key_cookie cookie = {
2548 .error = 0,
2549 };
2550 void *hdr;
2551 struct sk_buff *msg;
2552
2553 if (info->attrs[NL80211_ATTR_KEY_IDX])
2554 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2555
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002556 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002557 return -EINVAL;
2558
2559 if (info->attrs[NL80211_ATTR_MAC])
2560 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2561
Johannes Berge31b8212010-10-05 19:39:30 +02002562 pairwise = !!mac_addr;
2563 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2564 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2565 if (kt >= NUM_NL80211_KEYTYPES)
2566 return -EINVAL;
2567 if (kt != NL80211_KEYTYPE_GROUP &&
2568 kt != NL80211_KEYTYPE_PAIRWISE)
2569 return -EINVAL;
2570 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2571 }
2572
Johannes Berg4c476992010-10-04 21:36:35 +02002573 if (!rdev->ops->get_key)
2574 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002575
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002577 if (!msg)
2578 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002579
Eric W. Biederman15e47302012-09-07 20:12:54 +00002580 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002581 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002582 if (IS_ERR(hdr))
2583 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002584
2585 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002586 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002587
David S. Miller9360ffd2012-03-29 04:41:26 -04002588 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2589 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2590 goto nla_put_failure;
2591 if (mac_addr &&
2592 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2593 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002594
Johannes Berge31b8212010-10-05 19:39:30 +02002595 if (pairwise && mac_addr &&
2596 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2597 return -ENOENT;
2598
Hila Gonene35e4d22012-06-27 17:19:42 +03002599 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2600 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002601
2602 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002603 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002604
2605 if (cookie.error)
2606 goto nla_put_failure;
2607
2608 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002609 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002610
2611 nla_put_failure:
2612 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002613 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002614 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002615 return err;
2616}
2617
2618static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2619{
Johannes Berg4c476992010-10-04 21:36:35 +02002620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002621 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002622 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002623 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002624
Johannes Bergb9454e82009-07-08 13:29:08 +02002625 err = nl80211_parse_key(info, &key);
2626 if (err)
2627 return err;
2628
2629 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002630 return -EINVAL;
2631
Johannes Bergb9454e82009-07-08 13:29:08 +02002632 /* only support setting default key */
2633 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002634 return -EINVAL;
2635
Johannes Bergfffd0932009-07-08 14:22:54 +02002636 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002637
2638 if (key.def) {
2639 if (!rdev->ops->set_default_key) {
2640 err = -EOPNOTSUPP;
2641 goto out;
2642 }
2643
2644 err = nl80211_key_allowed(dev->ieee80211_ptr);
2645 if (err)
2646 goto out;
2647
Hila Gonene35e4d22012-06-27 17:19:42 +03002648 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002649 key.def_uni, key.def_multi);
2650
2651 if (err)
2652 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002653
Johannes Berg3d23e342009-09-29 23:27:28 +02002654#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002655 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002656#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002657 } else {
2658 if (key.def_uni || !key.def_multi) {
2659 err = -EINVAL;
2660 goto out;
2661 }
2662
2663 if (!rdev->ops->set_default_mgmt_key) {
2664 err = -EOPNOTSUPP;
2665 goto out;
2666 }
2667
2668 err = nl80211_key_allowed(dev->ieee80211_ptr);
2669 if (err)
2670 goto out;
2671
Hila Gonene35e4d22012-06-27 17:19:42 +03002672 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002673 if (err)
2674 goto out;
2675
2676#ifdef CONFIG_CFG80211_WEXT
2677 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2678#endif
2679 }
2680
2681 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002682 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002683
Johannes Berg41ade002007-12-19 02:03:29 +01002684 return err;
2685}
2686
2687static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2688{
Johannes Berg4c476992010-10-04 21:36:35 +02002689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002690 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002691 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002692 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002693 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002694
Johannes Bergb9454e82009-07-08 13:29:08 +02002695 err = nl80211_parse_key(info, &key);
2696 if (err)
2697 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002698
Johannes Bergb9454e82009-07-08 13:29:08 +02002699 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002700 return -EINVAL;
2701
Johannes Berg41ade002007-12-19 02:03:29 +01002702 if (info->attrs[NL80211_ATTR_MAC])
2703 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2704
Johannes Berge31b8212010-10-05 19:39:30 +02002705 if (key.type == -1) {
2706 if (mac_addr)
2707 key.type = NL80211_KEYTYPE_PAIRWISE;
2708 else
2709 key.type = NL80211_KEYTYPE_GROUP;
2710 }
2711
2712 /* for now */
2713 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2714 key.type != NL80211_KEYTYPE_GROUP)
2715 return -EINVAL;
2716
Johannes Berg4c476992010-10-04 21:36:35 +02002717 if (!rdev->ops->add_key)
2718 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002719
Johannes Berge31b8212010-10-05 19:39:30 +02002720 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2721 key.type == NL80211_KEYTYPE_PAIRWISE,
2722 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002723 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002724
2725 wdev_lock(dev->ieee80211_ptr);
2726 err = nl80211_key_allowed(dev->ieee80211_ptr);
2727 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002728 err = rdev_add_key(rdev, dev, key.idx,
2729 key.type == NL80211_KEYTYPE_PAIRWISE,
2730 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002731 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002732
Johannes Berg41ade002007-12-19 02:03:29 +01002733 return err;
2734}
2735
2736static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2737{
Johannes Berg4c476992010-10-04 21:36:35 +02002738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002739 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002740 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002741 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002742 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002743
Johannes Bergb9454e82009-07-08 13:29:08 +02002744 err = nl80211_parse_key(info, &key);
2745 if (err)
2746 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002747
2748 if (info->attrs[NL80211_ATTR_MAC])
2749 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2750
Johannes Berge31b8212010-10-05 19:39:30 +02002751 if (key.type == -1) {
2752 if (mac_addr)
2753 key.type = NL80211_KEYTYPE_PAIRWISE;
2754 else
2755 key.type = NL80211_KEYTYPE_GROUP;
2756 }
2757
2758 /* for now */
2759 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2760 key.type != NL80211_KEYTYPE_GROUP)
2761 return -EINVAL;
2762
Johannes Berg4c476992010-10-04 21:36:35 +02002763 if (!rdev->ops->del_key)
2764 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002765
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 wdev_lock(dev->ieee80211_ptr);
2767 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002768
2769 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2770 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2771 err = -ENOENT;
2772
Johannes Bergfffd0932009-07-08 14:22:54 +02002773 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002774 err = rdev_del_key(rdev, dev, key.idx,
2775 key.type == NL80211_KEYTYPE_PAIRWISE,
2776 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002777
Johannes Berg3d23e342009-09-29 23:27:28 +02002778#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002779 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002781 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002782 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002783 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2784 }
2785#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002786 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002787
Johannes Berg41ade002007-12-19 02:03:29 +01002788 return err;
2789}
2790
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302791/* This function returns an error or the number of nested attributes */
2792static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2793{
2794 struct nlattr *attr;
2795 int n_entries = 0, tmp;
2796
2797 nla_for_each_nested(attr, nl_attr, tmp) {
2798 if (nla_len(attr) != ETH_ALEN)
2799 return -EINVAL;
2800
2801 n_entries++;
2802 }
2803
2804 return n_entries;
2805}
2806
2807/*
2808 * This function parses ACL information and allocates memory for ACL data.
2809 * On successful return, the calling function is responsible to free the
2810 * ACL buffer returned by this function.
2811 */
2812static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2813 struct genl_info *info)
2814{
2815 enum nl80211_acl_policy acl_policy;
2816 struct nlattr *attr;
2817 struct cfg80211_acl_data *acl;
2818 int i = 0, n_entries, tmp;
2819
2820 if (!wiphy->max_acl_mac_addrs)
2821 return ERR_PTR(-EOPNOTSUPP);
2822
2823 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2824 return ERR_PTR(-EINVAL);
2825
2826 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2827 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2828 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2829 return ERR_PTR(-EINVAL);
2830
2831 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2832 return ERR_PTR(-EINVAL);
2833
2834 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2835 if (n_entries < 0)
2836 return ERR_PTR(n_entries);
2837
2838 if (n_entries > wiphy->max_acl_mac_addrs)
2839 return ERR_PTR(-ENOTSUPP);
2840
2841 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2842 GFP_KERNEL);
2843 if (!acl)
2844 return ERR_PTR(-ENOMEM);
2845
2846 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2847 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2848 i++;
2849 }
2850
2851 acl->n_acl_entries = n_entries;
2852 acl->acl_policy = acl_policy;
2853
2854 return acl;
2855}
2856
2857static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2858{
2859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2860 struct net_device *dev = info->user_ptr[1];
2861 struct cfg80211_acl_data *acl;
2862 int err;
2863
2864 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2865 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2866 return -EOPNOTSUPP;
2867
2868 if (!dev->ieee80211_ptr->beacon_interval)
2869 return -EINVAL;
2870
2871 acl = parse_acl_data(&rdev->wiphy, info);
2872 if (IS_ERR(acl))
2873 return PTR_ERR(acl);
2874
2875 err = rdev_set_mac_acl(rdev, dev, acl);
2876
2877 kfree(acl);
2878
2879 return err;
2880}
2881
Johannes Berg88600202012-02-13 15:17:18 +01002882static int nl80211_parse_beacon(struct genl_info *info,
2883 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002884{
Johannes Berg88600202012-02-13 15:17:18 +01002885 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002886
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002887 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) ||
2888 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) ||
2889 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2890 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002891 return -EINVAL;
2892
Johannes Berg88600202012-02-13 15:17:18 +01002893 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002894
Johannes Berged1b6cc2007-12-19 02:03:32 +01002895 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
Johannes Berg88600202012-02-13 15:17:18 +01002896 bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2897 bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
2898 if (!bcn->head_len)
2899 return -EINVAL;
2900 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002901 }
2902
2903 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
Johannes Berg88600202012-02-13 15:17:18 +01002904 bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
2905 bcn->tail_len =
Johannes Berged1b6cc2007-12-19 02:03:32 +01002906 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002907 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002908 }
2909
Johannes Berg4c476992010-10-04 21:36:35 +02002910 if (!haveinfo)
2911 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002912
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002913 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg88600202012-02-13 15:17:18 +01002914 bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]);
2915 bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002916 }
2917
2918 if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002919 bcn->proberesp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002920 nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002921 bcn->proberesp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002922 nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]);
2923 }
2924
2925 if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002926 bcn->assocresp_ies =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002927 nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002928 bcn->assocresp_ies_len =
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002929 nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]);
2930 }
2931
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002932 if (info->attrs[NL80211_ATTR_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002933 bcn->probe_resp =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002934 nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002935 bcn->probe_resp_len =
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002936 nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]);
2937 }
2938
Johannes Berg88600202012-02-13 15:17:18 +01002939 return 0;
2940}
2941
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002942static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2943 struct cfg80211_ap_settings *params)
2944{
2945 struct wireless_dev *wdev;
2946 bool ret = false;
2947
Johannes Berg89a54e42012-06-15 14:33:17 +02002948 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002949 if (wdev->iftype != NL80211_IFTYPE_AP &&
2950 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2951 continue;
2952
Johannes Berg683b6d32012-11-08 21:25:48 +01002953 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002954 continue;
2955
Johannes Berg683b6d32012-11-08 21:25:48 +01002956 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002957 ret = true;
2958 break;
2959 }
2960
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002961 return ret;
2962}
2963
Jouni Malinene39e5b52012-09-30 19:29:39 +03002964static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
2965 enum nl80211_auth_type auth_type,
2966 enum nl80211_commands cmd)
2967{
2968 if (auth_type > NL80211_AUTHTYPE_MAX)
2969 return false;
2970
2971 switch (cmd) {
2972 case NL80211_CMD_AUTHENTICATE:
2973 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
2974 auth_type == NL80211_AUTHTYPE_SAE)
2975 return false;
2976 return true;
2977 case NL80211_CMD_CONNECT:
2978 case NL80211_CMD_START_AP:
2979 /* SAE not supported yet */
2980 if (auth_type == NL80211_AUTHTYPE_SAE)
2981 return false;
2982 return true;
2983 default:
2984 return false;
2985 }
2986}
2987
Johannes Berg88600202012-02-13 15:17:18 +01002988static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2989{
2990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2991 struct net_device *dev = info->user_ptr[1];
2992 struct wireless_dev *wdev = dev->ieee80211_ptr;
2993 struct cfg80211_ap_settings params;
2994 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01002995 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01002996
2997 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2998 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2999 return -EOPNOTSUPP;
3000
3001 if (!rdev->ops->start_ap)
3002 return -EOPNOTSUPP;
3003
3004 if (wdev->beacon_interval)
3005 return -EALREADY;
3006
3007 memset(&params, 0, sizeof(params));
3008
3009 /* these are required for START_AP */
3010 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3011 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3012 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3013 return -EINVAL;
3014
3015 err = nl80211_parse_beacon(info, &params.beacon);
3016 if (err)
3017 return err;
3018
3019 params.beacon_interval =
3020 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3021 params.dtim_period =
3022 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3023
3024 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3025 if (err)
3026 return err;
3027
3028 /*
3029 * In theory, some of these attributes should be required here
3030 * but since they were not used when the command was originally
3031 * added, keep them optional for old user space programs to let
3032 * them continue to work with drivers that do not need the
3033 * additional information -- drivers must check!
3034 */
3035 if (info->attrs[NL80211_ATTR_SSID]) {
3036 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3037 params.ssid_len =
3038 nla_len(info->attrs[NL80211_ATTR_SSID]);
3039 if (params.ssid_len == 0 ||
3040 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3041 return -EINVAL;
3042 }
3043
3044 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3045 params.hidden_ssid = nla_get_u32(
3046 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3047 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3048 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3049 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3050 return -EINVAL;
3051 }
3052
3053 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3054
3055 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3056 params.auth_type = nla_get_u32(
3057 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003058 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3059 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003060 return -EINVAL;
3061 } else
3062 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3063
3064 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3065 NL80211_MAX_NR_CIPHER_SUITES);
3066 if (err)
3067 return err;
3068
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303069 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3070 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3071 return -EOPNOTSUPP;
3072 params.inactivity_timeout = nla_get_u16(
3073 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3074 }
3075
Johannes Berg53cabad2012-11-14 15:17:28 +01003076 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3078 return -EINVAL;
3079 params.p2p_ctwindow =
3080 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3081 if (params.p2p_ctwindow > 127)
3082 return -EINVAL;
3083 if (params.p2p_ctwindow != 0 &&
3084 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3085 return -EINVAL;
3086 }
3087
3088 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3089 u8 tmp;
3090
3091 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3092 return -EINVAL;
3093 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3094 if (tmp > 1)
3095 return -EINVAL;
3096 params.p2p_opp_ps = tmp;
3097 if (params.p2p_opp_ps != 0 &&
3098 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3099 return -EINVAL;
3100 }
3101
Johannes Bergaa430da2012-05-16 23:50:18 +02003102 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003103 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3104 if (err)
3105 return err;
3106 } else if (wdev->preset_chandef.chan) {
3107 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003108 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003109 return -EINVAL;
3110
Johannes Berg683b6d32012-11-08 21:25:48 +01003111 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003112 return -EINVAL;
3113
Simon Wunderlich04f39042013-02-08 18:16:19 +01003114 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3115 if (err < 0)
3116 return err;
3117 if (err) {
3118 radar_detect_width = BIT(params.chandef.width);
3119 params.radar_required = true;
3120 }
3121
Simon Wunderlich04f39042013-02-08 18:16:19 +01003122 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3123 params.chandef.chan,
3124 CHAN_MODE_SHARED,
3125 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003126 if (err)
3127 return err;
3128
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303129 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3130 params.acl = parse_acl_data(&rdev->wiphy, info);
3131 if (IS_ERR(params.acl))
3132 return PTR_ERR(params.acl);
3133 }
3134
Hila Gonene35e4d22012-06-27 17:19:42 +03003135 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003136 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003137 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003138 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003139 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003140 wdev->ssid_len = params.ssid_len;
3141 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003142 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303143
3144 kfree(params.acl);
3145
Johannes Berg56d18932011-05-09 18:41:15 +02003146 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003147}
3148
Johannes Berg88600202012-02-13 15:17:18 +01003149static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3150{
3151 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3152 struct net_device *dev = info->user_ptr[1];
3153 struct wireless_dev *wdev = dev->ieee80211_ptr;
3154 struct cfg80211_beacon_data params;
3155 int err;
3156
3157 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3158 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3159 return -EOPNOTSUPP;
3160
3161 if (!rdev->ops->change_beacon)
3162 return -EOPNOTSUPP;
3163
3164 if (!wdev->beacon_interval)
3165 return -EINVAL;
3166
3167 err = nl80211_parse_beacon(info, &params);
3168 if (err)
3169 return err;
3170
Hila Gonene35e4d22012-06-27 17:19:42 +03003171 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003172}
3173
3174static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003175{
Johannes Berg4c476992010-10-04 21:36:35 +02003176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3177 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003178
Michal Kazior60771782012-06-29 12:46:56 +02003179 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003180}
3181
Johannes Berg5727ef12007-12-19 02:03:34 +01003182static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3183 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3184 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3185 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003186 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003187 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003188 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003189};
3190
Johannes Bergeccb8e82009-05-11 21:57:56 +03003191static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003192 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003193 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003194{
3195 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003196 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003197 int flag;
3198
Johannes Bergeccb8e82009-05-11 21:57:56 +03003199 /*
3200 * Try parsing the new attribute first so userspace
3201 * can specify both for older kernels.
3202 */
3203 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3204 if (nla) {
3205 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003206
Johannes Bergeccb8e82009-05-11 21:57:56 +03003207 sta_flags = nla_data(nla);
3208 params->sta_flags_mask = sta_flags->mask;
3209 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003210 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003211 if ((params->sta_flags_mask |
3212 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3213 return -EINVAL;
3214 return 0;
3215 }
3216
3217 /* if present, parse the old attribute */
3218
3219 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003220 if (!nla)
3221 return 0;
3222
3223 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3224 nla, sta_flags_policy))
3225 return -EINVAL;
3226
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003227 /*
3228 * Only allow certain flags for interface types so that
3229 * other attributes are silently ignored. Remember that
3230 * this is backward compatibility code with old userspace
3231 * and shouldn't be hit in other cases anyway.
3232 */
3233 switch (iftype) {
3234 case NL80211_IFTYPE_AP:
3235 case NL80211_IFTYPE_AP_VLAN:
3236 case NL80211_IFTYPE_P2P_GO:
3237 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3238 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3239 BIT(NL80211_STA_FLAG_WME) |
3240 BIT(NL80211_STA_FLAG_MFP);
3241 break;
3242 case NL80211_IFTYPE_P2P_CLIENT:
3243 case NL80211_IFTYPE_STATION:
3244 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3245 BIT(NL80211_STA_FLAG_TDLS_PEER);
3246 break;
3247 case NL80211_IFTYPE_MESH_POINT:
3248 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3249 BIT(NL80211_STA_FLAG_MFP) |
3250 BIT(NL80211_STA_FLAG_AUTHORIZED);
3251 default:
3252 return -EINVAL;
3253 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003254
Johannes Berg3383b5a2012-05-10 20:14:43 +02003255 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3256 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003257 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003258
Johannes Berg3383b5a2012-05-10 20:14:43 +02003259 /* no longer support new API additions in old API */
3260 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3261 return -EINVAL;
3262 }
3263 }
3264
Johannes Berg5727ef12007-12-19 02:03:34 +01003265 return 0;
3266}
3267
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003268static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3269 int attr)
3270{
3271 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003272 u32 bitrate;
3273 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003274
3275 rate = nla_nest_start(msg, attr);
3276 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003277 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003278
3279 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3280 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003281 /* report 16-bit bitrate only if we can */
3282 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003283 if (bitrate > 0 &&
3284 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3285 return false;
3286 if (bitrate_compat > 0 &&
3287 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3288 return false;
3289
3290 if (info->flags & RATE_INFO_FLAGS_MCS) {
3291 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3292 return false;
3293 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3294 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3295 return false;
3296 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3297 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3298 return false;
3299 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3300 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3301 return false;
3302 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3303 return false;
3304 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3305 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3306 return false;
3307 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3308 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3309 return false;
3310 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3311 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3312 return false;
3313 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3314 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3315 return false;
3316 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3317 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3318 return false;
3319 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003320
3321 nla_nest_end(msg, rate);
3322 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003323}
3324
Felix Fietkau119363c2013-04-22 16:29:30 +02003325static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3326 int id)
3327{
3328 void *attr;
3329 int i = 0;
3330
3331 if (!mask)
3332 return true;
3333
3334 attr = nla_nest_start(msg, id);
3335 if (!attr)
3336 return false;
3337
3338 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3339 if (!(mask & BIT(i)))
3340 continue;
3341
3342 if (nla_put_u8(msg, i, signal[i]))
3343 return false;
3344 }
3345
3346 nla_nest_end(msg, attr);
3347
3348 return true;
3349}
3350
Eric W. Biederman15e47302012-09-07 20:12:54 +00003351static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003352 int flags,
3353 struct cfg80211_registered_device *rdev,
3354 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003355 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003356{
3357 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003358 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003359
Eric W. Biederman15e47302012-09-07 20:12:54 +00003360 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003361 if (!hdr)
3362 return -1;
3363
David S. Miller9360ffd2012-03-29 04:41:26 -04003364 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3366 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3367 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003368
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003369 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3370 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003371 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003372 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3373 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3374 sinfo->connected_time))
3375 goto nla_put_failure;
3376 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3377 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3378 sinfo->inactive_time))
3379 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003380 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3381 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003382 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003383 (u32)sinfo->rx_bytes))
3384 goto nla_put_failure;
3385 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003386 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003387 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3388 (u32)sinfo->tx_bytes))
3389 goto nla_put_failure;
3390 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3391 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003392 sinfo->rx_bytes))
3393 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003394 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3395 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003396 sinfo->tx_bytes))
3397 goto nla_put_failure;
3398 if ((sinfo->filled & STATION_INFO_LLID) &&
3399 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3400 goto nla_put_failure;
3401 if ((sinfo->filled & STATION_INFO_PLID) &&
3402 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3403 goto nla_put_failure;
3404 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3405 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3406 sinfo->plink_state))
3407 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003408 switch (rdev->wiphy.signal_type) {
3409 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3411 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3412 sinfo->signal))
3413 goto nla_put_failure;
3414 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3415 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3416 sinfo->signal_avg))
3417 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003418 break;
3419 default:
3420 break;
3421 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003422 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3423 if (!nl80211_put_signal(msg, sinfo->chains,
3424 sinfo->chain_signal,
3425 NL80211_STA_INFO_CHAIN_SIGNAL))
3426 goto nla_put_failure;
3427 }
3428 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3429 if (!nl80211_put_signal(msg, sinfo->chains,
3430 sinfo->chain_signal_avg,
3431 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3432 goto nla_put_failure;
3433 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003434 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003435 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3436 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003437 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003438 }
3439 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3440 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3441 NL80211_STA_INFO_RX_BITRATE))
3442 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003443 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003444 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3445 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3446 sinfo->rx_packets))
3447 goto nla_put_failure;
3448 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3449 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3450 sinfo->tx_packets))
3451 goto nla_put_failure;
3452 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3453 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3454 sinfo->tx_retries))
3455 goto nla_put_failure;
3456 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3457 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3458 sinfo->tx_failed))
3459 goto nla_put_failure;
3460 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3461 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3462 sinfo->beacon_loss_count))
3463 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003464 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3465 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3466 sinfo->local_pm))
3467 goto nla_put_failure;
3468 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3469 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3470 sinfo->peer_pm))
3471 goto nla_put_failure;
3472 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3473 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3474 sinfo->nonpeer_pm))
3475 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003476 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3477 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3478 if (!bss_param)
3479 goto nla_put_failure;
3480
David S. Miller9360ffd2012-03-29 04:41:26 -04003481 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3482 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3483 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3484 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3485 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3486 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3487 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3488 sinfo->bss_param.dtim_period) ||
3489 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3490 sinfo->bss_param.beacon_interval))
3491 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003492
3493 nla_nest_end(msg, bss_param);
3494 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003495 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3496 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3497 sizeof(struct nl80211_sta_flag_update),
3498 &sinfo->sta_flags))
3499 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003500 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3501 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3502 sinfo->t_offset))
3503 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003504 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003505
David S. Miller9360ffd2012-03-29 04:41:26 -04003506 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3507 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3508 sinfo->assoc_req_ies))
3509 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003510
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003511 return genlmsg_end(msg, hdr);
3512
3513 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003514 genlmsg_cancel(msg, hdr);
3515 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003516}
3517
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003518static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003519 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003520{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003521 struct station_info sinfo;
3522 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003523 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003524 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003525 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003526 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003527
Johannes Berg97990a02013-04-19 01:02:55 +02003528 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003529 if (err)
3530 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003531
Johannes Berg97990a02013-04-19 01:02:55 +02003532 if (!wdev->netdev) {
3533 err = -EINVAL;
3534 goto out_err;
3535 }
3536
Johannes Bergbba95fe2008-07-29 13:22:51 +02003537 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003538 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 goto out_err;
3540 }
3541
Johannes Bergbba95fe2008-07-29 13:22:51 +02003542 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003543 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003544 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003545 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003546 if (err == -ENOENT)
3547 break;
3548 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003549 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003550
3551 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003554 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003555 &sinfo) < 0)
3556 goto out;
3557
3558 sta_idx++;
3559 }
3560
3561
3562 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003563 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003565 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003566 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003567
3568 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003569}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003570
Johannes Berg5727ef12007-12-19 02:03:34 +01003571static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3572{
Johannes Berg4c476992010-10-04 21:36:35 +02003573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003575 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003576 struct sk_buff *msg;
3577 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003578 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003579
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003580 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003581
3582 if (!info->attrs[NL80211_ATTR_MAC])
3583 return -EINVAL;
3584
3585 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3586
Johannes Berg4c476992010-10-04 21:36:35 +02003587 if (!rdev->ops->get_station)
3588 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589
Hila Gonene35e4d22012-06-27 17:19:42 +03003590 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003592 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003595 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003596 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003597
Eric W. Biederman15e47302012-09-07 20:12:54 +00003598 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003599 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003600 nlmsg_free(msg);
3601 return -ENOBUFS;
3602 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003603
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003605}
3606
Johannes Berg77ee7c82013-02-15 00:48:33 +01003607int cfg80211_check_station_change(struct wiphy *wiphy,
3608 struct station_parameters *params,
3609 enum cfg80211_station_type statype)
3610{
3611 if (params->listen_interval != -1)
3612 return -EINVAL;
3613 if (params->aid)
3614 return -EINVAL;
3615
3616 /* When you run into this, adjust the code below for the new flag */
3617 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3618
3619 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003620 case CFG80211_STA_MESH_PEER_KERNEL:
3621 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003622 /*
3623 * No ignoring the TDLS flag here -- the userspace mesh
3624 * code doesn't have the bug of including TDLS in the
3625 * mask everywhere.
3626 */
3627 if (params->sta_flags_mask &
3628 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3629 BIT(NL80211_STA_FLAG_MFP) |
3630 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3631 return -EINVAL;
3632 break;
3633 case CFG80211_STA_TDLS_PEER_SETUP:
3634 case CFG80211_STA_TDLS_PEER_ACTIVE:
3635 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3636 return -EINVAL;
3637 /* ignore since it can't change */
3638 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3639 break;
3640 default:
3641 /* disallow mesh-specific things */
3642 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3643 return -EINVAL;
3644 if (params->local_pm)
3645 return -EINVAL;
3646 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3647 return -EINVAL;
3648 }
3649
3650 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3651 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3652 /* TDLS can't be set, ... */
3653 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3654 return -EINVAL;
3655 /*
3656 * ... but don't bother the driver with it. This works around
3657 * a hostapd/wpa_supplicant issue -- it always includes the
3658 * TLDS_PEER flag in the mask even for AP mode.
3659 */
3660 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3661 }
3662
3663 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3664 /* reject other things that can't change */
3665 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3666 return -EINVAL;
3667 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3668 return -EINVAL;
3669 if (params->supported_rates)
3670 return -EINVAL;
3671 if (params->ext_capab || params->ht_capa || params->vht_capa)
3672 return -EINVAL;
3673 }
3674
3675 if (statype != CFG80211_STA_AP_CLIENT) {
3676 if (params->vlan)
3677 return -EINVAL;
3678 }
3679
3680 switch (statype) {
3681 case CFG80211_STA_AP_MLME_CLIENT:
3682 /* Use this only for authorizing/unauthorizing a station */
3683 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3684 return -EOPNOTSUPP;
3685 break;
3686 case CFG80211_STA_AP_CLIENT:
3687 /* accept only the listed bits */
3688 if (params->sta_flags_mask &
3689 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3690 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3691 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3692 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3693 BIT(NL80211_STA_FLAG_WME) |
3694 BIT(NL80211_STA_FLAG_MFP)))
3695 return -EINVAL;
3696
3697 /* but authenticated/associated only if driver handles it */
3698 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3699 params->sta_flags_mask &
3700 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3701 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3702 return -EINVAL;
3703 break;
3704 case CFG80211_STA_IBSS:
3705 case CFG80211_STA_AP_STA:
3706 /* reject any changes other than AUTHORIZED */
3707 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3708 return -EINVAL;
3709 break;
3710 case CFG80211_STA_TDLS_PEER_SETUP:
3711 /* reject any changes other than AUTHORIZED or WME */
3712 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3713 BIT(NL80211_STA_FLAG_WME)))
3714 return -EINVAL;
3715 /* force (at least) rates when authorizing */
3716 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3717 !params->supported_rates)
3718 return -EINVAL;
3719 break;
3720 case CFG80211_STA_TDLS_PEER_ACTIVE:
3721 /* reject any changes */
3722 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003723 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003724 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3725 return -EINVAL;
3726 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003727 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003728 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3729 return -EINVAL;
3730 break;
3731 }
3732
3733 return 0;
3734}
3735EXPORT_SYMBOL(cfg80211_check_station_change);
3736
Johannes Berg5727ef12007-12-19 02:03:34 +01003737/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003738 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003739 */
Johannes Berg80b99892011-11-18 16:23:01 +01003740static struct net_device *get_vlan(struct genl_info *info,
3741 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003742{
Johannes Berg463d0182009-07-14 00:33:35 +02003743 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003744 struct net_device *v;
3745 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003746
Johannes Berg80b99892011-11-18 16:23:01 +01003747 if (!vlanattr)
3748 return NULL;
3749
3750 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3751 if (!v)
3752 return ERR_PTR(-ENODEV);
3753
3754 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3755 ret = -EINVAL;
3756 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003757 }
Johannes Berg80b99892011-11-18 16:23:01 +01003758
Johannes Berg77ee7c82013-02-15 00:48:33 +01003759 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3760 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3761 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3762 ret = -EINVAL;
3763 goto error;
3764 }
3765
Johannes Berg80b99892011-11-18 16:23:01 +01003766 if (!netif_running(v)) {
3767 ret = -ENETDOWN;
3768 goto error;
3769 }
3770
3771 return v;
3772 error:
3773 dev_put(v);
3774 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003775}
3776
Jouni Malinendf881292013-02-14 21:10:54 +02003777static struct nla_policy
3778nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3779 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3780 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3781};
3782
Johannes Bergff276692013-02-15 00:09:01 +01003783static int nl80211_parse_sta_wme(struct genl_info *info,
3784 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003785{
Jouni Malinendf881292013-02-14 21:10:54 +02003786 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3787 struct nlattr *nla;
3788 int err;
3789
Jouni Malinendf881292013-02-14 21:10:54 +02003790 /* parse WME attributes if present */
3791 if (!info->attrs[NL80211_ATTR_STA_WME])
3792 return 0;
3793
3794 nla = info->attrs[NL80211_ATTR_STA_WME];
3795 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3796 nl80211_sta_wme_policy);
3797 if (err)
3798 return err;
3799
3800 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3801 params->uapsd_queues = nla_get_u8(
3802 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3803 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3804 return -EINVAL;
3805
3806 if (tb[NL80211_STA_WME_MAX_SP])
3807 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3808
3809 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3810 return -EINVAL;
3811
3812 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3813
3814 return 0;
3815}
3816
Johannes Bergff276692013-02-15 00:09:01 +01003817static int nl80211_set_station_tdls(struct genl_info *info,
3818 struct station_parameters *params)
3819{
3820 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003821 if (info->attrs[NL80211_ATTR_PEER_AID])
3822 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003823 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3824 params->ht_capa =
3825 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3826 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3827 params->vht_capa =
3828 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3829
3830 return nl80211_parse_sta_wme(info, params);
3831}
3832
Johannes Berg5727ef12007-12-19 02:03:34 +01003833static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3834{
Johannes Berg4c476992010-10-04 21:36:35 +02003835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003836 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003837 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003838 u8 *mac_addr;
3839 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003840
3841 memset(&params, 0, sizeof(params));
3842
3843 params.listen_interval = -1;
3844
Johannes Berg77ee7c82013-02-15 00:48:33 +01003845 if (!rdev->ops->change_station)
3846 return -EOPNOTSUPP;
3847
Johannes Berg5727ef12007-12-19 02:03:34 +01003848 if (info->attrs[NL80211_ATTR_STA_AID])
3849 return -EINVAL;
3850
3851 if (!info->attrs[NL80211_ATTR_MAC])
3852 return -EINVAL;
3853
3854 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3855
3856 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3857 params.supported_rates =
3858 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3859 params.supported_rates_len =
3860 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3861 }
3862
Jouni Malinen9d62a982013-02-14 21:10:13 +02003863 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3864 params.capability =
3865 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3866 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3867 }
3868
3869 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3870 params.ext_capab =
3871 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3872 params.ext_capab_len =
3873 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3874 }
3875
Jouni Malinendf881292013-02-14 21:10:54 +02003876 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003877 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003878
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003879 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003880 return -EINVAL;
3881
Johannes Bergf8bacc22013-02-14 23:27:01 +01003882 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003883 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003884 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3885 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3886 return -EINVAL;
3887 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003888
Johannes Bergf8bacc22013-02-14 23:27:01 +01003889 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003890 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003891 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3892 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3893 return -EINVAL;
3894 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3895 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003896
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003897 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3898 enum nl80211_mesh_power_mode pm = nla_get_u32(
3899 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3900
3901 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3902 pm > NL80211_MESH_POWER_MAX)
3903 return -EINVAL;
3904
3905 params.local_pm = pm;
3906 }
3907
Johannes Berg77ee7c82013-02-15 00:48:33 +01003908 /* Include parameters for TDLS peer (will check later) */
3909 err = nl80211_set_station_tdls(info, &params);
3910 if (err)
3911 return err;
3912
3913 params.vlan = get_vlan(info, rdev);
3914 if (IS_ERR(params.vlan))
3915 return PTR_ERR(params.vlan);
3916
Johannes Berga97f4422009-06-18 17:23:43 +02003917 switch (dev->ieee80211_ptr->iftype) {
3918 case NL80211_IFTYPE_AP:
3919 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003920 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003921 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003922 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003923 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003924 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003925 break;
3926 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003927 err = -EOPNOTSUPP;
3928 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003929 }
3930
Johannes Berg77ee7c82013-02-15 00:48:33 +01003931 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003932 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003933
Johannes Berg77ee7c82013-02-15 00:48:33 +01003934 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003935 if (params.vlan)
3936 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003937
Johannes Berg5727ef12007-12-19 02:03:34 +01003938 return err;
3939}
3940
3941static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3942{
Johannes Berg4c476992010-10-04 21:36:35 +02003943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003944 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003945 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003946 struct station_parameters params;
3947 u8 *mac_addr = NULL;
3948
3949 memset(&params, 0, sizeof(params));
3950
Johannes Berg984c3112013-02-14 23:43:25 +01003951 if (!rdev->ops->add_station)
3952 return -EOPNOTSUPP;
3953
Johannes Berg5727ef12007-12-19 02:03:34 +01003954 if (!info->attrs[NL80211_ATTR_MAC])
3955 return -EINVAL;
3956
Johannes Berg5727ef12007-12-19 02:03:34 +01003957 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3958 return -EINVAL;
3959
3960 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3961 return -EINVAL;
3962
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003963 if (!info->attrs[NL80211_ATTR_STA_AID] &&
3964 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003965 return -EINVAL;
3966
Johannes Berg5727ef12007-12-19 02:03:34 +01003967 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3968 params.supported_rates =
3969 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3970 params.supported_rates_len =
3971 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3972 params.listen_interval =
3973 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02003974
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003975 if (info->attrs[NL80211_ATTR_STA_AID])
3976 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
3977 else
3978 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02003979 if (!params.aid || params.aid > IEEE80211_MAX_AID)
3980 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02003981
Jouni Malinen9d62a982013-02-14 21:10:13 +02003982 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3983 params.capability =
3984 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3985 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3986 }
3987
3988 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3989 params.ext_capab =
3990 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3991 params.ext_capab_len =
3992 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3993 }
3994
Jouni Malinen36aedc902008-08-25 11:58:58 +03003995 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3996 params.ht_capa =
3997 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01003998
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00003999 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4000 params.vht_capa =
4001 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4002
Johannes Bergf8bacc22013-02-14 23:27:01 +01004003 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004004 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004005 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4006 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4007 return -EINVAL;
4008 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004009
Johannes Bergff276692013-02-15 00:09:01 +01004010 err = nl80211_parse_sta_wme(info, &params);
4011 if (err)
4012 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004013
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004014 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004015 return -EINVAL;
4016
Johannes Berg77ee7c82013-02-15 00:48:33 +01004017 /* When you run into this, adjust the code below for the new flag */
4018 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4019
Johannes Bergbdd90d52011-12-14 12:20:27 +01004020 switch (dev->ieee80211_ptr->iftype) {
4021 case NL80211_IFTYPE_AP:
4022 case NL80211_IFTYPE_AP_VLAN:
4023 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004024 /* ignore WME attributes if iface/sta is not capable */
4025 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4026 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4027 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004028
Johannes Bergbdd90d52011-12-14 12:20:27 +01004029 /* TDLS peers cannot be added */
4030 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004031 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004032 /* but don't bother the driver with it */
4033 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004034
Johannes Bergd582cff2012-10-26 17:53:44 +02004035 /* allow authenticated/associated only if driver handles it */
4036 if (!(rdev->wiphy.features &
4037 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4038 params.sta_flags_mask &
4039 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4040 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4041 return -EINVAL;
4042
Johannes Bergbdd90d52011-12-14 12:20:27 +01004043 /* must be last in here for error handling */
4044 params.vlan = get_vlan(info, rdev);
4045 if (IS_ERR(params.vlan))
4046 return PTR_ERR(params.vlan);
4047 break;
4048 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004049 /* ignore uAPSD data */
4050 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4051
Johannes Bergd582cff2012-10-26 17:53:44 +02004052 /* associated is disallowed */
4053 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4054 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004055 /* TDLS peers cannot be added */
4056 if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Berg4319e192011-09-07 11:50:48 +02004057 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004058 break;
4059 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004060 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004061 /* ignore uAPSD data */
4062 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4063
Johannes Berg77ee7c82013-02-15 00:48:33 +01004064 /* these are disallowed */
4065 if (params.sta_flags_mask &
4066 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4067 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004068 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004069 /* Only TDLS peers can be added */
4070 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4071 return -EINVAL;
4072 /* Can only add if TDLS ... */
4073 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4074 return -EOPNOTSUPP;
4075 /* ... with external setup is supported */
4076 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4077 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004078 /*
4079 * Older wpa_supplicant versions always mark the TDLS peer
4080 * as authorized, but it shouldn't yet be.
4081 */
4082 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004083 break;
4084 default:
4085 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004086 }
4087
Johannes Bergbdd90d52011-12-14 12:20:27 +01004088 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004089
Hila Gonene35e4d22012-06-27 17:19:42 +03004090 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004091
Johannes Berg5727ef12007-12-19 02:03:34 +01004092 if (params.vlan)
4093 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 return err;
4095}
4096
4097static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4098{
Johannes Berg4c476992010-10-04 21:36:35 +02004099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4100 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004101 u8 *mac_addr = NULL;
4102
4103 if (info->attrs[NL80211_ATTR_MAC])
4104 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4105
Johannes Berge80cf852009-05-11 14:43:13 +02004106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004107 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004108 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004109 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4110 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004111
Johannes Berg4c476992010-10-04 21:36:35 +02004112 if (!rdev->ops->del_station)
4113 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004114
Hila Gonene35e4d22012-06-27 17:19:42 +03004115 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004116}
4117
Eric W. Biederman15e47302012-09-07 20:12:54 +00004118static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004119 int flags, struct net_device *dev,
4120 u8 *dst, u8 *next_hop,
4121 struct mpath_info *pinfo)
4122{
4123 void *hdr;
4124 struct nlattr *pinfoattr;
4125
Eric W. Biederman15e47302012-09-07 20:12:54 +00004126 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004127 if (!hdr)
4128 return -1;
4129
David S. Miller9360ffd2012-03-29 04:41:26 -04004130 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4131 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4132 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4133 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4134 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004135
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004136 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4137 if (!pinfoattr)
4138 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004139 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4140 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4141 pinfo->frame_qlen))
4142 goto nla_put_failure;
4143 if (((pinfo->filled & MPATH_INFO_SN) &&
4144 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4145 ((pinfo->filled & MPATH_INFO_METRIC) &&
4146 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4147 pinfo->metric)) ||
4148 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4149 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4150 pinfo->exptime)) ||
4151 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4152 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4153 pinfo->flags)) ||
4154 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4155 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4156 pinfo->discovery_timeout)) ||
4157 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4158 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4159 pinfo->discovery_retries)))
4160 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004161
4162 nla_nest_end(msg, pinfoattr);
4163
4164 return genlmsg_end(msg, hdr);
4165
4166 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004167 genlmsg_cancel(msg, hdr);
4168 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004169}
4170
4171static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004172 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004173{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004174 struct mpath_info pinfo;
4175 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004176 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004177 u8 dst[ETH_ALEN];
4178 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004179 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004180 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004181
Johannes Berg97990a02013-04-19 01:02:55 +02004182 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004183 if (err)
4184 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004185
4186 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004187 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004188 goto out_err;
4189 }
4190
Johannes Berg97990a02013-04-19 01:02:55 +02004191 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004192 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004193 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004194 }
4195
Johannes Bergbba95fe2008-07-29 13:22:51 +02004196 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004197 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4198 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004199 if (err == -ENOENT)
4200 break;
4201 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004202 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004203
Eric W. Biederman15e47302012-09-07 20:12:54 +00004204 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004205 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004206 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004207 &pinfo) < 0)
4208 goto out;
4209
4210 path_idx++;
4211 }
4212
4213
4214 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004215 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004216 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004217 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004218 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004219 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004220}
4221
4222static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4223{
Johannes Berg4c476992010-10-04 21:36:35 +02004224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004225 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004226 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004227 struct mpath_info pinfo;
4228 struct sk_buff *msg;
4229 u8 *dst = NULL;
4230 u8 next_hop[ETH_ALEN];
4231
4232 memset(&pinfo, 0, sizeof(pinfo));
4233
4234 if (!info->attrs[NL80211_ATTR_MAC])
4235 return -EINVAL;
4236
4237 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4238
Johannes Berg4c476992010-10-04 21:36:35 +02004239 if (!rdev->ops->get_mpath)
4240 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004241
Johannes Berg4c476992010-10-04 21:36:35 +02004242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4243 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004244
Hila Gonene35e4d22012-06-27 17:19:42 +03004245 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004246 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004247 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004250 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004251 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252
Eric W. Biederman15e47302012-09-07 20:12:54 +00004253 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004254 dev, dst, next_hop, &pinfo) < 0) {
4255 nlmsg_free(msg);
4256 return -ENOBUFS;
4257 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258
Johannes Berg4c476992010-10-04 21:36:35 +02004259 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260}
4261
4262static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4263{
Johannes Berg4c476992010-10-04 21:36:35 +02004264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4265 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004266 u8 *dst = NULL;
4267 u8 *next_hop = NULL;
4268
4269 if (!info->attrs[NL80211_ATTR_MAC])
4270 return -EINVAL;
4271
4272 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4273 return -EINVAL;
4274
4275 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4276 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4277
Johannes Berg4c476992010-10-04 21:36:35 +02004278 if (!rdev->ops->change_mpath)
4279 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004280
Johannes Berg4c476992010-10-04 21:36:35 +02004281 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4282 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004283
Hila Gonene35e4d22012-06-27 17:19:42 +03004284 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004285}
Johannes Berg4c476992010-10-04 21:36:35 +02004286
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004287static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4288{
Johannes Berg4c476992010-10-04 21:36:35 +02004289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4290 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004291 u8 *dst = NULL;
4292 u8 *next_hop = NULL;
4293
4294 if (!info->attrs[NL80211_ATTR_MAC])
4295 return -EINVAL;
4296
4297 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4298 return -EINVAL;
4299
4300 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4301 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4302
Johannes Berg4c476992010-10-04 21:36:35 +02004303 if (!rdev->ops->add_mpath)
4304 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004305
Johannes Berg4c476992010-10-04 21:36:35 +02004306 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4307 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004308
Hila Gonene35e4d22012-06-27 17:19:42 +03004309 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004310}
4311
4312static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4313{
Johannes Berg4c476992010-10-04 21:36:35 +02004314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4315 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004316 u8 *dst = NULL;
4317
4318 if (info->attrs[NL80211_ATTR_MAC])
4319 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4320
Johannes Berg4c476992010-10-04 21:36:35 +02004321 if (!rdev->ops->del_mpath)
4322 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004323
Hila Gonene35e4d22012-06-27 17:19:42 +03004324 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325}
4326
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004327static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4328{
Johannes Berg4c476992010-10-04 21:36:35 +02004329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4330 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004331 struct bss_parameters params;
4332
4333 memset(&params, 0, sizeof(params));
4334 /* default to not changing parameters */
4335 params.use_cts_prot = -1;
4336 params.use_short_preamble = -1;
4337 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004338 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004339 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004340 params.p2p_ctwindow = -1;
4341 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004342
4343 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4344 params.use_cts_prot =
4345 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4346 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4347 params.use_short_preamble =
4348 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4349 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4350 params.use_short_slot_time =
4351 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004352 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4353 params.basic_rates =
4354 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4355 params.basic_rates_len =
4356 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4357 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004358 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4359 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004360 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4361 params.ht_opmode =
4362 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004363
Johannes Berg53cabad2012-11-14 15:17:28 +01004364 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4366 return -EINVAL;
4367 params.p2p_ctwindow =
4368 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4369 if (params.p2p_ctwindow < 0)
4370 return -EINVAL;
4371 if (params.p2p_ctwindow != 0 &&
4372 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4373 return -EINVAL;
4374 }
4375
4376 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4377 u8 tmp;
4378
4379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4380 return -EINVAL;
4381 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4382 if (tmp > 1)
4383 return -EINVAL;
4384 params.p2p_opp_ps = tmp;
4385 if (params.p2p_opp_ps &&
4386 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4387 return -EINVAL;
4388 }
4389
Johannes Berg4c476992010-10-04 21:36:35 +02004390 if (!rdev->ops->change_bss)
4391 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004392
Johannes Berg074ac8d2010-09-16 14:58:22 +02004393 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004394 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4395 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004396
Hila Gonene35e4d22012-06-27 17:19:42 +03004397 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004398}
4399
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004400static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004401 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4402 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4403 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4404 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4405 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4406 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4407};
4408
4409static int parse_reg_rule(struct nlattr *tb[],
4410 struct ieee80211_reg_rule *reg_rule)
4411{
4412 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4413 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4414
4415 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4416 return -EINVAL;
4417 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4418 return -EINVAL;
4419 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4420 return -EINVAL;
4421 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4422 return -EINVAL;
4423 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4424 return -EINVAL;
4425
4426 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4427
4428 freq_range->start_freq_khz =
4429 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4430 freq_range->end_freq_khz =
4431 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4432 freq_range->max_bandwidth_khz =
4433 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4434
4435 power_rule->max_eirp =
4436 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4437
4438 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4439 power_rule->max_antenna_gain =
4440 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4441
4442 return 0;
4443}
4444
4445static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4446{
4447 int r;
4448 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004449 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004450
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004451 /*
4452 * You should only get this when cfg80211 hasn't yet initialized
4453 * completely when built-in to the kernel right between the time
4454 * window between nl80211_init() and regulatory_init(), if that is
4455 * even possible.
4456 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004457 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004458 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004459
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004460 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4461 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004462
4463 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4464
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004465 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4466 user_reg_hint_type =
4467 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4468 else
4469 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4470
4471 switch (user_reg_hint_type) {
4472 case NL80211_USER_REG_HINT_USER:
4473 case NL80211_USER_REG_HINT_CELL_BASE:
4474 break;
4475 default:
4476 return -EINVAL;
4477 }
4478
4479 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004480
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004481 return r;
4482}
4483
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004484static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004485 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004486{
Johannes Berg4c476992010-10-04 21:36:35 +02004487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004488 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004489 struct wireless_dev *wdev = dev->ieee80211_ptr;
4490 struct mesh_config cur_params;
4491 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004492 void *hdr;
4493 struct nlattr *pinfoattr;
4494 struct sk_buff *msg;
4495
Johannes Berg29cbe682010-12-03 09:20:44 +01004496 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4497 return -EOPNOTSUPP;
4498
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004499 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004500 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004501
Johannes Berg29cbe682010-12-03 09:20:44 +01004502 wdev_lock(wdev);
4503 /* If not connected, get default parameters */
4504 if (!wdev->mesh_id_len)
4505 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4506 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004507 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004508 wdev_unlock(wdev);
4509
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004510 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004511 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004512
4513 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004515 if (!msg)
4516 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004517 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004518 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004519 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004520 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004521 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004522 if (!pinfoattr)
4523 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004524 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4525 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4526 cur_params.dot11MeshRetryTimeout) ||
4527 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4528 cur_params.dot11MeshConfirmTimeout) ||
4529 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4530 cur_params.dot11MeshHoldingTimeout) ||
4531 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4532 cur_params.dot11MeshMaxPeerLinks) ||
4533 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4534 cur_params.dot11MeshMaxRetries) ||
4535 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4536 cur_params.dot11MeshTTL) ||
4537 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4538 cur_params.element_ttl) ||
4539 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4540 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004541 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4542 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004543 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4544 cur_params.dot11MeshHWMPmaxPREQretries) ||
4545 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4546 cur_params.path_refresh_time) ||
4547 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4548 cur_params.min_discovery_timeout) ||
4549 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4550 cur_params.dot11MeshHWMPactivePathTimeout) ||
4551 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4552 cur_params.dot11MeshHWMPpreqMinInterval) ||
4553 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4554 cur_params.dot11MeshHWMPperrMinInterval) ||
4555 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4556 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4557 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4558 cur_params.dot11MeshHWMPRootMode) ||
4559 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4560 cur_params.dot11MeshHWMPRannInterval) ||
4561 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4562 cur_params.dot11MeshGateAnnouncementProtocol) ||
4563 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4564 cur_params.dot11MeshForwarding) ||
4565 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004566 cur_params.rssi_threshold) ||
4567 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004568 cur_params.ht_opmode) ||
4569 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4570 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4571 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004572 cur_params.dot11MeshHWMProotInterval) ||
4573 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004574 cur_params.dot11MeshHWMPconfirmationInterval) ||
4575 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4576 cur_params.power_mode) ||
4577 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
4578 cur_params.dot11MeshAwakeWindowDuration))
David S. Miller9360ffd2012-03-29 04:41:26 -04004579 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004580 nla_nest_end(msg, pinfoattr);
4581 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004582 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004583
Johannes Berg3b858752009-03-12 09:55:09 +01004584 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004586 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004587 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004588 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004589}
4590
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004591static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004592 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4593 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4594 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4595 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4596 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4597 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004598 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004599 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004600 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004601 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4602 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4603 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4604 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4605 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004606 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004607 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004608 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004609 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004610 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004611 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004612 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4613 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004614 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4615 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004616 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004617 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4618 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004619};
4620
Javier Cardonac80d5452010-12-16 17:37:49 -08004621static const struct nla_policy
4622 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004623 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004624 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4625 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004626 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004627 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004628 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004629 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004630 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004631 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004632};
4633
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004634static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004635 struct mesh_config *cfg,
4636 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004637{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004638 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004639 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004640
Marco Porschea54fba2013-01-07 16:04:48 +01004641#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4642do { \
4643 if (tb[attr]) { \
4644 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4645 return -EINVAL; \
4646 cfg->param = fn(tb[attr]); \
4647 mask |= (1 << (attr - 1)); \
4648 } \
4649} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004650
4651
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004652 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004653 return -EINVAL;
4654 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004655 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004656 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004657 return -EINVAL;
4658
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004659 /* This makes sure that there aren't more than 32 mesh config
4660 * parameters (otherwise our bitfield scheme would not work.) */
4661 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4662
4663 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004664 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004665 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4666 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004667 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004668 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4669 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004670 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004671 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4672 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004674 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4675 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004676 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004677 mask, NL80211_MESHCONF_MAX_RETRIES,
4678 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004679 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004680 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004681 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004682 mask, NL80211_MESHCONF_ELEMENT_TTL,
4683 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004684 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004685 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4686 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004687 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4688 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004689 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4690 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004691 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004692 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4693 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004694 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004695 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4696 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004697 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004698 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4699 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4701 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004702 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4703 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004704 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004705 1, 65535, mask,
4706 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004707 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004708 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004709 1, 65535, mask,
4710 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004711 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004713 dot11MeshHWMPnetDiameterTraversalTime,
4714 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004715 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4716 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004717 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4718 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4719 nla_get_u8);
4720 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4721 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004722 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004723 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004724 dot11MeshGateAnnouncementProtocol, 0, 1,
4725 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004726 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004728 mask, NL80211_MESHCONF_FORWARDING,
4729 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004731 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4732 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004733 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004734 mask, NL80211_MESHCONF_HT_OPMODE,
4735 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004736 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004737 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004738 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4739 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004741 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4742 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004744 dot11MeshHWMPconfirmationInterval,
4745 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004746 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4747 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4749 NL80211_MESH_POWER_ACTIVE,
4750 NL80211_MESH_POWER_MAX,
4751 mask, NL80211_MESHCONF_POWER_MODE,
4752 nla_get_u32);
4753 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4754 0, 65535, mask,
4755 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004756 if (mask_out)
4757 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004758
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004759 return 0;
4760
4761#undef FILL_IN_MESH_PARAM_IF_SET
4762}
4763
Javier Cardonac80d5452010-12-16 17:37:49 -08004764static int nl80211_parse_mesh_setup(struct genl_info *info,
4765 struct mesh_setup *setup)
4766{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004768 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4769
4770 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4771 return -EINVAL;
4772 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4773 info->attrs[NL80211_ATTR_MESH_SETUP],
4774 nl80211_mesh_setup_params_policy))
4775 return -EINVAL;
4776
Javier Cardonad299a1f2012-03-31 11:31:33 -07004777 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4778 setup->sync_method =
4779 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4780 IEEE80211_SYNC_METHOD_VENDOR :
4781 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4782
Javier Cardonac80d5452010-12-16 17:37:49 -08004783 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4784 setup->path_sel_proto =
4785 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4786 IEEE80211_PATH_PROTOCOL_VENDOR :
4787 IEEE80211_PATH_PROTOCOL_HWMP;
4788
4789 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4790 setup->path_metric =
4791 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4792 IEEE80211_PATH_METRIC_VENDOR :
4793 IEEE80211_PATH_METRIC_AIRTIME;
4794
Javier Cardona581a8b02011-04-07 15:08:27 -07004795
4796 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004797 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004798 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004799 if (!is_valid_ie_attr(ieattr))
4800 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004801 setup->ie = nla_data(ieattr);
4802 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004803 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004804 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4805 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4806 return -EINVAL;
4807 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004808 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4809 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004810 if (setup->is_secure)
4811 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004812
Colleen Twitty6e16d902013-05-08 11:45:59 -07004813 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4814 if (!setup->user_mpm)
4815 return -EINVAL;
4816 setup->auth_id =
4817 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4818 }
4819
Javier Cardonac80d5452010-12-16 17:37:49 -08004820 return 0;
4821}
4822
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004823static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004824 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004825{
4826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4827 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004828 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004829 struct mesh_config cfg;
4830 u32 mask;
4831 int err;
4832
Johannes Berg29cbe682010-12-03 09:20:44 +01004833 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4834 return -EOPNOTSUPP;
4835
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004836 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004837 return -EOPNOTSUPP;
4838
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004839 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840 if (err)
4841 return err;
4842
Johannes Berg29cbe682010-12-03 09:20:44 +01004843 wdev_lock(wdev);
4844 if (!wdev->mesh_id_len)
4845 err = -ENOLINK;
4846
4847 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004848 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004849
4850 wdev_unlock(wdev);
4851
4852 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004853}
4854
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004855static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4856{
Johannes Berg458f4f92012-12-06 15:47:38 +01004857 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004858 struct sk_buff *msg;
4859 void *hdr = NULL;
4860 struct nlattr *nl_reg_rules;
4861 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004862
4863 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004864 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004865
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004867 if (!msg)
4868 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004869
Eric W. Biederman15e47302012-09-07 20:12:54 +00004870 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004871 NL80211_CMD_GET_REG);
4872 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004873 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004874
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004875 if (reg_last_request_cell_base() &&
4876 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4877 NL80211_USER_REG_HINT_CELL_BASE))
4878 goto nla_put_failure;
4879
Johannes Berg458f4f92012-12-06 15:47:38 +01004880 rcu_read_lock();
4881 regdom = rcu_dereference(cfg80211_regdomain);
4882
4883 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4884 (regdom->dfs_region &&
4885 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4886 goto nla_put_failure_rcu;
4887
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004888 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4889 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004890 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004891
Johannes Berg458f4f92012-12-06 15:47:38 +01004892 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004893 struct nlattr *nl_reg_rule;
4894 const struct ieee80211_reg_rule *reg_rule;
4895 const struct ieee80211_freq_range *freq_range;
4896 const struct ieee80211_power_rule *power_rule;
4897
Johannes Berg458f4f92012-12-06 15:47:38 +01004898 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004899 freq_range = &reg_rule->freq_range;
4900 power_rule = &reg_rule->power_rule;
4901
4902 nl_reg_rule = nla_nest_start(msg, i);
4903 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004904 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004905
David S. Miller9360ffd2012-03-29 04:41:26 -04004906 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4907 reg_rule->flags) ||
4908 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4909 freq_range->start_freq_khz) ||
4910 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4911 freq_range->end_freq_khz) ||
4912 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4913 freq_range->max_bandwidth_khz) ||
4914 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4915 power_rule->max_antenna_gain) ||
4916 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4917 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004918 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004919
4920 nla_nest_end(msg, nl_reg_rule);
4921 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004922 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004923
4924 nla_nest_end(msg, nl_reg_rules);
4925
4926 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004927 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004928
Johannes Berg458f4f92012-12-06 15:47:38 +01004929nla_put_failure_rcu:
4930 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004931nla_put_failure:
4932 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004933put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004934 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004935 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004936}
4937
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004938static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4939{
4940 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4941 struct nlattr *nl_reg_rule;
4942 char *alpha2 = NULL;
4943 int rem_reg_rules = 0, r = 0;
4944 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004945 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004946 struct ieee80211_regdomain *rd = NULL;
4947
4948 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4949 return -EINVAL;
4950
4951 if (!info->attrs[NL80211_ATTR_REG_RULES])
4952 return -EINVAL;
4953
4954 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4955
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004956 if (info->attrs[NL80211_ATTR_DFS_REGION])
4957 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
4958
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004960 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004961 num_rules++;
4962 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04004963 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004964 }
4965
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004966 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01004967 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004968
4969 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01004970 if (!rd)
4971 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972
4973 rd->n_reg_rules = num_rules;
4974 rd->alpha2[0] = alpha2[0];
4975 rd->alpha2[1] = alpha2[1];
4976
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004977 /*
4978 * Disable DFS master mode if the DFS region was
4979 * not supported or known on this kernel.
4980 */
4981 if (reg_supported_dfs_region(dfs_region))
4982 rd->dfs_region = dfs_region;
4983
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004984 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01004985 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004986 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01004987 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
4988 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004989 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
4990 if (r)
4991 goto bad_reg;
4992
4993 rule_idx++;
4994
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004995 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
4996 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004997 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04004998 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004999 }
5000
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005001 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005002 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005003 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005004
Johannes Bergd2372b32008-10-24 20:32:20 +02005005 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005006 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005007 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005008}
5009
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005010static int validate_scan_freqs(struct nlattr *freqs)
5011{
5012 struct nlattr *attr1, *attr2;
5013 int n_channels = 0, tmp1, tmp2;
5014
5015 nla_for_each_nested(attr1, freqs, tmp1) {
5016 n_channels++;
5017 /*
5018 * Some hardware has a limited channel list for
5019 * scanning, and it is pretty much nonsensical
5020 * to scan for a channel twice, so disallow that
5021 * and don't require drivers to check that the
5022 * channel list they get isn't longer than what
5023 * they can scan, as long as they can scan all
5024 * the channels they registered at once.
5025 */
5026 nla_for_each_nested(attr2, freqs, tmp2)
5027 if (attr1 != attr2 &&
5028 nla_get_u32(attr1) == nla_get_u32(attr2))
5029 return 0;
5030 }
5031
5032 return n_channels;
5033}
5034
Johannes Berg2a519312009-02-10 21:25:55 +01005035static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5036{
Johannes Berg4c476992010-10-04 21:36:35 +02005037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005038 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005039 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005040 struct nlattr *attr;
5041 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005042 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005043 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005044
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005045 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5046 return -EINVAL;
5047
Johannes Berg79c97e92009-07-07 03:56:12 +02005048 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005049
Johannes Berg4c476992010-10-04 21:36:35 +02005050 if (!rdev->ops->scan)
5051 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005052
Johannes Bergf9f47522013-03-19 15:04:07 +01005053 if (rdev->scan_req) {
5054 err = -EBUSY;
5055 goto unlock;
5056 }
Johannes Berg2a519312009-02-10 21:25:55 +01005057
5058 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005059 n_channels = validate_scan_freqs(
5060 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005061 if (!n_channels) {
5062 err = -EINVAL;
5063 goto unlock;
5064 }
Johannes Berg2a519312009-02-10 21:25:55 +01005065 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005066 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005067 n_channels = 0;
5068
Johannes Berg2a519312009-02-10 21:25:55 +01005069 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5070 if (wiphy->bands[band])
5071 n_channels += wiphy->bands[band]->n_channels;
5072 }
5073
5074 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5075 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5076 n_ssids++;
5077
Johannes Bergf9f47522013-03-19 15:04:07 +01005078 if (n_ssids > wiphy->max_scan_ssids) {
5079 err = -EINVAL;
5080 goto unlock;
5081 }
Johannes Berg2a519312009-02-10 21:25:55 +01005082
Jouni Malinen70692ad2009-02-16 19:39:13 +02005083 if (info->attrs[NL80211_ATTR_IE])
5084 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5085 else
5086 ie_len = 0;
5087
Johannes Bergf9f47522013-03-19 15:04:07 +01005088 if (ie_len > wiphy->max_scan_ie_len) {
5089 err = -EINVAL;
5090 goto unlock;
5091 }
Johannes Berg18a83652009-03-31 12:12:05 +02005092
Johannes Berg2a519312009-02-10 21:25:55 +01005093 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005094 + sizeof(*request->ssids) * n_ssids
5095 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005096 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005097 if (!request) {
5098 err = -ENOMEM;
5099 goto unlock;
5100 }
Johannes Berg2a519312009-02-10 21:25:55 +01005101
Johannes Berg2a519312009-02-10 21:25:55 +01005102 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005103 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005104 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005105 if (ie_len) {
5106 if (request->ssids)
5107 request->ie = (void *)(request->ssids + n_ssids);
5108 else
5109 request->ie = (void *)(request->channels + n_channels);
5110 }
Johannes Berg2a519312009-02-10 21:25:55 +01005111
Johannes Berg584991d2009-11-02 13:32:03 +01005112 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005113 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5114 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005115 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005116 struct ieee80211_channel *chan;
5117
5118 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5119
5120 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005121 err = -EINVAL;
5122 goto out_free;
5123 }
Johannes Berg584991d2009-11-02 13:32:03 +01005124
5125 /* ignore disabled channels */
5126 if (chan->flags & IEEE80211_CHAN_DISABLED)
5127 continue;
5128
5129 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005130 i++;
5131 }
5132 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005133 enum ieee80211_band band;
5134
Johannes Berg2a519312009-02-10 21:25:55 +01005135 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005136 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5137 int j;
5138 if (!wiphy->bands[band])
5139 continue;
5140 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005141 struct ieee80211_channel *chan;
5142
5143 chan = &wiphy->bands[band]->channels[j];
5144
5145 if (chan->flags & IEEE80211_CHAN_DISABLED)
5146 continue;
5147
5148 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005149 i++;
5150 }
5151 }
5152 }
5153
Johannes Berg584991d2009-11-02 13:32:03 +01005154 if (!i) {
5155 err = -EINVAL;
5156 goto out_free;
5157 }
5158
5159 request->n_channels = i;
5160
Johannes Berg2a519312009-02-10 21:25:55 +01005161 i = 0;
5162 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5163 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005164 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005165 err = -EINVAL;
5166 goto out_free;
5167 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005168 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005169 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005170 i++;
5171 }
5172 }
5173
Jouni Malinen70692ad2009-02-16 19:39:13 +02005174 if (info->attrs[NL80211_ATTR_IE]) {
5175 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005176 memcpy((void *)request->ie,
5177 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005178 request->ie_len);
5179 }
5180
Johannes Berg34850ab2011-07-18 18:08:35 +02005181 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005182 if (wiphy->bands[i])
5183 request->rates[i] =
5184 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005185
5186 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5187 nla_for_each_nested(attr,
5188 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5189 tmp) {
5190 enum ieee80211_band band = nla_type(attr);
5191
Dan Carpenter84404622011-07-29 11:52:18 +03005192 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005193 err = -EINVAL;
5194 goto out_free;
5195 }
5196 err = ieee80211_get_ratemask(wiphy->bands[band],
5197 nla_data(attr),
5198 nla_len(attr),
5199 &request->rates[band]);
5200 if (err)
5201 goto out_free;
5202 }
5203 }
5204
Sam Leffler46856bb2012-10-11 21:03:32 -07005205 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005206 request->flags = nla_get_u32(
5207 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005208 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5209 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5210 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5211 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005212 err = -EOPNOTSUPP;
5213 goto out_free;
5214 }
5215 }
Sam Lefflered4737712012-10-11 21:03:31 -07005216
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305217 request->no_cck =
5218 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5219
Johannes Bergfd014282012-06-18 19:17:03 +02005220 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005221 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005222 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005223
Johannes Berg79c97e92009-07-07 03:56:12 +02005224 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005225 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005226
Johannes Berg463d0182009-07-14 00:33:35 +02005227 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005228 nl80211_send_scan_start(rdev, wdev);
5229 if (wdev->netdev)
5230 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005231 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005232 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005233 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005234 kfree(request);
5235 }
Johannes Berg3b858752009-03-12 09:55:09 +01005236
Johannes Bergf9f47522013-03-19 15:04:07 +01005237 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005238 return err;
5239}
5240
Luciano Coelho807f8a82011-05-11 17:09:35 +03005241static int nl80211_start_sched_scan(struct sk_buff *skb,
5242 struct genl_info *info)
5243{
5244 struct cfg80211_sched_scan_request *request;
5245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5246 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005247 struct nlattr *attr;
5248 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005249 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005250 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005251 enum ieee80211_band band;
5252 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005253 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005254
5255 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5256 !rdev->ops->sched_scan_start)
5257 return -EOPNOTSUPP;
5258
5259 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5260 return -EINVAL;
5261
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005262 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5263 return -EINVAL;
5264
5265 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5266 if (interval == 0)
5267 return -EINVAL;
5268
Luciano Coelho807f8a82011-05-11 17:09:35 +03005269 wiphy = &rdev->wiphy;
5270
5271 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5272 n_channels = validate_scan_freqs(
5273 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5274 if (!n_channels)
5275 return -EINVAL;
5276 } else {
5277 n_channels = 0;
5278
5279 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5280 if (wiphy->bands[band])
5281 n_channels += wiphy->bands[band]->n_channels;
5282 }
5283
5284 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5285 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5286 tmp)
5287 n_ssids++;
5288
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005289 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005290 return -EINVAL;
5291
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005292 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5293 nla_for_each_nested(attr,
5294 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5295 tmp)
5296 n_match_sets++;
5297
5298 if (n_match_sets > wiphy->max_match_sets)
5299 return -EINVAL;
5300
Luciano Coelho807f8a82011-05-11 17:09:35 +03005301 if (info->attrs[NL80211_ATTR_IE])
5302 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5303 else
5304 ie_len = 0;
5305
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005306 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005307 return -EINVAL;
5308
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005309 if (rdev->sched_scan_req) {
5310 err = -EINPROGRESS;
5311 goto out;
5312 }
5313
Luciano Coelho807f8a82011-05-11 17:09:35 +03005314 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005315 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005316 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005317 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005318 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005319 if (!request) {
5320 err = -ENOMEM;
5321 goto out;
5322 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005323
5324 if (n_ssids)
5325 request->ssids = (void *)&request->channels[n_channels];
5326 request->n_ssids = n_ssids;
5327 if (ie_len) {
5328 if (request->ssids)
5329 request->ie = (void *)(request->ssids + n_ssids);
5330 else
5331 request->ie = (void *)(request->channels + n_channels);
5332 }
5333
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005334 if (n_match_sets) {
5335 if (request->ie)
5336 request->match_sets = (void *)(request->ie + ie_len);
5337 else if (request->ssids)
5338 request->match_sets =
5339 (void *)(request->ssids + n_ssids);
5340 else
5341 request->match_sets =
5342 (void *)(request->channels + n_channels);
5343 }
5344 request->n_match_sets = n_match_sets;
5345
Luciano Coelho807f8a82011-05-11 17:09:35 +03005346 i = 0;
5347 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5348 /* user specified, bail out if channel not found */
5349 nla_for_each_nested(attr,
5350 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5351 tmp) {
5352 struct ieee80211_channel *chan;
5353
5354 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5355
5356 if (!chan) {
5357 err = -EINVAL;
5358 goto out_free;
5359 }
5360
5361 /* ignore disabled channels */
5362 if (chan->flags & IEEE80211_CHAN_DISABLED)
5363 continue;
5364
5365 request->channels[i] = chan;
5366 i++;
5367 }
5368 } else {
5369 /* all channels */
5370 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5371 int j;
5372 if (!wiphy->bands[band])
5373 continue;
5374 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5375 struct ieee80211_channel *chan;
5376
5377 chan = &wiphy->bands[band]->channels[j];
5378
5379 if (chan->flags & IEEE80211_CHAN_DISABLED)
5380 continue;
5381
5382 request->channels[i] = chan;
5383 i++;
5384 }
5385 }
5386 }
5387
5388 if (!i) {
5389 err = -EINVAL;
5390 goto out_free;
5391 }
5392
5393 request->n_channels = i;
5394
5395 i = 0;
5396 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5397 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5398 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005399 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005400 err = -EINVAL;
5401 goto out_free;
5402 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005403 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005404 memcpy(request->ssids[i].ssid, nla_data(attr),
5405 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005406 i++;
5407 }
5408 }
5409
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005410 i = 0;
5411 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5412 nla_for_each_nested(attr,
5413 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5414 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005415 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005416
5417 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5418 nla_data(attr), nla_len(attr),
5419 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005420 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005421 if (ssid) {
5422 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5423 err = -EINVAL;
5424 goto out_free;
5425 }
5426 memcpy(request->match_sets[i].ssid.ssid,
5427 nla_data(ssid), nla_len(ssid));
5428 request->match_sets[i].ssid.ssid_len =
5429 nla_len(ssid);
5430 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005431 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5432 if (rssi)
5433 request->rssi_thold = nla_get_u32(rssi);
5434 else
5435 request->rssi_thold =
5436 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005437 i++;
5438 }
5439 }
5440
Luciano Coelho807f8a82011-05-11 17:09:35 +03005441 if (info->attrs[NL80211_ATTR_IE]) {
5442 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5443 memcpy((void *)request->ie,
5444 nla_data(info->attrs[NL80211_ATTR_IE]),
5445 request->ie_len);
5446 }
5447
Sam Leffler46856bb2012-10-11 21:03:32 -07005448 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005449 request->flags = nla_get_u32(
5450 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005451 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5452 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5453 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5454 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005455 err = -EOPNOTSUPP;
5456 goto out_free;
5457 }
5458 }
Sam Lefflered4737712012-10-11 21:03:31 -07005459
Luciano Coelho807f8a82011-05-11 17:09:35 +03005460 request->dev = dev;
5461 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005462 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005463 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005464
Hila Gonene35e4d22012-06-27 17:19:42 +03005465 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005466 if (!err) {
5467 rdev->sched_scan_req = request;
5468 nl80211_send_sched_scan(rdev, dev,
5469 NL80211_CMD_START_SCHED_SCAN);
5470 goto out;
5471 }
5472
5473out_free:
5474 kfree(request);
5475out:
5476 return err;
5477}
5478
5479static int nl80211_stop_sched_scan(struct sk_buff *skb,
5480 struct genl_info *info)
5481{
5482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5483
5484 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5485 !rdev->ops->sched_scan_stop)
5486 return -EOPNOTSUPP;
5487
Johannes Berg5fe231e2013-05-08 21:45:15 +02005488 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005489}
5490
Simon Wunderlich04f39042013-02-08 18:16:19 +01005491static int nl80211_start_radar_detection(struct sk_buff *skb,
5492 struct genl_info *info)
5493{
5494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5495 struct net_device *dev = info->user_ptr[1];
5496 struct wireless_dev *wdev = dev->ieee80211_ptr;
5497 struct cfg80211_chan_def chandef;
5498 int err;
5499
5500 err = nl80211_parse_chandef(rdev, info, &chandef);
5501 if (err)
5502 return err;
5503
5504 if (wdev->cac_started)
5505 return -EBUSY;
5506
5507 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5508 if (err < 0)
5509 return err;
5510
5511 if (err == 0)
5512 return -EINVAL;
5513
5514 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5515 return -EINVAL;
5516
5517 if (!rdev->ops->start_radar_detection)
5518 return -EOPNOTSUPP;
5519
Simon Wunderlich04f39042013-02-08 18:16:19 +01005520 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5521 chandef.chan, CHAN_MODE_SHARED,
5522 BIT(chandef.width));
5523 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005524 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005525
5526 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5527 if (!err) {
5528 wdev->channel = chandef.chan;
5529 wdev->cac_started = true;
5530 wdev->cac_start_time = jiffies;
5531 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005532 return err;
5533}
5534
Johannes Berg9720bb32011-06-21 09:45:33 +02005535static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5536 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005537 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005538 struct wireless_dev *wdev,
5539 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005540{
Johannes Berg48ab9052009-07-10 18:42:31 +02005541 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005542 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005543 void *hdr;
5544 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005545 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005546
5547 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005548
Eric W. Biederman15e47302012-09-07 20:12:54 +00005549 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005550 NL80211_CMD_NEW_SCAN_RESULTS);
5551 if (!hdr)
5552 return -1;
5553
Johannes Berg9720bb32011-06-21 09:45:33 +02005554 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5555
Johannes Berg97990a02013-04-19 01:02:55 +02005556 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5557 goto nla_put_failure;
5558 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005559 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5560 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005561 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5562 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005563
5564 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5565 if (!bss)
5566 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005567 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005568 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005569 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005570
5571 rcu_read_lock();
5572 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005573 if (ies) {
5574 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5575 goto fail_unlock_rcu;
5576 tsf = true;
5577 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5578 ies->len, ies->data))
5579 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005580 }
5581 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005582 if (ies) {
5583 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5584 goto fail_unlock_rcu;
5585 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5586 ies->len, ies->data))
5587 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005588 }
5589 rcu_read_unlock();
5590
David S. Miller9360ffd2012-03-29 04:41:26 -04005591 if (res->beacon_interval &&
5592 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5593 goto nla_put_failure;
5594 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5595 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5596 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5597 jiffies_to_msecs(jiffies - intbss->ts)))
5598 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005599
Johannes Berg77965c92009-02-18 18:45:06 +01005600 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005601 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005602 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5603 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005604 break;
5605 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005606 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5607 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005608 break;
5609 default:
5610 break;
5611 }
5612
Johannes Berg48ab9052009-07-10 18:42:31 +02005613 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005614 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005615 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005616 if (intbss == wdev->current_bss &&
5617 nla_put_u32(msg, NL80211_BSS_STATUS,
5618 NL80211_BSS_STATUS_ASSOCIATED))
5619 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005620 break;
5621 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005622 if (intbss == wdev->current_bss &&
5623 nla_put_u32(msg, NL80211_BSS_STATUS,
5624 NL80211_BSS_STATUS_IBSS_JOINED))
5625 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005626 break;
5627 default:
5628 break;
5629 }
5630
Johannes Berg2a519312009-02-10 21:25:55 +01005631 nla_nest_end(msg, bss);
5632
5633 return genlmsg_end(msg, hdr);
5634
Johannes Berg8cef2c92013-02-05 16:54:31 +01005635 fail_unlock_rcu:
5636 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005637 nla_put_failure:
5638 genlmsg_cancel(msg, hdr);
5639 return -EMSGSIZE;
5640}
5641
Johannes Berg97990a02013-04-19 01:02:55 +02005642static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005643{
Johannes Berg48ab9052009-07-10 18:42:31 +02005644 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005645 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005646 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005647 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005648 int err;
5649
Johannes Berg97990a02013-04-19 01:02:55 +02005650 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005651 if (err)
5652 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005653
Johannes Berg48ab9052009-07-10 18:42:31 +02005654 wdev_lock(wdev);
5655 spin_lock_bh(&rdev->bss_lock);
5656 cfg80211_bss_expire(rdev);
5657
Johannes Berg9720bb32011-06-21 09:45:33 +02005658 cb->seq = rdev->bss_generation;
5659
Johannes Berg48ab9052009-07-10 18:42:31 +02005660 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005661 if (++idx <= start)
5662 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005663 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005664 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005665 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005666 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005667 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005668 }
5669 }
5670
Johannes Berg48ab9052009-07-10 18:42:31 +02005671 spin_unlock_bh(&rdev->bss_lock);
5672 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005673
Johannes Berg97990a02013-04-19 01:02:55 +02005674 cb->args[2] = idx;
5675 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005676
Johannes Berg67748892010-10-04 21:14:06 +02005677 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005678}
5679
Eric W. Biederman15e47302012-09-07 20:12:54 +00005680static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005681 int flags, struct net_device *dev,
5682 struct survey_info *survey)
5683{
5684 void *hdr;
5685 struct nlattr *infoattr;
5686
Eric W. Biederman15e47302012-09-07 20:12:54 +00005687 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005688 NL80211_CMD_NEW_SURVEY_RESULTS);
5689 if (!hdr)
5690 return -ENOMEM;
5691
David S. Miller9360ffd2012-03-29 04:41:26 -04005692 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5693 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005694
5695 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5696 if (!infoattr)
5697 goto nla_put_failure;
5698
David S. Miller9360ffd2012-03-29 04:41:26 -04005699 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5700 survey->channel->center_freq))
5701 goto nla_put_failure;
5702
5703 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5704 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5705 goto nla_put_failure;
5706 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5707 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5708 goto nla_put_failure;
5709 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5710 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5711 survey->channel_time))
5712 goto nla_put_failure;
5713 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5714 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5715 survey->channel_time_busy))
5716 goto nla_put_failure;
5717 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5718 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5719 survey->channel_time_ext_busy))
5720 goto nla_put_failure;
5721 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5722 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5723 survey->channel_time_rx))
5724 goto nla_put_failure;
5725 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5726 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5727 survey->channel_time_tx))
5728 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005729
5730 nla_nest_end(msg, infoattr);
5731
5732 return genlmsg_end(msg, hdr);
5733
5734 nla_put_failure:
5735 genlmsg_cancel(msg, hdr);
5736 return -EMSGSIZE;
5737}
5738
5739static int nl80211_dump_survey(struct sk_buff *skb,
5740 struct netlink_callback *cb)
5741{
5742 struct survey_info survey;
5743 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005744 struct wireless_dev *wdev;
5745 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005746 int res;
5747
Johannes Berg97990a02013-04-19 01:02:55 +02005748 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005749 if (res)
5750 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005751
Johannes Berg97990a02013-04-19 01:02:55 +02005752 if (!wdev->netdev) {
5753 res = -EINVAL;
5754 goto out_err;
5755 }
5756
Holger Schurig61fa7132009-11-11 12:25:40 +01005757 if (!dev->ops->dump_survey) {
5758 res = -EOPNOTSUPP;
5759 goto out_err;
5760 }
5761
5762 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005763 struct ieee80211_channel *chan;
5764
Johannes Berg97990a02013-04-19 01:02:55 +02005765 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005766 if (res == -ENOENT)
5767 break;
5768 if (res)
5769 goto out_err;
5770
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005771 /* Survey without a channel doesn't make sense */
5772 if (!survey.channel) {
5773 res = -EINVAL;
5774 goto out;
5775 }
5776
5777 chan = ieee80211_get_channel(&dev->wiphy,
5778 survey.channel->center_freq);
5779 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5780 survey_idx++;
5781 continue;
5782 }
5783
Holger Schurig61fa7132009-11-11 12:25:40 +01005784 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005785 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005786 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005787 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005788 goto out;
5789 survey_idx++;
5790 }
5791
5792 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005793 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005794 res = skb->len;
5795 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005796 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005797 return res;
5798}
5799
Samuel Ortizb23aa672009-07-01 21:26:54 +02005800static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5801{
5802 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5803 NL80211_WPA_VERSION_2));
5804}
5805
Jouni Malinen636a5d32009-03-19 13:39:22 +02005806static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5807{
Johannes Berg4c476992010-10-04 21:36:35 +02005808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5809 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005810 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005811 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5812 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005813 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005814 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005815 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005816
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005817 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5818 return -EINVAL;
5819
5820 if (!info->attrs[NL80211_ATTR_MAC])
5821 return -EINVAL;
5822
Jouni Malinen17780922009-03-27 20:52:47 +02005823 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5824 return -EINVAL;
5825
Johannes Berg19957bb2009-07-02 17:20:43 +02005826 if (!info->attrs[NL80211_ATTR_SSID])
5827 return -EINVAL;
5828
5829 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5830 return -EINVAL;
5831
Johannes Bergfffd0932009-07-08 14:22:54 +02005832 err = nl80211_parse_key(info, &key);
5833 if (err)
5834 return err;
5835
5836 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005837 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5838 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005839 if (!key.p.key || !key.p.key_len)
5840 return -EINVAL;
5841 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5842 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5843 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5844 key.p.key_len != WLAN_KEY_LEN_WEP104))
5845 return -EINVAL;
5846 if (key.idx > 4)
5847 return -EINVAL;
5848 } else {
5849 key.p.key_len = 0;
5850 key.p.key = NULL;
5851 }
5852
Johannes Bergafea0b72010-08-10 09:46:42 +02005853 if (key.idx >= 0) {
5854 int i;
5855 bool ok = false;
5856 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5857 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5858 ok = true;
5859 break;
5860 }
5861 }
Johannes Berg4c476992010-10-04 21:36:35 +02005862 if (!ok)
5863 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005864 }
5865
Johannes Berg4c476992010-10-04 21:36:35 +02005866 if (!rdev->ops->auth)
5867 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005868
Johannes Berg074ac8d2010-09-16 14:58:22 +02005869 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005870 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5871 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005872
Johannes Berg19957bb2009-07-02 17:20:43 +02005873 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005874 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005875 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005876 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5877 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005878
Johannes Berg19957bb2009-07-02 17:20:43 +02005879 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5880 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5881
5882 if (info->attrs[NL80211_ATTR_IE]) {
5883 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5884 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5885 }
5886
5887 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005888 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005889 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005890
Jouni Malinene39e5b52012-09-30 19:29:39 +03005891 if (auth_type == NL80211_AUTHTYPE_SAE &&
5892 !info->attrs[NL80211_ATTR_SAE_DATA])
5893 return -EINVAL;
5894
5895 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5896 if (auth_type != NL80211_AUTHTYPE_SAE)
5897 return -EINVAL;
5898 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5899 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5900 /* need to include at least Auth Transaction and Status Code */
5901 if (sae_data_len < 4)
5902 return -EINVAL;
5903 }
5904
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005905 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5906
Johannes Berg95de8172012-01-20 13:55:25 +01005907 /*
5908 * Since we no longer track auth state, ignore
5909 * requests to only change local state.
5910 */
5911 if (local_state_change)
5912 return 0;
5913
Johannes Berg91bf9b22013-05-15 17:44:01 +02005914 wdev_lock(dev->ieee80211_ptr);
5915 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5916 ssid, ssid_len, ie, ie_len,
5917 key.p.key, key.p.key_len, key.idx,
5918 sae_data, sae_data_len);
5919 wdev_unlock(dev->ieee80211_ptr);
5920 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005921}
5922
Johannes Bergc0692b82010-08-27 14:26:53 +03005923static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5924 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005925 struct cfg80211_crypto_settings *settings,
5926 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005927{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005928 memset(settings, 0, sizeof(*settings));
5929
Samuel Ortizb23aa672009-07-01 21:26:54 +02005930 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5931
Johannes Bergc0692b82010-08-27 14:26:53 +03005932 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5933 u16 proto;
5934 proto = nla_get_u16(
5935 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5936 settings->control_port_ethertype = cpu_to_be16(proto);
5937 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5938 proto != ETH_P_PAE)
5939 return -EINVAL;
5940 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5941 settings->control_port_no_encrypt = true;
5942 } else
5943 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5944
Samuel Ortizb23aa672009-07-01 21:26:54 +02005945 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5946 void *data;
5947 int len, i;
5948
5949 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5950 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5951 settings->n_ciphers_pairwise = len / sizeof(u32);
5952
5953 if (len % sizeof(u32))
5954 return -EINVAL;
5955
Johannes Berg3dc27d22009-07-02 21:36:37 +02005956 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005957 return -EINVAL;
5958
5959 memcpy(settings->ciphers_pairwise, data, len);
5960
5961 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005962 if (!cfg80211_supported_cipher_suite(
5963 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02005964 settings->ciphers_pairwise[i]))
5965 return -EINVAL;
5966 }
5967
5968 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
5969 settings->cipher_group =
5970 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03005971 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
5972 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02005973 return -EINVAL;
5974 }
5975
5976 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
5977 settings->wpa_versions =
5978 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
5979 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
5980 return -EINVAL;
5981 }
5982
5983 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
5984 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03005985 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02005986
5987 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
5988 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
5989 settings->n_akm_suites = len / sizeof(u32);
5990
5991 if (len % sizeof(u32))
5992 return -EINVAL;
5993
Jouni Malinen1b9ca022011-09-21 16:13:07 +03005994 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
5995 return -EINVAL;
5996
Samuel Ortizb23aa672009-07-01 21:26:54 +02005997 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02005998 }
5999
6000 return 0;
6001}
6002
Jouni Malinen636a5d32009-03-19 13:39:22 +02006003static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6004{
Johannes Berg4c476992010-10-04 21:36:35 +02006005 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6006 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006007 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006008 struct cfg80211_assoc_request req = {};
6009 const u8 *bssid, *ssid;
6010 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006011
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006012 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6013 return -EINVAL;
6014
6015 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006016 !info->attrs[NL80211_ATTR_SSID] ||
6017 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006018 return -EINVAL;
6019
Johannes Berg4c476992010-10-04 21:36:35 +02006020 if (!rdev->ops->assoc)
6021 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006022
Johannes Berg074ac8d2010-09-16 14:58:22 +02006023 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006024 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6025 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006026
Johannes Berg19957bb2009-07-02 17:20:43 +02006027 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006028
Johannes Berg19957bb2009-07-02 17:20:43 +02006029 chan = ieee80211_get_channel(&rdev->wiphy,
6030 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006031 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6032 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006033
Johannes Berg19957bb2009-07-02 17:20:43 +02006034 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6035 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006036
6037 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006038 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6039 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006040 }
6041
Jouni Malinendc6382c2009-05-06 22:09:37 +03006042 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006043 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006044 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006045 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006046 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006047 else if (mfp != NL80211_MFP_NO)
6048 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006049 }
6050
Johannes Berg3e5d7642009-07-07 14:37:26 +02006051 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006052 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006053
Ben Greear7e7c8922011-11-18 11:31:59 -08006054 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006055 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006056
6057 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006058 memcpy(&req.ht_capa_mask,
6059 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6060 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006061
6062 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006063 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006064 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006065 memcpy(&req.ht_capa,
6066 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6067 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006068 }
6069
Johannes Bergee2aca32013-02-21 17:36:01 +01006070 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006071 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006072
6073 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006074 memcpy(&req.vht_capa_mask,
6075 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6076 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006077
6078 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006079 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006080 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006081 memcpy(&req.vht_capa,
6082 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6083 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006084 }
6085
Johannes Bergf62fab72013-02-21 20:09:09 +01006086 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006087 if (!err) {
6088 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006089 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6090 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006091 wdev_unlock(dev->ieee80211_ptr);
6092 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006093
Jouni Malinen636a5d32009-03-19 13:39:22 +02006094 return err;
6095}
6096
6097static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6098{
Johannes Berg4c476992010-10-04 21:36:35 +02006099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6100 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006101 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006102 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006103 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006104 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006105
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006106 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6107 return -EINVAL;
6108
6109 if (!info->attrs[NL80211_ATTR_MAC])
6110 return -EINVAL;
6111
6112 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6113 return -EINVAL;
6114
Johannes Berg4c476992010-10-04 21:36:35 +02006115 if (!rdev->ops->deauth)
6116 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006117
Johannes Berg074ac8d2010-09-16 14:58:22 +02006118 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006119 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6120 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006121
Johannes Berg19957bb2009-07-02 17:20:43 +02006122 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006123
Johannes Berg19957bb2009-07-02 17:20:43 +02006124 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6125 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006126 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006127 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006128 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006129
6130 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006131 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6132 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006133 }
6134
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006135 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6136
Johannes Berg91bf9b22013-05-15 17:44:01 +02006137 wdev_lock(dev->ieee80211_ptr);
6138 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6139 local_state_change);
6140 wdev_unlock(dev->ieee80211_ptr);
6141 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006142}
6143
6144static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6145{
Johannes Berg4c476992010-10-04 21:36:35 +02006146 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6147 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006148 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006149 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006150 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006151 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006152
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006153 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6154 return -EINVAL;
6155
6156 if (!info->attrs[NL80211_ATTR_MAC])
6157 return -EINVAL;
6158
6159 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6160 return -EINVAL;
6161
Johannes Berg4c476992010-10-04 21:36:35 +02006162 if (!rdev->ops->disassoc)
6163 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006164
Johannes Berg074ac8d2010-09-16 14:58:22 +02006165 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006166 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6167 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006168
Johannes Berg19957bb2009-07-02 17:20:43 +02006169 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006170
Johannes Berg19957bb2009-07-02 17:20:43 +02006171 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6172 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006173 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006174 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006175 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006176
6177 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006178 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6179 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006180 }
6181
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006182 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6183
Johannes Berg91bf9b22013-05-15 17:44:01 +02006184 wdev_lock(dev->ieee80211_ptr);
6185 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6186 local_state_change);
6187 wdev_unlock(dev->ieee80211_ptr);
6188 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006189}
6190
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006191static bool
6192nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6193 int mcast_rate[IEEE80211_NUM_BANDS],
6194 int rateval)
6195{
6196 struct wiphy *wiphy = &rdev->wiphy;
6197 bool found = false;
6198 int band, i;
6199
6200 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6201 struct ieee80211_supported_band *sband;
6202
6203 sband = wiphy->bands[band];
6204 if (!sband)
6205 continue;
6206
6207 for (i = 0; i < sband->n_bitrates; i++) {
6208 if (sband->bitrates[i].bitrate == rateval) {
6209 mcast_rate[band] = i + 1;
6210 found = true;
6211 break;
6212 }
6213 }
6214 }
6215
6216 return found;
6217}
6218
Johannes Berg04a773a2009-04-19 21:24:32 +02006219static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6220{
Johannes Berg4c476992010-10-04 21:36:35 +02006221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6222 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006223 struct cfg80211_ibss_params ibss;
6224 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006225 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006226 int err;
6227
Johannes Berg8e30bc52009-04-22 17:45:38 +02006228 memset(&ibss, 0, sizeof(ibss));
6229
Johannes Berg04a773a2009-04-19 21:24:32 +02006230 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6231 return -EINVAL;
6232
Johannes Berg683b6d32012-11-08 21:25:48 +01006233 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006234 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6235 return -EINVAL;
6236
Johannes Berg8e30bc52009-04-22 17:45:38 +02006237 ibss.beacon_interval = 100;
6238
6239 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6240 ibss.beacon_interval =
6241 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6242 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6243 return -EINVAL;
6244 }
6245
Johannes Berg4c476992010-10-04 21:36:35 +02006246 if (!rdev->ops->join_ibss)
6247 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006248
Johannes Berg4c476992010-10-04 21:36:35 +02006249 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6250 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006251
Johannes Berg79c97e92009-07-07 03:56:12 +02006252 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006253
Johannes Berg39193492011-09-16 13:45:25 +02006254 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006255 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006256
6257 if (!is_valid_ether_addr(ibss.bssid))
6258 return -EINVAL;
6259 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006260 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6261 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6262
6263 if (info->attrs[NL80211_ATTR_IE]) {
6264 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6265 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6266 }
6267
Johannes Berg683b6d32012-11-08 21:25:48 +01006268 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6269 if (err)
6270 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006271
Johannes Berg683b6d32012-11-08 21:25:48 +01006272 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006273 return -EINVAL;
6274
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006275 if (ibss.chandef.width > NL80211_CHAN_WIDTH_40)
6276 return -EINVAL;
6277 if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
6278 !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
Simon Wunderlichc04d6152012-11-29 18:37:22 +01006279 return -EINVAL;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006280
Johannes Berg04a773a2009-04-19 21:24:32 +02006281 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006282 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006283
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006284 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6285 u8 *rates =
6286 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6287 int n_rates =
6288 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6289 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006290 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006291
Johannes Berg34850ab2011-07-18 18:08:35 +02006292 err = ieee80211_get_ratemask(sband, rates, n_rates,
6293 &ibss.basic_rates);
6294 if (err)
6295 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006296 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006297
6298 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6299 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6300 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6301 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006302
Johannes Berg4c476992010-10-04 21:36:35 +02006303 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306304 bool no_ht = false;
6305
Johannes Berg4c476992010-10-04 21:36:35 +02006306 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306307 info->attrs[NL80211_ATTR_KEYS],
6308 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006309 if (IS_ERR(connkeys))
6310 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306311
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006312 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6313 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306314 kfree(connkeys);
6315 return -EINVAL;
6316 }
Johannes Berg4c476992010-10-04 21:36:35 +02006317 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006318
Antonio Quartulli267335d2012-01-31 20:25:47 +01006319 ibss.control_port =
6320 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6321
Johannes Berg4c476992010-10-04 21:36:35 +02006322 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006323 if (err)
6324 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006325 return err;
6326}
6327
6328static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6329{
Johannes Berg4c476992010-10-04 21:36:35 +02006330 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6331 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006332
Johannes Berg4c476992010-10-04 21:36:35 +02006333 if (!rdev->ops->leave_ibss)
6334 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006335
Johannes Berg4c476992010-10-04 21:36:35 +02006336 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6337 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006338
Johannes Berg4c476992010-10-04 21:36:35 +02006339 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006340}
6341
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006342static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6343{
6344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6345 struct net_device *dev = info->user_ptr[1];
6346 int mcast_rate[IEEE80211_NUM_BANDS];
6347 u32 nla_rate;
6348 int err;
6349
6350 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6351 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6352 return -EOPNOTSUPP;
6353
6354 if (!rdev->ops->set_mcast_rate)
6355 return -EOPNOTSUPP;
6356
6357 memset(mcast_rate, 0, sizeof(mcast_rate));
6358
6359 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6360 return -EINVAL;
6361
6362 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6363 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6364 return -EINVAL;
6365
6366 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6367
6368 return err;
6369}
6370
6371
Johannes Bergaff89a92009-07-01 21:26:51 +02006372#ifdef CONFIG_NL80211_TESTMODE
6373static struct genl_multicast_group nl80211_testmode_mcgrp = {
6374 .name = "testmode",
6375};
6376
6377static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6378{
Johannes Berg4c476992010-10-04 21:36:35 +02006379 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006380 int err;
6381
6382 if (!info->attrs[NL80211_ATTR_TESTDATA])
6383 return -EINVAL;
6384
Johannes Bergaff89a92009-07-01 21:26:51 +02006385 err = -EOPNOTSUPP;
6386 if (rdev->ops->testmode_cmd) {
6387 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006388 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006389 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6390 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6391 rdev->testmode_info = NULL;
6392 }
6393
Johannes Bergaff89a92009-07-01 21:26:51 +02006394 return err;
6395}
6396
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006397static int nl80211_testmode_dump(struct sk_buff *skb,
6398 struct netlink_callback *cb)
6399{
Johannes Berg00918d32011-12-13 17:22:05 +01006400 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006401 int err;
6402 long phy_idx;
6403 void *data = NULL;
6404 int data_len = 0;
6405
Johannes Berg5fe231e2013-05-08 21:45:15 +02006406 rtnl_lock();
6407
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006408 if (cb->args[0]) {
6409 /*
6410 * 0 is a valid index, but not valid for args[0],
6411 * so we need to offset by 1.
6412 */
6413 phy_idx = cb->args[0] - 1;
6414 } else {
6415 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6416 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6417 nl80211_policy);
6418 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006419 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006420
Johannes Berg2bd7e352012-06-15 14:23:16 +02006421 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6422 nl80211_fam.attrbuf);
6423 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006424 err = PTR_ERR(rdev);
6425 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006426 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006427 phy_idx = rdev->wiphy_idx;
6428 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006429
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006430 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6431 cb->args[1] =
6432 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6433 }
6434
6435 if (cb->args[1]) {
6436 data = nla_data((void *)cb->args[1]);
6437 data_len = nla_len((void *)cb->args[1]);
6438 }
6439
Johannes Berg00918d32011-12-13 17:22:05 +01006440 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6441 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006442 err = -ENOENT;
6443 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006444 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006445
Johannes Berg00918d32011-12-13 17:22:05 +01006446 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006447 err = -EOPNOTSUPP;
6448 goto out_err;
6449 }
6450
6451 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006452 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006453 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6454 NL80211_CMD_TESTMODE);
6455 struct nlattr *tmdata;
6456
David S. Miller9360ffd2012-03-29 04:41:26 -04006457 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006458 genlmsg_cancel(skb, hdr);
6459 break;
6460 }
6461
6462 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6463 if (!tmdata) {
6464 genlmsg_cancel(skb, hdr);
6465 break;
6466 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006467 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006468 nla_nest_end(skb, tmdata);
6469
6470 if (err == -ENOBUFS || err == -ENOENT) {
6471 genlmsg_cancel(skb, hdr);
6472 break;
6473 } else if (err) {
6474 genlmsg_cancel(skb, hdr);
6475 goto out_err;
6476 }
6477
6478 genlmsg_end(skb, hdr);
6479 }
6480
6481 err = skb->len;
6482 /* see above */
6483 cb->args[0] = phy_idx + 1;
6484 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006485 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006486 return err;
6487}
6488
Johannes Bergaff89a92009-07-01 21:26:51 +02006489static struct sk_buff *
6490__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006491 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006492{
6493 struct sk_buff *skb;
6494 void *hdr;
6495 struct nlattr *data;
6496
6497 skb = nlmsg_new(approxlen + 100, gfp);
6498 if (!skb)
6499 return NULL;
6500
Eric W. Biederman15e47302012-09-07 20:12:54 +00006501 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006502 if (!hdr) {
6503 kfree_skb(skb);
6504 return NULL;
6505 }
6506
David S. Miller9360ffd2012-03-29 04:41:26 -04006507 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6508 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006509 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6510
6511 ((void **)skb->cb)[0] = rdev;
6512 ((void **)skb->cb)[1] = hdr;
6513 ((void **)skb->cb)[2] = data;
6514
6515 return skb;
6516
6517 nla_put_failure:
6518 kfree_skb(skb);
6519 return NULL;
6520}
6521
6522struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6523 int approxlen)
6524{
6525 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6526
6527 if (WARN_ON(!rdev->testmode_info))
6528 return NULL;
6529
6530 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006531 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006532 rdev->testmode_info->snd_seq,
6533 GFP_KERNEL);
6534}
6535EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6536
6537int cfg80211_testmode_reply(struct sk_buff *skb)
6538{
6539 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6540 void *hdr = ((void **)skb->cb)[1];
6541 struct nlattr *data = ((void **)skb->cb)[2];
6542
6543 if (WARN_ON(!rdev->testmode_info)) {
6544 kfree_skb(skb);
6545 return -EINVAL;
6546 }
6547
6548 nla_nest_end(skb, data);
6549 genlmsg_end(skb, hdr);
6550 return genlmsg_reply(skb, rdev->testmode_info);
6551}
6552EXPORT_SYMBOL(cfg80211_testmode_reply);
6553
6554struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6555 int approxlen, gfp_t gfp)
6556{
6557 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6558
6559 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6560}
6561EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6562
6563void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6564{
6565 void *hdr = ((void **)skb->cb)[1];
6566 struct nlattr *data = ((void **)skb->cb)[2];
6567
6568 nla_nest_end(skb, data);
6569 genlmsg_end(skb, hdr);
6570 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6571}
6572EXPORT_SYMBOL(cfg80211_testmode_event);
6573#endif
6574
Samuel Ortizb23aa672009-07-01 21:26:54 +02006575static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6576{
Johannes Berg4c476992010-10-04 21:36:35 +02006577 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6578 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006579 struct cfg80211_connect_params connect;
6580 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006581 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006582 int err;
6583
6584 memset(&connect, 0, sizeof(connect));
6585
6586 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6587 return -EINVAL;
6588
6589 if (!info->attrs[NL80211_ATTR_SSID] ||
6590 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6591 return -EINVAL;
6592
6593 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6594 connect.auth_type =
6595 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006596 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6597 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006598 return -EINVAL;
6599 } else
6600 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6601
6602 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6603
Johannes Bergc0692b82010-08-27 14:26:53 +03006604 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006605 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006606 if (err)
6607 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006608
Johannes Berg074ac8d2010-09-16 14:58:22 +02006609 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006610 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6611 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006612
Johannes Berg79c97e92009-07-07 03:56:12 +02006613 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006614
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306615 connect.bg_scan_period = -1;
6616 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6617 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6618 connect.bg_scan_period =
6619 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6620 }
6621
Samuel Ortizb23aa672009-07-01 21:26:54 +02006622 if (info->attrs[NL80211_ATTR_MAC])
6623 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6624 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6625 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6626
6627 if (info->attrs[NL80211_ATTR_IE]) {
6628 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6629 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6630 }
6631
Jouni Malinencee00a92013-01-15 17:15:57 +02006632 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6633 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6634 if (connect.mfp != NL80211_MFP_REQUIRED &&
6635 connect.mfp != NL80211_MFP_NO)
6636 return -EINVAL;
6637 } else {
6638 connect.mfp = NL80211_MFP_NO;
6639 }
6640
Samuel Ortizb23aa672009-07-01 21:26:54 +02006641 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6642 connect.channel =
6643 ieee80211_get_channel(wiphy,
6644 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6645 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006646 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6647 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006648 }
6649
Johannes Bergfffd0932009-07-08 14:22:54 +02006650 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6651 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306652 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006653 if (IS_ERR(connkeys))
6654 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006655 }
6656
Ben Greear7e7c8922011-11-18 11:31:59 -08006657 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6658 connect.flags |= ASSOC_REQ_DISABLE_HT;
6659
6660 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6661 memcpy(&connect.ht_capa_mask,
6662 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6663 sizeof(connect.ht_capa_mask));
6664
6665 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006666 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6667 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006668 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006669 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006670 memcpy(&connect.ht_capa,
6671 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6672 sizeof(connect.ht_capa));
6673 }
6674
Johannes Bergee2aca32013-02-21 17:36:01 +01006675 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6676 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6677
6678 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6679 memcpy(&connect.vht_capa_mask,
6680 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6681 sizeof(connect.vht_capa_mask));
6682
6683 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6684 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6685 kfree(connkeys);
6686 return -EINVAL;
6687 }
6688 memcpy(&connect.vht_capa,
6689 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6690 sizeof(connect.vht_capa));
6691 }
6692
Johannes Berg83739b02013-05-15 17:44:01 +02006693 wdev_lock(dev->ieee80211_ptr);
6694 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6695 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006696 if (err)
6697 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006698 return err;
6699}
6700
6701static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6702{
Johannes Berg4c476992010-10-04 21:36:35 +02006703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6704 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006705 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006706 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006707
6708 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6709 reason = WLAN_REASON_DEAUTH_LEAVING;
6710 else
6711 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6712
6713 if (reason == 0)
6714 return -EINVAL;
6715
Johannes Berg074ac8d2010-09-16 14:58:22 +02006716 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006717 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6718 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006719
Johannes Berg83739b02013-05-15 17:44:01 +02006720 wdev_lock(dev->ieee80211_ptr);
6721 ret = cfg80211_disconnect(rdev, dev, reason, true);
6722 wdev_unlock(dev->ieee80211_ptr);
6723 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006724}
6725
Johannes Berg463d0182009-07-14 00:33:35 +02006726static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6727{
Johannes Berg4c476992010-10-04 21:36:35 +02006728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006729 struct net *net;
6730 int err;
6731 u32 pid;
6732
6733 if (!info->attrs[NL80211_ATTR_PID])
6734 return -EINVAL;
6735
6736 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6737
Johannes Berg463d0182009-07-14 00:33:35 +02006738 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006739 if (IS_ERR(net))
6740 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006741
6742 err = 0;
6743
6744 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006745 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6746 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006747
Johannes Berg463d0182009-07-14 00:33:35 +02006748 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006749 return err;
6750}
6751
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006752static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6753{
Johannes Berg4c476992010-10-04 21:36:35 +02006754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006755 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6756 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006757 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006758 struct cfg80211_pmksa pmksa;
6759
6760 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6761
6762 if (!info->attrs[NL80211_ATTR_MAC])
6763 return -EINVAL;
6764
6765 if (!info->attrs[NL80211_ATTR_PMKID])
6766 return -EINVAL;
6767
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006768 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6769 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6770
Johannes Berg074ac8d2010-09-16 14:58:22 +02006771 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006772 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6773 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006774
6775 switch (info->genlhdr->cmd) {
6776 case NL80211_CMD_SET_PMKSA:
6777 rdev_ops = rdev->ops->set_pmksa;
6778 break;
6779 case NL80211_CMD_DEL_PMKSA:
6780 rdev_ops = rdev->ops->del_pmksa;
6781 break;
6782 default:
6783 WARN_ON(1);
6784 break;
6785 }
6786
Johannes Berg4c476992010-10-04 21:36:35 +02006787 if (!rdev_ops)
6788 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006789
Johannes Berg4c476992010-10-04 21:36:35 +02006790 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006791}
6792
6793static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6794{
Johannes Berg4c476992010-10-04 21:36:35 +02006795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6796 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006797
Johannes Berg074ac8d2010-09-16 14:58:22 +02006798 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006799 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6800 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006801
Johannes Berg4c476992010-10-04 21:36:35 +02006802 if (!rdev->ops->flush_pmksa)
6803 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006804
Hila Gonene35e4d22012-06-27 17:19:42 +03006805 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006806}
6807
Arik Nemtsov109086c2011-09-28 14:12:50 +03006808static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6809{
6810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6811 struct net_device *dev = info->user_ptr[1];
6812 u8 action_code, dialog_token;
6813 u16 status_code;
6814 u8 *peer;
6815
6816 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6817 !rdev->ops->tdls_mgmt)
6818 return -EOPNOTSUPP;
6819
6820 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6821 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6822 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6823 !info->attrs[NL80211_ATTR_IE] ||
6824 !info->attrs[NL80211_ATTR_MAC])
6825 return -EINVAL;
6826
6827 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6828 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6829 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6830 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6831
Hila Gonene35e4d22012-06-27 17:19:42 +03006832 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6833 dialog_token, status_code,
6834 nla_data(info->attrs[NL80211_ATTR_IE]),
6835 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006836}
6837
6838static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6839{
6840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6841 struct net_device *dev = info->user_ptr[1];
6842 enum nl80211_tdls_operation operation;
6843 u8 *peer;
6844
6845 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6846 !rdev->ops->tdls_oper)
6847 return -EOPNOTSUPP;
6848
6849 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6850 !info->attrs[NL80211_ATTR_MAC])
6851 return -EINVAL;
6852
6853 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6854 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6855
Hila Gonene35e4d22012-06-27 17:19:42 +03006856 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006857}
6858
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006859static int nl80211_remain_on_channel(struct sk_buff *skb,
6860 struct genl_info *info)
6861{
Johannes Berg4c476992010-10-04 21:36:35 +02006862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006863 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006864 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006865 struct sk_buff *msg;
6866 void *hdr;
6867 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006868 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006869 int err;
6870
6871 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6872 !info->attrs[NL80211_ATTR_DURATION])
6873 return -EINVAL;
6874
6875 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6876
Johannes Berg7c4ef712011-11-18 15:33:48 +01006877 if (!rdev->ops->remain_on_channel ||
6878 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006879 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006880
Johannes Bergebf348f2012-06-01 12:50:54 +02006881 /*
6882 * We should be on that channel for at least a minimum amount of
6883 * time (10ms) but no longer than the driver supports.
6884 */
6885 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6886 duration > rdev->wiphy.max_remain_on_channel_duration)
6887 return -EINVAL;
6888
Johannes Berg683b6d32012-11-08 21:25:48 +01006889 err = nl80211_parse_chandef(rdev, info, &chandef);
6890 if (err)
6891 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006892
6893 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006894 if (!msg)
6895 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006896
Eric W. Biederman15e47302012-09-07 20:12:54 +00006897 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006898 NL80211_CMD_REMAIN_ON_CHANNEL);
6899
6900 if (IS_ERR(hdr)) {
6901 err = PTR_ERR(hdr);
6902 goto free_msg;
6903 }
6904
Johannes Berg683b6d32012-11-08 21:25:48 +01006905 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6906 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006907
6908 if (err)
6909 goto free_msg;
6910
David S. Miller9360ffd2012-03-29 04:41:26 -04006911 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6912 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006913
6914 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006915
6916 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006917
6918 nla_put_failure:
6919 err = -ENOBUFS;
6920 free_msg:
6921 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006922 return err;
6923}
6924
6925static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6926 struct genl_info *info)
6927{
Johannes Berg4c476992010-10-04 21:36:35 +02006928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006929 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006930 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006931
6932 if (!info->attrs[NL80211_ATTR_COOKIE])
6933 return -EINVAL;
6934
Johannes Berg4c476992010-10-04 21:36:35 +02006935 if (!rdev->ops->cancel_remain_on_channel)
6936 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006937
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006938 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6939
Hila Gonene35e4d22012-06-27 17:19:42 +03006940 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006941}
6942
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006943static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6944 u8 *rates, u8 rates_len)
6945{
6946 u8 i;
6947 u32 mask = 0;
6948
6949 for (i = 0; i < rates_len; i++) {
6950 int rate = (rates[i] & 0x7f) * 5;
6951 int ridx;
6952 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
6953 struct ieee80211_rate *srate =
6954 &sband->bitrates[ridx];
6955 if (rate == srate->bitrate) {
6956 mask |= 1 << ridx;
6957 break;
6958 }
6959 }
6960 if (ridx == sband->n_bitrates)
6961 return 0; /* rate not found */
6962 }
6963
6964 return mask;
6965}
6966
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006967static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
6968 u8 *rates, u8 rates_len,
6969 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
6970{
6971 u8 i;
6972
6973 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
6974
6975 for (i = 0; i < rates_len; i++) {
6976 int ridx, rbit;
6977
6978 ridx = rates[i] / 8;
6979 rbit = BIT(rates[i] % 8);
6980
6981 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03006982 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006983 return false;
6984
6985 /* check availability */
6986 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
6987 mcs[ridx] |= rbit;
6988 else
6989 return false;
6990 }
6991
6992 return true;
6993}
6994
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00006995static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006996 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
6997 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01006998 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
6999 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007000};
7001
7002static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7003 struct genl_info *info)
7004{
7005 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007007 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007008 int rem, i;
7009 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007010 struct nlattr *tx_rates;
7011 struct ieee80211_supported_band *sband;
7012
7013 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7014 return -EINVAL;
7015
Johannes Berg4c476992010-10-04 21:36:35 +02007016 if (!rdev->ops->set_bitrate_mask)
7017 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007018
7019 memset(&mask, 0, sizeof(mask));
7020 /* Default to all rates enabled */
7021 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7022 sband = rdev->wiphy.bands[i];
7023 mask.control[i].legacy =
7024 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007025 if (sband)
7026 memcpy(mask.control[i].mcs,
7027 sband->ht_cap.mcs.rx_mask,
7028 sizeof(mask.control[i].mcs));
7029 else
7030 memset(mask.control[i].mcs, 0,
7031 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007032 }
7033
7034 /*
7035 * The nested attribute uses enum nl80211_band as the index. This maps
7036 * directly to the enum ieee80211_band values used in cfg80211.
7037 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007038 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007039 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7040 {
7041 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007042 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7043 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007044 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007045 if (sband == NULL)
7046 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007047 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7048 nla_len(tx_rates), nl80211_txattr_policy);
7049 if (tb[NL80211_TXRATE_LEGACY]) {
7050 mask.control[band].legacy = rateset_to_mask(
7051 sband,
7052 nla_data(tb[NL80211_TXRATE_LEGACY]),
7053 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307054 if ((mask.control[band].legacy == 0) &&
7055 nla_len(tb[NL80211_TXRATE_LEGACY]))
7056 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007057 }
7058 if (tb[NL80211_TXRATE_MCS]) {
7059 if (!ht_rateset_to_mask(
7060 sband,
7061 nla_data(tb[NL80211_TXRATE_MCS]),
7062 nla_len(tb[NL80211_TXRATE_MCS]),
7063 mask.control[band].mcs))
7064 return -EINVAL;
7065 }
7066
7067 if (mask.control[band].legacy == 0) {
7068 /* don't allow empty legacy rates if HT
7069 * is not even supported. */
7070 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7071 return -EINVAL;
7072
7073 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7074 if (mask.control[band].mcs[i])
7075 break;
7076
7077 /* legacy and mcs rates may not be both empty */
7078 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007079 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007080 }
7081 }
7082
Hila Gonene35e4d22012-06-27 17:19:42 +03007083 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007084}
7085
Johannes Berg2e161f72010-08-12 15:38:38 +02007086static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007087{
Johannes Berg4c476992010-10-04 21:36:35 +02007088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007089 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007090 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007091
7092 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7093 return -EINVAL;
7094
Johannes Berg2e161f72010-08-12 15:38:38 +02007095 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7096 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007097
Johannes Berg71bbc992012-06-15 15:30:18 +02007098 switch (wdev->iftype) {
7099 case NL80211_IFTYPE_STATION:
7100 case NL80211_IFTYPE_ADHOC:
7101 case NL80211_IFTYPE_P2P_CLIENT:
7102 case NL80211_IFTYPE_AP:
7103 case NL80211_IFTYPE_AP_VLAN:
7104 case NL80211_IFTYPE_MESH_POINT:
7105 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007106 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007107 break;
7108 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007109 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007110 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007111
7112 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007113 if (!rdev->ops->mgmt_tx)
7114 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007115
Eric W. Biederman15e47302012-09-07 20:12:54 +00007116 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007117 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7118 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007119}
7120
Johannes Berg2e161f72010-08-12 15:38:38 +02007121static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007122{
Johannes Berg4c476992010-10-04 21:36:35 +02007123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007124 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007125 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007126 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007127 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007128 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007129 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007130 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007131 bool offchan, no_cck, dont_wait_for_ack;
7132
7133 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007134
Johannes Berg683b6d32012-11-08 21:25:48 +01007135 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007136 return -EINVAL;
7137
Johannes Berg4c476992010-10-04 21:36:35 +02007138 if (!rdev->ops->mgmt_tx)
7139 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007140
Johannes Berg71bbc992012-06-15 15:30:18 +02007141 switch (wdev->iftype) {
7142 case NL80211_IFTYPE_STATION:
7143 case NL80211_IFTYPE_ADHOC:
7144 case NL80211_IFTYPE_P2P_CLIENT:
7145 case NL80211_IFTYPE_AP:
7146 case NL80211_IFTYPE_AP_VLAN:
7147 case NL80211_IFTYPE_MESH_POINT:
7148 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007149 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007150 break;
7151 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007152 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007153 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007154
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007155 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007156 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007157 return -EINVAL;
7158 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007159
7160 /*
7161 * We should wait on the channel for at least a minimum amount
7162 * of time (10ms) but no longer than the driver supports.
7163 */
7164 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7165 wait > rdev->wiphy.max_remain_on_channel_duration)
7166 return -EINVAL;
7167
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007168 }
7169
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007170 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7171
Johannes Berg7c4ef712011-11-18 15:33:48 +01007172 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7173 return -EINVAL;
7174
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307175 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7176
Johannes Berg683b6d32012-11-08 21:25:48 +01007177 err = nl80211_parse_chandef(rdev, info, &chandef);
7178 if (err)
7179 return err;
Jouni Malinen026331c2010-02-15 12:53:10 +02007180
Johannes Berge247bd902011-11-04 11:18:21 +01007181 if (!dont_wait_for_ack) {
7182 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7183 if (!msg)
7184 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007185
Eric W. Biederman15e47302012-09-07 20:12:54 +00007186 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007187 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007188
Johannes Berge247bd902011-11-04 11:18:21 +01007189 if (IS_ERR(hdr)) {
7190 err = PTR_ERR(hdr);
7191 goto free_msg;
7192 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007193 }
Johannes Berge247bd902011-11-04 11:18:21 +01007194
Johannes Berg683b6d32012-11-08 21:25:48 +01007195 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007196 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7197 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007198 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007199 if (err)
7200 goto free_msg;
7201
Johannes Berge247bd902011-11-04 11:18:21 +01007202 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007203 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7204 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007205
Johannes Berge247bd902011-11-04 11:18:21 +01007206 genlmsg_end(msg, hdr);
7207 return genlmsg_reply(msg, info);
7208 }
7209
7210 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007211
7212 nla_put_failure:
7213 err = -ENOBUFS;
7214 free_msg:
7215 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007216 return err;
7217}
7218
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007219static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7220{
7221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007222 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007223 u64 cookie;
7224
7225 if (!info->attrs[NL80211_ATTR_COOKIE])
7226 return -EINVAL;
7227
7228 if (!rdev->ops->mgmt_tx_cancel_wait)
7229 return -EOPNOTSUPP;
7230
Johannes Berg71bbc992012-06-15 15:30:18 +02007231 switch (wdev->iftype) {
7232 case NL80211_IFTYPE_STATION:
7233 case NL80211_IFTYPE_ADHOC:
7234 case NL80211_IFTYPE_P2P_CLIENT:
7235 case NL80211_IFTYPE_AP:
7236 case NL80211_IFTYPE_AP_VLAN:
7237 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007238 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007239 break;
7240 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007241 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007242 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007243
7244 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7245
Hila Gonene35e4d22012-06-27 17:19:42 +03007246 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007247}
7248
Kalle Valoffb9eb32010-02-17 17:58:10 +02007249static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7250{
Johannes Berg4c476992010-10-04 21:36:35 +02007251 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007252 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007253 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007254 u8 ps_state;
7255 bool state;
7256 int err;
7257
Johannes Berg4c476992010-10-04 21:36:35 +02007258 if (!info->attrs[NL80211_ATTR_PS_STATE])
7259 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007260
7261 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7262
Johannes Berg4c476992010-10-04 21:36:35 +02007263 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7264 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007265
7266 wdev = dev->ieee80211_ptr;
7267
Johannes Berg4c476992010-10-04 21:36:35 +02007268 if (!rdev->ops->set_power_mgmt)
7269 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007270
7271 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7272
7273 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007274 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007275
Hila Gonene35e4d22012-06-27 17:19:42 +03007276 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007277 if (!err)
7278 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007279 return err;
7280}
7281
7282static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7283{
Johannes Berg4c476992010-10-04 21:36:35 +02007284 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007285 enum nl80211_ps_state ps_state;
7286 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007287 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007288 struct sk_buff *msg;
7289 void *hdr;
7290 int err;
7291
Kalle Valoffb9eb32010-02-17 17:58:10 +02007292 wdev = dev->ieee80211_ptr;
7293
Johannes Berg4c476992010-10-04 21:36:35 +02007294 if (!rdev->ops->set_power_mgmt)
7295 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007296
7297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007298 if (!msg)
7299 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007300
Eric W. Biederman15e47302012-09-07 20:12:54 +00007301 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007302 NL80211_CMD_GET_POWER_SAVE);
7303 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007304 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007305 goto free_msg;
7306 }
7307
7308 if (wdev->ps)
7309 ps_state = NL80211_PS_ENABLED;
7310 else
7311 ps_state = NL80211_PS_DISABLED;
7312
David S. Miller9360ffd2012-03-29 04:41:26 -04007313 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7314 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007315
7316 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007317 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007318
Johannes Berg4c476992010-10-04 21:36:35 +02007319 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007320 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007321 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007322 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007323 return err;
7324}
7325
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007326static struct nla_policy
7327nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7328 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7329 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7330 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007331 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7332 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7333 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007334};
7335
Thomas Pedersen84f10702012-07-12 16:17:33 -07007336static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007337 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007338{
7339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7340 struct wireless_dev *wdev;
7341 struct net_device *dev = info->user_ptr[1];
7342
Johannes Bergd9d8b012012-11-26 12:51:52 +01007343 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007344 return -EINVAL;
7345
7346 wdev = dev->ieee80211_ptr;
7347
7348 if (!rdev->ops->set_cqm_txe_config)
7349 return -EOPNOTSUPP;
7350
7351 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7352 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7353 return -EOPNOTSUPP;
7354
Hila Gonene35e4d22012-06-27 17:19:42 +03007355 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007356}
7357
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007358static int nl80211_set_cqm_rssi(struct genl_info *info,
7359 s32 threshold, u32 hysteresis)
7360{
Johannes Berg4c476992010-10-04 21:36:35 +02007361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007362 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007363 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007364
7365 if (threshold > 0)
7366 return -EINVAL;
7367
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007368 wdev = dev->ieee80211_ptr;
7369
Johannes Berg4c476992010-10-04 21:36:35 +02007370 if (!rdev->ops->set_cqm_rssi_config)
7371 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007372
Johannes Berg074ac8d2010-09-16 14:58:22 +02007373 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007374 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7375 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007376
Hila Gonene35e4d22012-06-27 17:19:42 +03007377 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007378}
7379
7380static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7381{
7382 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7383 struct nlattr *cqm;
7384 int err;
7385
7386 cqm = info->attrs[NL80211_ATTR_CQM];
7387 if (!cqm) {
7388 err = -EINVAL;
7389 goto out;
7390 }
7391
7392 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7393 nl80211_attr_cqm_policy);
7394 if (err)
7395 goto out;
7396
7397 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7398 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7399 s32 threshold;
7400 u32 hysteresis;
7401 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7402 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7403 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007404 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7405 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7406 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7407 u32 rate, pkts, intvl;
7408 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7409 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7410 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7411 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007412 } else
7413 err = -EINVAL;
7414
7415out:
7416 return err;
7417}
7418
Johannes Berg29cbe682010-12-03 09:20:44 +01007419static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7420{
7421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7422 struct net_device *dev = info->user_ptr[1];
7423 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007424 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007425 int err;
7426
7427 /* start with default */
7428 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007429 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007430
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007431 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007432 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007433 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007434 if (err)
7435 return err;
7436 }
7437
7438 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7439 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7440 return -EINVAL;
7441
Javier Cardonac80d5452010-12-16 17:37:49 -08007442 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7443 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7444
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007445 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7446 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7447 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7448 return -EINVAL;
7449
Marco Porsch9bdbf042013-01-07 16:04:51 +01007450 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7451 setup.beacon_interval =
7452 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7453 if (setup.beacon_interval < 10 ||
7454 setup.beacon_interval > 10000)
7455 return -EINVAL;
7456 }
7457
7458 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7459 setup.dtim_period =
7460 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7461 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7462 return -EINVAL;
7463 }
7464
Javier Cardonac80d5452010-12-16 17:37:49 -08007465 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7466 /* parse additional setup parameters if given */
7467 err = nl80211_parse_mesh_setup(info, &setup);
7468 if (err)
7469 return err;
7470 }
7471
Thomas Pedersend37bb182013-03-04 13:06:13 -08007472 if (setup.user_mpm)
7473 cfg.auto_open_plinks = false;
7474
Johannes Bergcc1d2802012-05-16 23:50:20 +02007475 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007476 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7477 if (err)
7478 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007479 } else {
7480 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007481 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007482 }
7483
Javier Cardonac80d5452010-12-16 17:37:49 -08007484 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007485}
7486
7487static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7488{
7489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7490 struct net_device *dev = info->user_ptr[1];
7491
7492 return cfg80211_leave_mesh(rdev, dev);
7493}
7494
Johannes Bergdfb89c52012-06-27 09:23:48 +02007495#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007496static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7497 struct cfg80211_registered_device *rdev)
7498{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007499 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007500 struct nlattr *nl_pats, *nl_pat;
7501 int i, pat_len;
7502
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007503 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007504 return 0;
7505
7506 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7507 if (!nl_pats)
7508 return -ENOBUFS;
7509
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007510 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007511 nl_pat = nla_nest_start(msg, i + 1);
7512 if (!nl_pat)
7513 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007514 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007515 if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
7516 DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007517 wowlan->patterns[i].mask) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007518 nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007519 pat_len, wowlan->patterns[i].pattern) ||
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007520 nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007521 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007522 return -ENOBUFS;
7523 nla_nest_end(msg, nl_pat);
7524 }
7525 nla_nest_end(msg, nl_pats);
7526
7527 return 0;
7528}
7529
Johannes Berg2a0e0472013-01-23 22:57:40 +01007530static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7531 struct cfg80211_wowlan_tcp *tcp)
7532{
7533 struct nlattr *nl_tcp;
7534
7535 if (!tcp)
7536 return 0;
7537
7538 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7539 if (!nl_tcp)
7540 return -ENOBUFS;
7541
7542 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7543 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7544 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7545 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7546 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7547 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7548 tcp->payload_len, tcp->payload) ||
7549 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7550 tcp->data_interval) ||
7551 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7552 tcp->wake_len, tcp->wake_data) ||
7553 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7554 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7555 return -ENOBUFS;
7556
7557 if (tcp->payload_seq.len &&
7558 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7559 sizeof(tcp->payload_seq), &tcp->payload_seq))
7560 return -ENOBUFS;
7561
7562 if (tcp->payload_tok.len &&
7563 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7564 sizeof(tcp->payload_tok) + tcp->tokens_size,
7565 &tcp->payload_tok))
7566 return -ENOBUFS;
7567
Johannes Berge248ad32013-05-16 10:24:28 +02007568 nla_nest_end(msg, nl_tcp);
7569
Johannes Berg2a0e0472013-01-23 22:57:40 +01007570 return 0;
7571}
7572
Johannes Bergff1b6e62011-05-04 15:37:28 +02007573static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7574{
7575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7576 struct sk_buff *msg;
7577 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007578 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007579
Johannes Berg964dc9e2013-06-03 17:25:34 +02007580 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007581 return -EOPNOTSUPP;
7582
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007583 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007584 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007585 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7586 rdev->wiphy.wowlan_config->tcp->payload_len +
7587 rdev->wiphy.wowlan_config->tcp->wake_len +
7588 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007589 }
7590
7591 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007592 if (!msg)
7593 return -ENOMEM;
7594
Eric W. Biederman15e47302012-09-07 20:12:54 +00007595 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007596 NL80211_CMD_GET_WOWLAN);
7597 if (!hdr)
7598 goto nla_put_failure;
7599
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007600 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007601 struct nlattr *nl_wowlan;
7602
7603 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7604 if (!nl_wowlan)
7605 goto nla_put_failure;
7606
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007607 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007608 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007609 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007610 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007611 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007612 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007613 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007614 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007615 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007616 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007617 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007618 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007619 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007620 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7621 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007622
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007623 if (nl80211_send_wowlan_patterns(msg, rdev))
7624 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007625
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007626 if (nl80211_send_wowlan_tcp(msg,
7627 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007628 goto nla_put_failure;
7629
Johannes Bergff1b6e62011-05-04 15:37:28 +02007630 nla_nest_end(msg, nl_wowlan);
7631 }
7632
7633 genlmsg_end(msg, hdr);
7634 return genlmsg_reply(msg, info);
7635
7636nla_put_failure:
7637 nlmsg_free(msg);
7638 return -ENOBUFS;
7639}
7640
Johannes Berg2a0e0472013-01-23 22:57:40 +01007641static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7642 struct nlattr *attr,
7643 struct cfg80211_wowlan *trig)
7644{
7645 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7646 struct cfg80211_wowlan_tcp *cfg;
7647 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7648 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7649 u32 size;
7650 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7651 int err, port;
7652
Johannes Berg964dc9e2013-06-03 17:25:34 +02007653 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007654 return -EINVAL;
7655
7656 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7657 nla_data(attr), nla_len(attr),
7658 nl80211_wowlan_tcp_policy);
7659 if (err)
7660 return err;
7661
7662 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7663 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7664 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7665 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7666 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7667 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7668 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7669 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7670 return -EINVAL;
7671
7672 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007673 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007674 return -EINVAL;
7675
7676 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007677 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007678 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007679 return -EINVAL;
7680
7681 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007682 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007683 return -EINVAL;
7684
7685 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7686 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7687 return -EINVAL;
7688
7689 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7690 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7691
7692 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7693 tokens_size = tokln - sizeof(*tok);
7694
7695 if (!tok->len || tokens_size % tok->len)
7696 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007697 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007698 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007699 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007700 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007701 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007702 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007703 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007704 return -EINVAL;
7705 if (tok->offset + tok->len > data_size)
7706 return -EINVAL;
7707 }
7708
7709 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7710 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007711 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007712 return -EINVAL;
7713 if (seq->len == 0 || seq->len > 4)
7714 return -EINVAL;
7715 if (seq->len + seq->offset > data_size)
7716 return -EINVAL;
7717 }
7718
7719 size = sizeof(*cfg);
7720 size += data_size;
7721 size += wake_size + wake_mask_size;
7722 size += tokens_size;
7723
7724 cfg = kzalloc(size, GFP_KERNEL);
7725 if (!cfg)
7726 return -ENOMEM;
7727 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7728 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7729 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7730 ETH_ALEN);
7731 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7732 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7733 else
7734 port = 0;
7735#ifdef CONFIG_INET
7736 /* allocate a socket and port for it and use it */
7737 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7738 IPPROTO_TCP, &cfg->sock, 1);
7739 if (err) {
7740 kfree(cfg);
7741 return err;
7742 }
7743 if (inet_csk_get_port(cfg->sock->sk, port)) {
7744 sock_release(cfg->sock);
7745 kfree(cfg);
7746 return -EADDRINUSE;
7747 }
7748 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7749#else
7750 if (!port) {
7751 kfree(cfg);
7752 return -EINVAL;
7753 }
7754 cfg->src_port = port;
7755#endif
7756
7757 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7758 cfg->payload_len = data_size;
7759 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7760 memcpy((void *)cfg->payload,
7761 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7762 data_size);
7763 if (seq)
7764 cfg->payload_seq = *seq;
7765 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7766 cfg->wake_len = wake_size;
7767 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7768 memcpy((void *)cfg->wake_data,
7769 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7770 wake_size);
7771 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7772 data_size + wake_size;
7773 memcpy((void *)cfg->wake_mask,
7774 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7775 wake_mask_size);
7776 if (tok) {
7777 cfg->tokens_size = tokens_size;
7778 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7779 }
7780
7781 trig->tcp = cfg;
7782
7783 return 0;
7784}
7785
Johannes Bergff1b6e62011-05-04 15:37:28 +02007786static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7787{
7788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7789 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007790 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007791 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007792 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007793 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007794 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007795
Johannes Berg964dc9e2013-06-03 17:25:34 +02007796 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007797 return -EOPNOTSUPP;
7798
Johannes Bergae33bd82012-07-12 16:25:02 +02007799 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7800 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007801 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007802 goto set_wakeup;
7803 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007804
7805 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7806 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7807 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7808 nl80211_wowlan_policy);
7809 if (err)
7810 return err;
7811
7812 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7813 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7814 return -EINVAL;
7815 new_triggers.any = true;
7816 }
7817
7818 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7819 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7820 return -EINVAL;
7821 new_triggers.disconnect = true;
7822 }
7823
7824 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7825 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7826 return -EINVAL;
7827 new_triggers.magic_pkt = true;
7828 }
7829
Johannes Berg77dbbb12011-07-13 10:48:55 +02007830 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7831 return -EINVAL;
7832
7833 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7834 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7835 return -EINVAL;
7836 new_triggers.gtk_rekey_failure = true;
7837 }
7838
7839 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7840 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7841 return -EINVAL;
7842 new_triggers.eap_identity_req = true;
7843 }
7844
7845 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7846 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7847 return -EINVAL;
7848 new_triggers.four_way_handshake = true;
7849 }
7850
7851 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7852 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7853 return -EINVAL;
7854 new_triggers.rfkill_release = true;
7855 }
7856
Johannes Bergff1b6e62011-05-04 15:37:28 +02007857 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7858 struct nlattr *pat;
7859 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007860 int rem, pat_len, mask_len, pkt_offset;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007861 struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
7862
7863 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7864 rem)
7865 n_patterns++;
7866 if (n_patterns > wowlan->n_patterns)
7867 return -EINVAL;
7868
7869 new_triggers.patterns = kcalloc(n_patterns,
7870 sizeof(new_triggers.patterns[0]),
7871 GFP_KERNEL);
7872 if (!new_triggers.patterns)
7873 return -ENOMEM;
7874
7875 new_triggers.n_patterns = n_patterns;
7876 i = 0;
7877
7878 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7879 rem) {
7880 nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
7881 nla_data(pat), nla_len(pat), NULL);
7882 err = -EINVAL;
7883 if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
7884 !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
7885 goto error;
7886 pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
7887 mask_len = DIV_ROUND_UP(pat_len, 8);
7888 if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
7889 mask_len)
7890 goto error;
7891 if (pat_len > wowlan->pattern_max_len ||
7892 pat_len < wowlan->pattern_min_len)
7893 goto error;
7894
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007895 if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
7896 pkt_offset = 0;
7897 else
7898 pkt_offset = nla_get_u32(
7899 pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
7900 if (pkt_offset > wowlan->max_pkt_offset)
7901 goto error;
7902 new_triggers.patterns[i].pkt_offset = pkt_offset;
7903
Johannes Bergff1b6e62011-05-04 15:37:28 +02007904 new_triggers.patterns[i].mask =
7905 kmalloc(mask_len + pat_len, GFP_KERNEL);
7906 if (!new_triggers.patterns[i].mask) {
7907 err = -ENOMEM;
7908 goto error;
7909 }
7910 new_triggers.patterns[i].pattern =
7911 new_triggers.patterns[i].mask + mask_len;
7912 memcpy(new_triggers.patterns[i].mask,
7913 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
7914 mask_len);
7915 new_triggers.patterns[i].pattern_len = pat_len;
7916 memcpy(new_triggers.patterns[i].pattern,
7917 nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
7918 pat_len);
7919 i++;
7920 }
7921 }
7922
Johannes Berg2a0e0472013-01-23 22:57:40 +01007923 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
7924 err = nl80211_parse_wowlan_tcp(
7925 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
7926 &new_triggers);
7927 if (err)
7928 goto error;
7929 }
7930
Johannes Bergae33bd82012-07-12 16:25:02 +02007931 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
7932 if (!ntrig) {
7933 err = -ENOMEM;
7934 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007935 }
Johannes Bergae33bd82012-07-12 16:25:02 +02007936 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007937 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007938
Johannes Bergae33bd82012-07-12 16:25:02 +02007939 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007940 if (rdev->ops->set_wakeup &&
7941 prev_enabled != !!rdev->wiphy.wowlan_config)
7942 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02007943
Johannes Bergff1b6e62011-05-04 15:37:28 +02007944 return 0;
7945 error:
7946 for (i = 0; i < new_triggers.n_patterns; i++)
7947 kfree(new_triggers.patterns[i].mask);
7948 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01007949 if (new_triggers.tcp && new_triggers.tcp->sock)
7950 sock_release(new_triggers.tcp->sock);
7951 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007952 return err;
7953}
Johannes Bergdfb89c52012-06-27 09:23:48 +02007954#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02007955
Johannes Berge5497d72011-07-05 16:35:40 +02007956static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
7957{
7958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7959 struct net_device *dev = info->user_ptr[1];
7960 struct wireless_dev *wdev = dev->ieee80211_ptr;
7961 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
7962 struct cfg80211_gtk_rekey_data rekey_data;
7963 int err;
7964
7965 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
7966 return -EINVAL;
7967
7968 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
7969 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
7970 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
7971 nl80211_rekey_policy);
7972 if (err)
7973 return err;
7974
7975 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
7976 return -ERANGE;
7977 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
7978 return -ERANGE;
7979 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
7980 return -ERANGE;
7981
7982 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
7983 NL80211_KEK_LEN);
7984 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
7985 NL80211_KCK_LEN);
7986 memcpy(rekey_data.replay_ctr,
7987 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
7988 NL80211_REPLAY_CTR_LEN);
7989
7990 wdev_lock(wdev);
7991 if (!wdev->current_bss) {
7992 err = -ENOTCONN;
7993 goto out;
7994 }
7995
7996 if (!rdev->ops->set_rekey_data) {
7997 err = -EOPNOTSUPP;
7998 goto out;
7999 }
8000
Hila Gonene35e4d22012-06-27 17:19:42 +03008001 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008002 out:
8003 wdev_unlock(wdev);
8004 return err;
8005}
8006
Johannes Berg28946da2011-11-04 11:18:12 +01008007static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8008 struct genl_info *info)
8009{
8010 struct net_device *dev = info->user_ptr[1];
8011 struct wireless_dev *wdev = dev->ieee80211_ptr;
8012
8013 if (wdev->iftype != NL80211_IFTYPE_AP &&
8014 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8015 return -EINVAL;
8016
Eric W. Biederman15e47302012-09-07 20:12:54 +00008017 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008018 return -EBUSY;
8019
Eric W. Biederman15e47302012-09-07 20:12:54 +00008020 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008021 return 0;
8022}
8023
Johannes Berg7f6cf312011-11-04 11:18:15 +01008024static int nl80211_probe_client(struct sk_buff *skb,
8025 struct genl_info *info)
8026{
8027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8028 struct net_device *dev = info->user_ptr[1];
8029 struct wireless_dev *wdev = dev->ieee80211_ptr;
8030 struct sk_buff *msg;
8031 void *hdr;
8032 const u8 *addr;
8033 u64 cookie;
8034 int err;
8035
8036 if (wdev->iftype != NL80211_IFTYPE_AP &&
8037 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8038 return -EOPNOTSUPP;
8039
8040 if (!info->attrs[NL80211_ATTR_MAC])
8041 return -EINVAL;
8042
8043 if (!rdev->ops->probe_client)
8044 return -EOPNOTSUPP;
8045
8046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8047 if (!msg)
8048 return -ENOMEM;
8049
Eric W. Biederman15e47302012-09-07 20:12:54 +00008050 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008051 NL80211_CMD_PROBE_CLIENT);
8052
8053 if (IS_ERR(hdr)) {
8054 err = PTR_ERR(hdr);
8055 goto free_msg;
8056 }
8057
8058 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8059
Hila Gonene35e4d22012-06-27 17:19:42 +03008060 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008061 if (err)
8062 goto free_msg;
8063
David S. Miller9360ffd2012-03-29 04:41:26 -04008064 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8065 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008066
8067 genlmsg_end(msg, hdr);
8068
8069 return genlmsg_reply(msg, info);
8070
8071 nla_put_failure:
8072 err = -ENOBUFS;
8073 free_msg:
8074 nlmsg_free(msg);
8075 return err;
8076}
8077
Johannes Berg5e7602302011-11-04 11:18:17 +01008078static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8079{
8080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008081 struct cfg80211_beacon_registration *reg, *nreg;
8082 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008083
8084 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8085 return -EOPNOTSUPP;
8086
Ben Greear37c73b52012-10-26 14:49:25 -07008087 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8088 if (!nreg)
8089 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008090
Ben Greear37c73b52012-10-26 14:49:25 -07008091 /* First, check if already registered. */
8092 spin_lock_bh(&rdev->beacon_registrations_lock);
8093 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8094 if (reg->nlportid == info->snd_portid) {
8095 rv = -EALREADY;
8096 goto out_err;
8097 }
8098 }
8099 /* Add it to the list */
8100 nreg->nlportid = info->snd_portid;
8101 list_add(&nreg->list, &rdev->beacon_registrations);
8102
8103 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008104
8105 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008106out_err:
8107 spin_unlock_bh(&rdev->beacon_registrations_lock);
8108 kfree(nreg);
8109 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008110}
8111
Johannes Berg98104fde2012-06-16 00:19:54 +02008112static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8113{
8114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8115 struct wireless_dev *wdev = info->user_ptr[1];
8116 int err;
8117
8118 if (!rdev->ops->start_p2p_device)
8119 return -EOPNOTSUPP;
8120
8121 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8122 return -EOPNOTSUPP;
8123
8124 if (wdev->p2p_started)
8125 return 0;
8126
Johannes Berg98104fde2012-06-16 00:19:54 +02008127 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008128 if (err)
8129 return err;
8130
Johannes Bergeeb126e2012-10-23 15:16:50 +02008131 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008132 if (err)
8133 return err;
8134
8135 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008136 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008137
8138 return 0;
8139}
8140
8141static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8142{
8143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8144 struct wireless_dev *wdev = info->user_ptr[1];
8145
8146 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8147 return -EOPNOTSUPP;
8148
8149 if (!rdev->ops->stop_p2p_device)
8150 return -EOPNOTSUPP;
8151
Johannes Bergf9f47522013-03-19 15:04:07 +01008152 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008153
8154 return 0;
8155}
8156
Johannes Berg3713b4e2013-02-14 16:19:38 +01008157static int nl80211_get_protocol_features(struct sk_buff *skb,
8158 struct genl_info *info)
8159{
8160 void *hdr;
8161 struct sk_buff *msg;
8162
8163 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8164 if (!msg)
8165 return -ENOMEM;
8166
8167 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8168 NL80211_CMD_GET_PROTOCOL_FEATURES);
8169 if (!hdr)
8170 goto nla_put_failure;
8171
8172 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8173 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8174 goto nla_put_failure;
8175
8176 genlmsg_end(msg, hdr);
8177 return genlmsg_reply(msg, info);
8178
8179 nla_put_failure:
8180 kfree_skb(msg);
8181 return -ENOBUFS;
8182}
8183
Jouni Malinen355199e2013-02-27 17:14:27 +02008184static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8185{
8186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8187 struct cfg80211_update_ft_ies_params ft_params;
8188 struct net_device *dev = info->user_ptr[1];
8189
8190 if (!rdev->ops->update_ft_ies)
8191 return -EOPNOTSUPP;
8192
8193 if (!info->attrs[NL80211_ATTR_MDID] ||
8194 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8195 return -EINVAL;
8196
8197 memset(&ft_params, 0, sizeof(ft_params));
8198 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8199 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8200 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8201
8202 return rdev_update_ft_ies(rdev, dev, &ft_params);
8203}
8204
Arend van Spriel5de17982013-04-18 15:49:00 +02008205static int nl80211_crit_protocol_start(struct sk_buff *skb,
8206 struct genl_info *info)
8207{
8208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8209 struct wireless_dev *wdev = info->user_ptr[1];
8210 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8211 u16 duration;
8212 int ret;
8213
8214 if (!rdev->ops->crit_proto_start)
8215 return -EOPNOTSUPP;
8216
8217 if (WARN_ON(!rdev->ops->crit_proto_stop))
8218 return -EINVAL;
8219
8220 if (rdev->crit_proto_nlportid)
8221 return -EBUSY;
8222
8223 /* determine protocol if provided */
8224 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8225 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8226
8227 if (proto >= NUM_NL80211_CRIT_PROTO)
8228 return -EINVAL;
8229
8230 /* timeout must be provided */
8231 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8232 return -EINVAL;
8233
8234 duration =
8235 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8236
8237 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8238 return -ERANGE;
8239
8240 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8241 if (!ret)
8242 rdev->crit_proto_nlportid = info->snd_portid;
8243
8244 return ret;
8245}
8246
8247static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8248 struct genl_info *info)
8249{
8250 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8251 struct wireless_dev *wdev = info->user_ptr[1];
8252
8253 if (!rdev->ops->crit_proto_stop)
8254 return -EOPNOTSUPP;
8255
8256 if (rdev->crit_proto_nlportid) {
8257 rdev->crit_proto_nlportid = 0;
8258 rdev_crit_proto_stop(rdev, wdev);
8259 }
8260 return 0;
8261}
8262
Johannes Berg4c476992010-10-04 21:36:35 +02008263#define NL80211_FLAG_NEED_WIPHY 0x01
8264#define NL80211_FLAG_NEED_NETDEV 0x02
8265#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008266#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8267#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8268 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008269#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008270/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008271#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8272 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008273
8274static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8275 struct genl_info *info)
8276{
8277 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008278 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008279 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008280 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8281
8282 if (rtnl)
8283 rtnl_lock();
8284
8285 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008286 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008287 if (IS_ERR(rdev)) {
8288 if (rtnl)
8289 rtnl_unlock();
8290 return PTR_ERR(rdev);
8291 }
8292 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008293 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8294 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008295 ASSERT_RTNL();
8296
Johannes Berg89a54e42012-06-15 14:33:17 +02008297 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8298 info->attrs);
8299 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008300 if (rtnl)
8301 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008302 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008303 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008304
Johannes Berg89a54e42012-06-15 14:33:17 +02008305 dev = wdev->netdev;
8306 rdev = wiphy_to_dev(wdev->wiphy);
8307
Johannes Berg1bf614e2012-06-15 15:23:36 +02008308 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8309 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008310 if (rtnl)
8311 rtnl_unlock();
8312 return -EINVAL;
8313 }
8314
8315 info->user_ptr[1] = dev;
8316 } else {
8317 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008318 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008319
Johannes Berg1bf614e2012-06-15 15:23:36 +02008320 if (dev) {
8321 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8322 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008323 if (rtnl)
8324 rtnl_unlock();
8325 return -ENETDOWN;
8326 }
8327
8328 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008329 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8330 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008331 if (rtnl)
8332 rtnl_unlock();
8333 return -ENETDOWN;
8334 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008335 }
8336
Johannes Berg4c476992010-10-04 21:36:35 +02008337 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008338 }
8339
8340 return 0;
8341}
8342
8343static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8344 struct genl_info *info)
8345{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008346 if (info->user_ptr[1]) {
8347 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8348 struct wireless_dev *wdev = info->user_ptr[1];
8349
8350 if (wdev->netdev)
8351 dev_put(wdev->netdev);
8352 } else {
8353 dev_put(info->user_ptr[1]);
8354 }
8355 }
Johannes Berg4c476992010-10-04 21:36:35 +02008356 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8357 rtnl_unlock();
8358}
8359
Johannes Berg55682962007-09-20 13:09:35 -04008360static struct genl_ops nl80211_ops[] = {
8361 {
8362 .cmd = NL80211_CMD_GET_WIPHY,
8363 .doit = nl80211_get_wiphy,
8364 .dumpit = nl80211_dump_wiphy,
8365 .policy = nl80211_policy,
8366 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008367 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8368 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008369 },
8370 {
8371 .cmd = NL80211_CMD_SET_WIPHY,
8372 .doit = nl80211_set_wiphy,
8373 .policy = nl80211_policy,
8374 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008375 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008376 },
8377 {
8378 .cmd = NL80211_CMD_GET_INTERFACE,
8379 .doit = nl80211_get_interface,
8380 .dumpit = nl80211_dump_interface,
8381 .policy = nl80211_policy,
8382 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008383 .internal_flags = NL80211_FLAG_NEED_WDEV |
8384 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008385 },
8386 {
8387 .cmd = NL80211_CMD_SET_INTERFACE,
8388 .doit = nl80211_set_interface,
8389 .policy = nl80211_policy,
8390 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008391 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8392 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008393 },
8394 {
8395 .cmd = NL80211_CMD_NEW_INTERFACE,
8396 .doit = nl80211_new_interface,
8397 .policy = nl80211_policy,
8398 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008399 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8400 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008401 },
8402 {
8403 .cmd = NL80211_CMD_DEL_INTERFACE,
8404 .doit = nl80211_del_interface,
8405 .policy = nl80211_policy,
8406 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008407 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008408 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008409 },
Johannes Berg41ade002007-12-19 02:03:29 +01008410 {
8411 .cmd = NL80211_CMD_GET_KEY,
8412 .doit = nl80211_get_key,
8413 .policy = nl80211_policy,
8414 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008415 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008416 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008417 },
8418 {
8419 .cmd = NL80211_CMD_SET_KEY,
8420 .doit = nl80211_set_key,
8421 .policy = nl80211_policy,
8422 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008423 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008424 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008425 },
8426 {
8427 .cmd = NL80211_CMD_NEW_KEY,
8428 .doit = nl80211_new_key,
8429 .policy = nl80211_policy,
8430 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008432 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008433 },
8434 {
8435 .cmd = NL80211_CMD_DEL_KEY,
8436 .doit = nl80211_del_key,
8437 .policy = nl80211_policy,
8438 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008440 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008441 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008442 {
8443 .cmd = NL80211_CMD_SET_BEACON,
8444 .policy = nl80211_policy,
8445 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008446 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008448 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008449 },
8450 {
Johannes Berg88600202012-02-13 15:17:18 +01008451 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008452 .policy = nl80211_policy,
8453 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008454 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008456 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008457 },
8458 {
Johannes Berg88600202012-02-13 15:17:18 +01008459 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008460 .policy = nl80211_policy,
8461 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008462 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008464 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008465 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008466 {
8467 .cmd = NL80211_CMD_GET_STATION,
8468 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008469 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008470 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008471 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8472 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008473 },
8474 {
8475 .cmd = NL80211_CMD_SET_STATION,
8476 .doit = nl80211_set_station,
8477 .policy = nl80211_policy,
8478 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008480 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008481 },
8482 {
8483 .cmd = NL80211_CMD_NEW_STATION,
8484 .doit = nl80211_new_station,
8485 .policy = nl80211_policy,
8486 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008487 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008488 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008489 },
8490 {
8491 .cmd = NL80211_CMD_DEL_STATION,
8492 .doit = nl80211_del_station,
8493 .policy = nl80211_policy,
8494 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008495 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008496 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008497 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008498 {
8499 .cmd = NL80211_CMD_GET_MPATH,
8500 .doit = nl80211_get_mpath,
8501 .dumpit = nl80211_dump_mpath,
8502 .policy = nl80211_policy,
8503 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008505 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008506 },
8507 {
8508 .cmd = NL80211_CMD_SET_MPATH,
8509 .doit = nl80211_set_mpath,
8510 .policy = nl80211_policy,
8511 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008513 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008514 },
8515 {
8516 .cmd = NL80211_CMD_NEW_MPATH,
8517 .doit = nl80211_new_mpath,
8518 .policy = nl80211_policy,
8519 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008521 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008522 },
8523 {
8524 .cmd = NL80211_CMD_DEL_MPATH,
8525 .doit = nl80211_del_mpath,
8526 .policy = nl80211_policy,
8527 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008528 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008529 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008530 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008531 {
8532 .cmd = NL80211_CMD_SET_BSS,
8533 .doit = nl80211_set_bss,
8534 .policy = nl80211_policy,
8535 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008536 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008537 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008538 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008539 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008540 .cmd = NL80211_CMD_GET_REG,
8541 .doit = nl80211_get_reg,
8542 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008543 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008544 /* can be retrieved by unprivileged users */
8545 },
8546 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008547 .cmd = NL80211_CMD_SET_REG,
8548 .doit = nl80211_set_reg,
8549 .policy = nl80211_policy,
8550 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008551 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008552 },
8553 {
8554 .cmd = NL80211_CMD_REQ_SET_REG,
8555 .doit = nl80211_req_set_reg,
8556 .policy = nl80211_policy,
8557 .flags = GENL_ADMIN_PERM,
8558 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008559 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008560 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8561 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008562 .policy = nl80211_policy,
8563 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008564 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008565 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008566 },
8567 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008568 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8569 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008570 .policy = nl80211_policy,
8571 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008572 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008573 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008574 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008575 {
Johannes Berg2a519312009-02-10 21:25:55 +01008576 .cmd = NL80211_CMD_TRIGGER_SCAN,
8577 .doit = nl80211_trigger_scan,
8578 .policy = nl80211_policy,
8579 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008580 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008581 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008582 },
8583 {
8584 .cmd = NL80211_CMD_GET_SCAN,
8585 .policy = nl80211_policy,
8586 .dumpit = nl80211_dump_scan,
8587 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008588 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008589 .cmd = NL80211_CMD_START_SCHED_SCAN,
8590 .doit = nl80211_start_sched_scan,
8591 .policy = nl80211_policy,
8592 .flags = GENL_ADMIN_PERM,
8593 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8594 NL80211_FLAG_NEED_RTNL,
8595 },
8596 {
8597 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8598 .doit = nl80211_stop_sched_scan,
8599 .policy = nl80211_policy,
8600 .flags = GENL_ADMIN_PERM,
8601 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8602 NL80211_FLAG_NEED_RTNL,
8603 },
8604 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008605 .cmd = NL80211_CMD_AUTHENTICATE,
8606 .doit = nl80211_authenticate,
8607 .policy = nl80211_policy,
8608 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008609 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008610 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008611 },
8612 {
8613 .cmd = NL80211_CMD_ASSOCIATE,
8614 .doit = nl80211_associate,
8615 .policy = nl80211_policy,
8616 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008617 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008618 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008619 },
8620 {
8621 .cmd = NL80211_CMD_DEAUTHENTICATE,
8622 .doit = nl80211_deauthenticate,
8623 .policy = nl80211_policy,
8624 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008625 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008626 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008627 },
8628 {
8629 .cmd = NL80211_CMD_DISASSOCIATE,
8630 .doit = nl80211_disassociate,
8631 .policy = nl80211_policy,
8632 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008633 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008634 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008635 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008636 {
8637 .cmd = NL80211_CMD_JOIN_IBSS,
8638 .doit = nl80211_join_ibss,
8639 .policy = nl80211_policy,
8640 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008641 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008642 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008643 },
8644 {
8645 .cmd = NL80211_CMD_LEAVE_IBSS,
8646 .doit = nl80211_leave_ibss,
8647 .policy = nl80211_policy,
8648 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008649 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008650 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008651 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008652#ifdef CONFIG_NL80211_TESTMODE
8653 {
8654 .cmd = NL80211_CMD_TESTMODE,
8655 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008656 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008657 .policy = nl80211_policy,
8658 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008659 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8660 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008661 },
8662#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008663 {
8664 .cmd = NL80211_CMD_CONNECT,
8665 .doit = nl80211_connect,
8666 .policy = nl80211_policy,
8667 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008669 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008670 },
8671 {
8672 .cmd = NL80211_CMD_DISCONNECT,
8673 .doit = nl80211_disconnect,
8674 .policy = nl80211_policy,
8675 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008677 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008678 },
Johannes Berg463d0182009-07-14 00:33:35 +02008679 {
8680 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8681 .doit = nl80211_wiphy_netns,
8682 .policy = nl80211_policy,
8683 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008684 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8685 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008686 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008687 {
8688 .cmd = NL80211_CMD_GET_SURVEY,
8689 .policy = nl80211_policy,
8690 .dumpit = nl80211_dump_survey,
8691 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008692 {
8693 .cmd = NL80211_CMD_SET_PMKSA,
8694 .doit = nl80211_setdel_pmksa,
8695 .policy = nl80211_policy,
8696 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008697 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008698 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008699 },
8700 {
8701 .cmd = NL80211_CMD_DEL_PMKSA,
8702 .doit = nl80211_setdel_pmksa,
8703 .policy = nl80211_policy,
8704 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008705 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008706 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008707 },
8708 {
8709 .cmd = NL80211_CMD_FLUSH_PMKSA,
8710 .doit = nl80211_flush_pmksa,
8711 .policy = nl80211_policy,
8712 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008714 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008715 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008716 {
8717 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8718 .doit = nl80211_remain_on_channel,
8719 .policy = nl80211_policy,
8720 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008721 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008722 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008723 },
8724 {
8725 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8726 .doit = nl80211_cancel_remain_on_channel,
8727 .policy = nl80211_policy,
8728 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008729 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008730 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008731 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008732 {
8733 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8734 .doit = nl80211_set_tx_bitrate_mask,
8735 .policy = nl80211_policy,
8736 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008737 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8738 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008739 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008740 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008741 .cmd = NL80211_CMD_REGISTER_FRAME,
8742 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008743 .policy = nl80211_policy,
8744 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008745 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008746 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008747 },
8748 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008749 .cmd = NL80211_CMD_FRAME,
8750 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008751 .policy = nl80211_policy,
8752 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008753 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008754 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008755 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008756 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008757 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8758 .doit = nl80211_tx_mgmt_cancel_wait,
8759 .policy = nl80211_policy,
8760 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008761 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008762 NL80211_FLAG_NEED_RTNL,
8763 },
8764 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008765 .cmd = NL80211_CMD_SET_POWER_SAVE,
8766 .doit = nl80211_set_power_save,
8767 .policy = nl80211_policy,
8768 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008769 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8770 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008771 },
8772 {
8773 .cmd = NL80211_CMD_GET_POWER_SAVE,
8774 .doit = nl80211_get_power_save,
8775 .policy = nl80211_policy,
8776 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008777 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8778 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008779 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008780 {
8781 .cmd = NL80211_CMD_SET_CQM,
8782 .doit = nl80211_set_cqm,
8783 .policy = nl80211_policy,
8784 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008785 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8786 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008787 },
Johannes Bergf444de02010-05-05 15:25:02 +02008788 {
8789 .cmd = NL80211_CMD_SET_CHANNEL,
8790 .doit = nl80211_set_channel,
8791 .policy = nl80211_policy,
8792 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008793 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8794 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008795 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008796 {
8797 .cmd = NL80211_CMD_SET_WDS_PEER,
8798 .doit = nl80211_set_wds_peer,
8799 .policy = nl80211_policy,
8800 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008801 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8802 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008803 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008804 {
8805 .cmd = NL80211_CMD_JOIN_MESH,
8806 .doit = nl80211_join_mesh,
8807 .policy = nl80211_policy,
8808 .flags = GENL_ADMIN_PERM,
8809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8810 NL80211_FLAG_NEED_RTNL,
8811 },
8812 {
8813 .cmd = NL80211_CMD_LEAVE_MESH,
8814 .doit = nl80211_leave_mesh,
8815 .policy = nl80211_policy,
8816 .flags = GENL_ADMIN_PERM,
8817 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8818 NL80211_FLAG_NEED_RTNL,
8819 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008820#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008821 {
8822 .cmd = NL80211_CMD_GET_WOWLAN,
8823 .doit = nl80211_get_wowlan,
8824 .policy = nl80211_policy,
8825 /* can be retrieved by unprivileged users */
8826 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8827 NL80211_FLAG_NEED_RTNL,
8828 },
8829 {
8830 .cmd = NL80211_CMD_SET_WOWLAN,
8831 .doit = nl80211_set_wowlan,
8832 .policy = nl80211_policy,
8833 .flags = GENL_ADMIN_PERM,
8834 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8835 NL80211_FLAG_NEED_RTNL,
8836 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008837#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008838 {
8839 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8840 .doit = nl80211_set_rekey_data,
8841 .policy = nl80211_policy,
8842 .flags = GENL_ADMIN_PERM,
8843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8844 NL80211_FLAG_NEED_RTNL,
8845 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008846 {
8847 .cmd = NL80211_CMD_TDLS_MGMT,
8848 .doit = nl80211_tdls_mgmt,
8849 .policy = nl80211_policy,
8850 .flags = GENL_ADMIN_PERM,
8851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8852 NL80211_FLAG_NEED_RTNL,
8853 },
8854 {
8855 .cmd = NL80211_CMD_TDLS_OPER,
8856 .doit = nl80211_tdls_oper,
8857 .policy = nl80211_policy,
8858 .flags = GENL_ADMIN_PERM,
8859 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8860 NL80211_FLAG_NEED_RTNL,
8861 },
Johannes Berg28946da2011-11-04 11:18:12 +01008862 {
8863 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8864 .doit = nl80211_register_unexpected_frame,
8865 .policy = nl80211_policy,
8866 .flags = GENL_ADMIN_PERM,
8867 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8868 NL80211_FLAG_NEED_RTNL,
8869 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008870 {
8871 .cmd = NL80211_CMD_PROBE_CLIENT,
8872 .doit = nl80211_probe_client,
8873 .policy = nl80211_policy,
8874 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008875 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008876 NL80211_FLAG_NEED_RTNL,
8877 },
Johannes Berg5e7602302011-11-04 11:18:17 +01008878 {
8879 .cmd = NL80211_CMD_REGISTER_BEACONS,
8880 .doit = nl80211_register_beacons,
8881 .policy = nl80211_policy,
8882 .flags = GENL_ADMIN_PERM,
8883 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8884 NL80211_FLAG_NEED_RTNL,
8885 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008886 {
8887 .cmd = NL80211_CMD_SET_NOACK_MAP,
8888 .doit = nl80211_set_noack_map,
8889 .policy = nl80211_policy,
8890 .flags = GENL_ADMIN_PERM,
8891 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8892 NL80211_FLAG_NEED_RTNL,
8893 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008894 {
8895 .cmd = NL80211_CMD_START_P2P_DEVICE,
8896 .doit = nl80211_start_p2p_device,
8897 .policy = nl80211_policy,
8898 .flags = GENL_ADMIN_PERM,
8899 .internal_flags = NL80211_FLAG_NEED_WDEV |
8900 NL80211_FLAG_NEED_RTNL,
8901 },
8902 {
8903 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8904 .doit = nl80211_stop_p2p_device,
8905 .policy = nl80211_policy,
8906 .flags = GENL_ADMIN_PERM,
8907 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8908 NL80211_FLAG_NEED_RTNL,
8909 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008910 {
8911 .cmd = NL80211_CMD_SET_MCAST_RATE,
8912 .doit = nl80211_set_mcast_rate,
8913 .policy = nl80211_policy,
8914 .flags = GENL_ADMIN_PERM,
8915 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8916 NL80211_FLAG_NEED_RTNL,
8917 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308918 {
8919 .cmd = NL80211_CMD_SET_MAC_ACL,
8920 .doit = nl80211_set_mac_acl,
8921 .policy = nl80211_policy,
8922 .flags = GENL_ADMIN_PERM,
8923 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8924 NL80211_FLAG_NEED_RTNL,
8925 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01008926 {
8927 .cmd = NL80211_CMD_RADAR_DETECT,
8928 .doit = nl80211_start_radar_detection,
8929 .policy = nl80211_policy,
8930 .flags = GENL_ADMIN_PERM,
8931 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8932 NL80211_FLAG_NEED_RTNL,
8933 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01008934 {
8935 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
8936 .doit = nl80211_get_protocol_features,
8937 .policy = nl80211_policy,
8938 },
Jouni Malinen355199e2013-02-27 17:14:27 +02008939 {
8940 .cmd = NL80211_CMD_UPDATE_FT_IES,
8941 .doit = nl80211_update_ft_ies,
8942 .policy = nl80211_policy,
8943 .flags = GENL_ADMIN_PERM,
8944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8945 NL80211_FLAG_NEED_RTNL,
8946 },
Arend van Spriel5de17982013-04-18 15:49:00 +02008947 {
8948 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
8949 .doit = nl80211_crit_protocol_start,
8950 .policy = nl80211_policy,
8951 .flags = GENL_ADMIN_PERM,
8952 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8953 NL80211_FLAG_NEED_RTNL,
8954 },
8955 {
8956 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
8957 .doit = nl80211_crit_protocol_stop,
8958 .policy = nl80211_policy,
8959 .flags = GENL_ADMIN_PERM,
8960 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8961 NL80211_FLAG_NEED_RTNL,
8962 }
Johannes Berg55682962007-09-20 13:09:35 -04008963};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008964
Jouni Malinen6039f6d2009-03-19 13:39:21 +02008965static struct genl_multicast_group nl80211_mlme_mcgrp = {
8966 .name = "mlme",
8967};
Johannes Berg55682962007-09-20 13:09:35 -04008968
8969/* multicast groups */
8970static struct genl_multicast_group nl80211_config_mcgrp = {
8971 .name = "config",
8972};
Johannes Berg2a519312009-02-10 21:25:55 +01008973static struct genl_multicast_group nl80211_scan_mcgrp = {
8974 .name = "scan",
8975};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04008976static struct genl_multicast_group nl80211_regulatory_mcgrp = {
8977 .name = "regulatory",
8978};
Johannes Berg55682962007-09-20 13:09:35 -04008979
8980/* notification functions */
8981
8982void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
8983{
8984 struct sk_buff *msg;
8985
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07008986 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008987 if (!msg)
8988 return;
8989
Johannes Berg3713b4e2013-02-14 16:19:38 +01008990 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0,
8991 false, NULL, NULL, NULL) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04008992 nlmsg_free(msg);
8993 return;
8994 }
8995
Johannes Berg463d0182009-07-14 00:33:35 +02008996 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
8997 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04008998}
8999
Johannes Berg362a4152009-05-24 16:43:15 +02009000static int nl80211_add_scan_req(struct sk_buff *msg,
9001 struct cfg80211_registered_device *rdev)
9002{
9003 struct cfg80211_scan_request *req = rdev->scan_req;
9004 struct nlattr *nest;
9005 int i;
9006
9007 if (WARN_ON(!req))
9008 return 0;
9009
9010 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9011 if (!nest)
9012 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009013 for (i = 0; i < req->n_ssids; i++) {
9014 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9015 goto nla_put_failure;
9016 }
Johannes Berg362a4152009-05-24 16:43:15 +02009017 nla_nest_end(msg, nest);
9018
9019 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9020 if (!nest)
9021 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009022 for (i = 0; i < req->n_channels; i++) {
9023 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9024 goto nla_put_failure;
9025 }
Johannes Berg362a4152009-05-24 16:43:15 +02009026 nla_nest_end(msg, nest);
9027
David S. Miller9360ffd2012-03-29 04:41:26 -04009028 if (req->ie &&
9029 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9030 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009031
Sam Lefflered4737712012-10-11 21:03:31 -07009032 if (req->flags)
9033 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9034
Johannes Berg362a4152009-05-24 16:43:15 +02009035 return 0;
9036 nla_put_failure:
9037 return -ENOBUFS;
9038}
9039
Johannes Berga538e2d2009-06-16 19:56:42 +02009040static int nl80211_send_scan_msg(struct sk_buff *msg,
9041 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009042 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009043 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009044 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009045{
9046 void *hdr;
9047
Eric W. Biederman15e47302012-09-07 20:12:54 +00009048 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009049 if (!hdr)
9050 return -1;
9051
David S. Miller9360ffd2012-03-29 04:41:26 -04009052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009053 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9054 wdev->netdev->ifindex)) ||
9055 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009056 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009057
Johannes Berg362a4152009-05-24 16:43:15 +02009058 /* ignore errors and send incomplete event anyway */
9059 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009060
9061 return genlmsg_end(msg, hdr);
9062
9063 nla_put_failure:
9064 genlmsg_cancel(msg, hdr);
9065 return -EMSGSIZE;
9066}
9067
Luciano Coelho807f8a82011-05-11 17:09:35 +03009068static int
9069nl80211_send_sched_scan_msg(struct sk_buff *msg,
9070 struct cfg80211_registered_device *rdev,
9071 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009072 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009073{
9074 void *hdr;
9075
Eric W. Biederman15e47302012-09-07 20:12:54 +00009076 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009077 if (!hdr)
9078 return -1;
9079
David S. Miller9360ffd2012-03-29 04:41:26 -04009080 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9081 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9082 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009083
9084 return genlmsg_end(msg, hdr);
9085
9086 nla_put_failure:
9087 genlmsg_cancel(msg, hdr);
9088 return -EMSGSIZE;
9089}
9090
Johannes Berga538e2d2009-06-16 19:56:42 +02009091void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009092 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009093{
9094 struct sk_buff *msg;
9095
Thomas Graf58050fc2012-06-28 03:57:45 +00009096 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009097 if (!msg)
9098 return;
9099
Johannes Bergfd014282012-06-18 19:17:03 +02009100 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009101 NL80211_CMD_TRIGGER_SCAN) < 0) {
9102 nlmsg_free(msg);
9103 return;
9104 }
9105
Johannes Berg463d0182009-07-14 00:33:35 +02009106 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9107 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009108}
9109
Johannes Berg2a519312009-02-10 21:25:55 +01009110void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009111 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009112{
9113 struct sk_buff *msg;
9114
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009116 if (!msg)
9117 return;
9118
Johannes Bergfd014282012-06-18 19:17:03 +02009119 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009120 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009121 nlmsg_free(msg);
9122 return;
9123 }
9124
Johannes Berg463d0182009-07-14 00:33:35 +02009125 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9126 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009127}
9128
9129void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009130 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009131{
9132 struct sk_buff *msg;
9133
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009135 if (!msg)
9136 return;
9137
Johannes Bergfd014282012-06-18 19:17:03 +02009138 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009139 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009140 nlmsg_free(msg);
9141 return;
9142 }
9143
Johannes Berg463d0182009-07-14 00:33:35 +02009144 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9145 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009146}
9147
Luciano Coelho807f8a82011-05-11 17:09:35 +03009148void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9149 struct net_device *netdev)
9150{
9151 struct sk_buff *msg;
9152
9153 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9154 if (!msg)
9155 return;
9156
9157 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9158 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9159 nlmsg_free(msg);
9160 return;
9161 }
9162
9163 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9164 nl80211_scan_mcgrp.id, GFP_KERNEL);
9165}
9166
9167void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9168 struct net_device *netdev, u32 cmd)
9169{
9170 struct sk_buff *msg;
9171
Thomas Graf58050fc2012-06-28 03:57:45 +00009172 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009173 if (!msg)
9174 return;
9175
9176 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9177 nlmsg_free(msg);
9178 return;
9179 }
9180
9181 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9182 nl80211_scan_mcgrp.id, GFP_KERNEL);
9183}
9184
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009185/*
9186 * This can happen on global regulatory changes or device specific settings
9187 * based on custom world regulatory domains.
9188 */
9189void nl80211_send_reg_change_event(struct regulatory_request *request)
9190{
9191 struct sk_buff *msg;
9192 void *hdr;
9193
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009194 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009195 if (!msg)
9196 return;
9197
9198 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9199 if (!hdr) {
9200 nlmsg_free(msg);
9201 return;
9202 }
9203
9204 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009205 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9206 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009207
David S. Miller9360ffd2012-03-29 04:41:26 -04009208 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9209 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9210 NL80211_REGDOM_TYPE_WORLD))
9211 goto nla_put_failure;
9212 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9213 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9214 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9215 goto nla_put_failure;
9216 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9217 request->intersect) {
9218 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9219 NL80211_REGDOM_TYPE_INTERSECTION))
9220 goto nla_put_failure;
9221 } else {
9222 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9223 NL80211_REGDOM_TYPE_COUNTRY) ||
9224 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9225 request->alpha2))
9226 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009227 }
9228
Johannes Bergf4173762012-12-03 18:23:37 +01009229 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009230 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9231 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009232
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009233 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009234
Johannes Bergbc43b282009-07-25 10:54:13 +02009235 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009236 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009237 GFP_ATOMIC);
9238 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009239
9240 return;
9241
9242nla_put_failure:
9243 genlmsg_cancel(msg, hdr);
9244 nlmsg_free(msg);
9245}
9246
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009247static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9248 struct net_device *netdev,
9249 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009250 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009251{
9252 struct sk_buff *msg;
9253 void *hdr;
9254
Johannes Berge6d6e342009-07-01 21:26:47 +02009255 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009256 if (!msg)
9257 return;
9258
9259 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9260 if (!hdr) {
9261 nlmsg_free(msg);
9262 return;
9263 }
9264
David S. Miller9360ffd2012-03-29 04:41:26 -04009265 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9266 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9267 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9268 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009269
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009270 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009271
Johannes Berg463d0182009-07-14 00:33:35 +02009272 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9273 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009274 return;
9275
9276 nla_put_failure:
9277 genlmsg_cancel(msg, hdr);
9278 nlmsg_free(msg);
9279}
9280
9281void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009282 struct net_device *netdev, const u8 *buf,
9283 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009284{
9285 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009286 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009287}
9288
9289void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9290 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009291 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009292{
Johannes Berge6d6e342009-07-01 21:26:47 +02009293 nl80211_send_mlme_event(rdev, netdev, buf, len,
9294 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009295}
9296
Jouni Malinen53b46b82009-03-27 20:53:56 +02009297void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009298 struct net_device *netdev, const u8 *buf,
9299 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009300{
9301 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009302 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009303}
9304
Jouni Malinen53b46b82009-03-27 20:53:56 +02009305void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9306 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009307 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009308{
9309 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009310 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009311}
9312
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009313void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9314 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009315{
Johannes Berg947add32013-02-22 22:05:20 +01009316 struct wireless_dev *wdev = dev->ieee80211_ptr;
9317 struct wiphy *wiphy = wdev->wiphy;
9318 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009319 const struct ieee80211_mgmt *mgmt = (void *)buf;
9320 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009321
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009322 if (WARN_ON(len < 2))
9323 return;
9324
9325 if (ieee80211_is_deauth(mgmt->frame_control))
9326 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9327 else
9328 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9329
9330 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9331 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009332}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009333EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009334
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009335static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9336 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009337 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009338{
9339 struct sk_buff *msg;
9340 void *hdr;
9341
Johannes Berge6d6e342009-07-01 21:26:47 +02009342 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009343 if (!msg)
9344 return;
9345
9346 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9347 if (!hdr) {
9348 nlmsg_free(msg);
9349 return;
9350 }
9351
David S. Miller9360ffd2012-03-29 04:41:26 -04009352 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9353 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9354 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9355 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9356 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009357
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009358 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009359
Johannes Berg463d0182009-07-14 00:33:35 +02009360 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9361 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009362 return;
9363
9364 nla_put_failure:
9365 genlmsg_cancel(msg, hdr);
9366 nlmsg_free(msg);
9367}
9368
9369void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009370 struct net_device *netdev, const u8 *addr,
9371 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009372{
9373 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009374 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009375}
9376
9377void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009378 struct net_device *netdev, const u8 *addr,
9379 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009380{
Johannes Berge6d6e342009-07-01 21:26:47 +02009381 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9382 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009383}
9384
Samuel Ortizb23aa672009-07-01 21:26:54 +02009385void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9386 struct net_device *netdev, const u8 *bssid,
9387 const u8 *req_ie, size_t req_ie_len,
9388 const u8 *resp_ie, size_t resp_ie_len,
9389 u16 status, gfp_t gfp)
9390{
9391 struct sk_buff *msg;
9392 void *hdr;
9393
Thomas Graf58050fc2012-06-28 03:57:45 +00009394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009395 if (!msg)
9396 return;
9397
9398 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9399 if (!hdr) {
9400 nlmsg_free(msg);
9401 return;
9402 }
9403
David S. Miller9360ffd2012-03-29 04:41:26 -04009404 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9405 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9406 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9407 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9408 (req_ie &&
9409 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9410 (resp_ie &&
9411 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9412 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009413
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009414 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009415
Johannes Berg463d0182009-07-14 00:33:35 +02009416 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9417 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009418 return;
9419
9420 nla_put_failure:
9421 genlmsg_cancel(msg, hdr);
9422 nlmsg_free(msg);
9423
9424}
9425
9426void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9427 struct net_device *netdev, const u8 *bssid,
9428 const u8 *req_ie, size_t req_ie_len,
9429 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9430{
9431 struct sk_buff *msg;
9432 void *hdr;
9433
Thomas Graf58050fc2012-06-28 03:57:45 +00009434 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009435 if (!msg)
9436 return;
9437
9438 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9439 if (!hdr) {
9440 nlmsg_free(msg);
9441 return;
9442 }
9443
David S. Miller9360ffd2012-03-29 04:41:26 -04009444 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9445 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9446 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
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_disconnected(struct cfg80211_registered_device *rdev,
9466 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009467 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009468{
9469 struct sk_buff *msg;
9470 void *hdr;
9471
Thomas Graf58050fc2012-06-28 03:57:45 +00009472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009473 if (!msg)
9474 return;
9475
9476 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9477 if (!hdr) {
9478 nlmsg_free(msg);
9479 return;
9480 }
9481
David S. Miller9360ffd2012-03-29 04:41:26 -04009482 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9483 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9484 (from_ap && reason &&
9485 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9486 (from_ap &&
9487 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9488 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9489 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009490
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009491 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009492
Johannes Berg463d0182009-07-14 00:33:35 +02009493 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9494 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009495 return;
9496
9497 nla_put_failure:
9498 genlmsg_cancel(msg, hdr);
9499 nlmsg_free(msg);
9500
9501}
9502
Johannes Berg04a773a2009-04-19 21:24:32 +02009503void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9504 struct net_device *netdev, const u8 *bssid,
9505 gfp_t gfp)
9506{
9507 struct sk_buff *msg;
9508 void *hdr;
9509
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009510 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009511 if (!msg)
9512 return;
9513
9514 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9515 if (!hdr) {
9516 nlmsg_free(msg);
9517 return;
9518 }
9519
David S. Miller9360ffd2012-03-29 04:41:26 -04009520 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9521 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9522 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9523 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009524
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009525 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009526
Johannes Berg463d0182009-07-14 00:33:35 +02009527 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9528 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009529 return;
9530
9531 nla_put_failure:
9532 genlmsg_cancel(msg, hdr);
9533 nlmsg_free(msg);
9534}
9535
Johannes Berg947add32013-02-22 22:05:20 +01009536void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9537 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009538{
Johannes Berg947add32013-02-22 22:05:20 +01009539 struct wireless_dev *wdev = dev->ieee80211_ptr;
9540 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009541 struct sk_buff *msg;
9542 void *hdr;
9543
Johannes Berg947add32013-02-22 22:05:20 +01009544 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9545 return;
9546
9547 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9548
Javier Cardonac93b5e72011-04-07 15:08:34 -07009549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9550 if (!msg)
9551 return;
9552
9553 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
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) ||
Johannes Berg947add32013-02-22 22:05:20 +01009560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9561 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009562 (ie_len && ie &&
9563 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9564 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009565
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009566 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009567
9568 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9569 nl80211_mlme_mcgrp.id, gfp);
9570 return;
9571
9572 nla_put_failure:
9573 genlmsg_cancel(msg, hdr);
9574 nlmsg_free(msg);
9575}
Johannes Berg947add32013-02-22 22:05:20 +01009576EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009577
Jouni Malinena3b8b052009-03-27 21:59:49 +02009578void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9579 struct net_device *netdev, const u8 *addr,
9580 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009581 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009582{
9583 struct sk_buff *msg;
9584 void *hdr;
9585
Johannes Berge6d6e342009-07-01 21:26:47 +02009586 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009587 if (!msg)
9588 return;
9589
9590 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9591 if (!hdr) {
9592 nlmsg_free(msg);
9593 return;
9594 }
9595
David S. Miller9360ffd2012-03-29 04:41:26 -04009596 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9597 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9598 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9599 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9600 (key_id != -1 &&
9601 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9602 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9603 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009604
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009605 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009606
Johannes Berg463d0182009-07-14 00:33:35 +02009607 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9608 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009609 return;
9610
9611 nla_put_failure:
9612 genlmsg_cancel(msg, hdr);
9613 nlmsg_free(msg);
9614}
9615
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009616void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9617 struct ieee80211_channel *channel_before,
9618 struct ieee80211_channel *channel_after)
9619{
9620 struct sk_buff *msg;
9621 void *hdr;
9622 struct nlattr *nl_freq;
9623
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009624 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009625 if (!msg)
9626 return;
9627
9628 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9629 if (!hdr) {
9630 nlmsg_free(msg);
9631 return;
9632 }
9633
9634 /*
9635 * Since we are applying the beacon hint to a wiphy we know its
9636 * wiphy_idx is valid
9637 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009638 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9639 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009640
9641 /* Before */
9642 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9643 if (!nl_freq)
9644 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009645 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009646 goto nla_put_failure;
9647 nla_nest_end(msg, nl_freq);
9648
9649 /* After */
9650 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9651 if (!nl_freq)
9652 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009653 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009654 goto nla_put_failure;
9655 nla_nest_end(msg, nl_freq);
9656
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009657 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009658
Johannes Berg463d0182009-07-14 00:33:35 +02009659 rcu_read_lock();
9660 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9661 GFP_ATOMIC);
9662 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009663
9664 return;
9665
9666nla_put_failure:
9667 genlmsg_cancel(msg, hdr);
9668 nlmsg_free(msg);
9669}
9670
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009671static void nl80211_send_remain_on_chan_event(
9672 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009673 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009674 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009675 unsigned int duration, gfp_t gfp)
9676{
9677 struct sk_buff *msg;
9678 void *hdr;
9679
9680 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9681 if (!msg)
9682 return;
9683
9684 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9685 if (!hdr) {
9686 nlmsg_free(msg);
9687 return;
9688 }
9689
David S. Miller9360ffd2012-03-29 04:41:26 -04009690 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009691 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9692 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009693 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009694 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009695 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9696 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009697 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9698 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009699
David S. Miller9360ffd2012-03-29 04:41:26 -04009700 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9701 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9702 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009703
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009704 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009705
9706 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9707 nl80211_mlme_mcgrp.id, gfp);
9708 return;
9709
9710 nla_put_failure:
9711 genlmsg_cancel(msg, hdr);
9712 nlmsg_free(msg);
9713}
9714
Johannes Berg947add32013-02-22 22:05:20 +01009715void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9716 struct ieee80211_channel *chan,
9717 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009718{
Johannes Berg947add32013-02-22 22:05:20 +01009719 struct wiphy *wiphy = wdev->wiphy;
9720 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9721
9722 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009723 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009724 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009725 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009726}
Johannes Berg947add32013-02-22 22:05:20 +01009727EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009728
Johannes Berg947add32013-02-22 22:05:20 +01009729void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9730 struct ieee80211_channel *chan,
9731 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009732{
Johannes Berg947add32013-02-22 22:05:20 +01009733 struct wiphy *wiphy = wdev->wiphy;
9734 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9735
9736 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009737 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009738 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009739}
Johannes Berg947add32013-02-22 22:05:20 +01009740EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009741
Johannes Berg947add32013-02-22 22:05:20 +01009742void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9743 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009744{
Johannes Berg947add32013-02-22 22:05:20 +01009745 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9746 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009747 struct sk_buff *msg;
9748
Johannes Berg947add32013-02-22 22:05:20 +01009749 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9750
Thomas Graf58050fc2012-06-28 03:57:45 +00009751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009752 if (!msg)
9753 return;
9754
John W. Linville66266b32012-03-15 13:25:41 -04009755 if (nl80211_send_station(msg, 0, 0, 0,
9756 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009757 nlmsg_free(msg);
9758 return;
9759 }
9760
9761 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9762 nl80211_mlme_mcgrp.id, gfp);
9763}
Johannes Berg947add32013-02-22 22:05:20 +01009764EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009765
Johannes Berg947add32013-02-22 22:05:20 +01009766void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009767{
Johannes Berg947add32013-02-22 22:05:20 +01009768 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9769 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009770 struct sk_buff *msg;
9771 void *hdr;
9772
Johannes Berg947add32013-02-22 22:05:20 +01009773 trace_cfg80211_del_sta(dev, mac_addr);
9774
Thomas Graf58050fc2012-06-28 03:57:45 +00009775 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009776 if (!msg)
9777 return;
9778
9779 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9780 if (!hdr) {
9781 nlmsg_free(msg);
9782 return;
9783 }
9784
David S. Miller9360ffd2012-03-29 04:41:26 -04009785 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9786 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9787 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009788
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009789 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009790
9791 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9792 nl80211_mlme_mcgrp.id, gfp);
9793 return;
9794
9795 nla_put_failure:
9796 genlmsg_cancel(msg, hdr);
9797 nlmsg_free(msg);
9798}
Johannes Berg947add32013-02-22 22:05:20 +01009799EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009800
Johannes Berg947add32013-02-22 22:05:20 +01009801void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9802 enum nl80211_connect_failed_reason reason,
9803 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309804{
Johannes Berg947add32013-02-22 22:05:20 +01009805 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9806 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309807 struct sk_buff *msg;
9808 void *hdr;
9809
9810 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9811 if (!msg)
9812 return;
9813
9814 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9815 if (!hdr) {
9816 nlmsg_free(msg);
9817 return;
9818 }
9819
9820 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9821 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9822 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9823 goto nla_put_failure;
9824
9825 genlmsg_end(msg, hdr);
9826
9827 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9828 nl80211_mlme_mcgrp.id, gfp);
9829 return;
9830
9831 nla_put_failure:
9832 genlmsg_cancel(msg, hdr);
9833 nlmsg_free(msg);
9834}
Johannes Berg947add32013-02-22 22:05:20 +01009835EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309836
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009837static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9838 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009839{
9840 struct wireless_dev *wdev = dev->ieee80211_ptr;
9841 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9842 struct sk_buff *msg;
9843 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009844 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009845
Eric W. Biederman15e47302012-09-07 20:12:54 +00009846 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009847 return false;
9848
9849 msg = nlmsg_new(100, gfp);
9850 if (!msg)
9851 return true;
9852
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009853 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009854 if (!hdr) {
9855 nlmsg_free(msg);
9856 return true;
9857 }
9858
David S. Miller9360ffd2012-03-29 04:41:26 -04009859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9860 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9861 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9862 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009863
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009864 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009865 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009866 return true;
9867
9868 nla_put_failure:
9869 genlmsg_cancel(msg, hdr);
9870 nlmsg_free(msg);
9871 return true;
9872}
9873
Johannes Berg947add32013-02-22 22:05:20 +01009874bool cfg80211_rx_spurious_frame(struct net_device *dev,
9875 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009876{
Johannes Berg947add32013-02-22 22:05:20 +01009877 struct wireless_dev *wdev = dev->ieee80211_ptr;
9878 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009879
Johannes Berg947add32013-02-22 22:05:20 +01009880 trace_cfg80211_rx_spurious_frame(dev, addr);
9881
9882 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9883 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9884 trace_cfg80211_return_bool(false);
9885 return false;
9886 }
9887 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9888 addr, gfp);
9889 trace_cfg80211_return_bool(ret);
9890 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009891}
Johannes Berg947add32013-02-22 22:05:20 +01009892EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9893
9894bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9895 const u8 *addr, gfp_t gfp)
9896{
9897 struct wireless_dev *wdev = dev->ieee80211_ptr;
9898 bool ret;
9899
9900 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9901
9902 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9903 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9904 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9905 trace_cfg80211_return_bool(false);
9906 return false;
9907 }
9908 ret = __nl80211_unexpected_frame(dev,
9909 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9910 addr, gfp);
9911 trace_cfg80211_return_bool(ret);
9912 return ret;
9913}
9914EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009915
Johannes Berg2e161f72010-08-12 15:38:38 +02009916int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009917 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009918 int freq, int sig_dbm,
9919 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009920{
Johannes Berg71bbc992012-06-15 15:30:18 +02009921 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +02009922 struct sk_buff *msg;
9923 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +02009924
9925 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9926 if (!msg)
9927 return -ENOMEM;
9928
Johannes Berg2e161f72010-08-12 15:38:38 +02009929 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02009930 if (!hdr) {
9931 nlmsg_free(msg);
9932 return -ENOMEM;
9933 }
9934
David S. Miller9360ffd2012-03-29 04:41:26 -04009935 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009936 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9937 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009938 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009939 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
9940 (sig_dbm &&
9941 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
9942 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9943 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009944
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009945 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009946
Eric W. Biederman15e47302012-09-07 20:12:54 +00009947 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +02009948
9949 nla_put_failure:
9950 genlmsg_cancel(msg, hdr);
9951 nlmsg_free(msg);
9952 return -ENOBUFS;
9953}
9954
Johannes Berg947add32013-02-22 22:05:20 +01009955void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
9956 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009957{
Johannes Berg947add32013-02-22 22:05:20 +01009958 struct wiphy *wiphy = wdev->wiphy;
9959 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
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;
9963
Johannes Berg947add32013-02-22 22:05:20 +01009964 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
9965
Jouni Malinen026331c2010-02-15 12:53:10 +02009966 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9967 if (!msg)
9968 return;
9969
Johannes Berg2e161f72010-08-12 15:38:38 +02009970 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +02009971 if (!hdr) {
9972 nlmsg_free(msg);
9973 return;
9974 }
9975
David S. Miller9360ffd2012-03-29 04:41:26 -04009976 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009977 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9978 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +03009979 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009980 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
9981 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
9982 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
9983 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02009984
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009985 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +02009986
9987 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
9988 return;
9989
9990 nla_put_failure:
9991 genlmsg_cancel(msg, hdr);
9992 nlmsg_free(msg);
9993}
Johannes Berg947add32013-02-22 22:05:20 +01009994EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +02009995
Johannes Berg947add32013-02-22 22:05:20 +01009996void cfg80211_cqm_rssi_notify(struct net_device *dev,
9997 enum nl80211_cqm_rssi_threshold_event rssi_event,
9998 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009999{
Johannes Berg947add32013-02-22 22:05:20 +010010000 struct wireless_dev *wdev = dev->ieee80211_ptr;
10001 struct wiphy *wiphy = wdev->wiphy;
10002 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010003 struct sk_buff *msg;
10004 struct nlattr *pinfoattr;
10005 void *hdr;
10006
Johannes Berg947add32013-02-22 22:05:20 +010010007 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10008
Thomas Graf58050fc2012-06-28 03:57:45 +000010009 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010010 if (!msg)
10011 return;
10012
10013 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10014 if (!hdr) {
10015 nlmsg_free(msg);
10016 return;
10017 }
10018
David S. Miller9360ffd2012-03-29 04:41:26 -040010019 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010020 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010021 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010022
10023 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10024 if (!pinfoattr)
10025 goto nla_put_failure;
10026
David S. Miller9360ffd2012-03-29 04:41:26 -040010027 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10028 rssi_event))
10029 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010030
10031 nla_nest_end(msg, pinfoattr);
10032
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010033 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010034
10035 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10036 nl80211_mlme_mcgrp.id, gfp);
10037 return;
10038
10039 nla_put_failure:
10040 genlmsg_cancel(msg, hdr);
10041 nlmsg_free(msg);
10042}
Johannes Berg947add32013-02-22 22:05:20 +010010043EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010044
Johannes Berg947add32013-02-22 22:05:20 +010010045static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10046 struct net_device *netdev, const u8 *bssid,
10047 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010048{
10049 struct sk_buff *msg;
10050 struct nlattr *rekey_attr;
10051 void *hdr;
10052
Thomas Graf58050fc2012-06-28 03:57:45 +000010053 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010054 if (!msg)
10055 return;
10056
10057 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10058 if (!hdr) {
10059 nlmsg_free(msg);
10060 return;
10061 }
10062
David S. Miller9360ffd2012-03-29 04:41:26 -040010063 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10064 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10065 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10066 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010067
10068 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10069 if (!rekey_attr)
10070 goto nla_put_failure;
10071
David S. Miller9360ffd2012-03-29 04:41:26 -040010072 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10073 NL80211_REPLAY_CTR_LEN, replay_ctr))
10074 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010075
10076 nla_nest_end(msg, rekey_attr);
10077
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010078 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010079
10080 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10081 nl80211_mlme_mcgrp.id, gfp);
10082 return;
10083
10084 nla_put_failure:
10085 genlmsg_cancel(msg, hdr);
10086 nlmsg_free(msg);
10087}
10088
Johannes Berg947add32013-02-22 22:05:20 +010010089void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10090 const u8 *replay_ctr, gfp_t gfp)
10091{
10092 struct wireless_dev *wdev = dev->ieee80211_ptr;
10093 struct wiphy *wiphy = wdev->wiphy;
10094 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10095
10096 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10097 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10098}
10099EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10100
10101static void
10102nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10103 struct net_device *netdev, int index,
10104 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010105{
10106 struct sk_buff *msg;
10107 struct nlattr *attr;
10108 void *hdr;
10109
Thomas Graf58050fc2012-06-28 03:57:45 +000010110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010111 if (!msg)
10112 return;
10113
10114 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10115 if (!hdr) {
10116 nlmsg_free(msg);
10117 return;
10118 }
10119
David S. Miller9360ffd2012-03-29 04:41:26 -040010120 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10121 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10122 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010123
10124 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10125 if (!attr)
10126 goto nla_put_failure;
10127
David S. Miller9360ffd2012-03-29 04:41:26 -040010128 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10129 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10130 (preauth &&
10131 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10132 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010133
10134 nla_nest_end(msg, attr);
10135
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010136 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010137
10138 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10139 nl80211_mlme_mcgrp.id, gfp);
10140 return;
10141
10142 nla_put_failure:
10143 genlmsg_cancel(msg, hdr);
10144 nlmsg_free(msg);
10145}
10146
Johannes Berg947add32013-02-22 22:05:20 +010010147void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10148 const u8 *bssid, bool preauth, gfp_t gfp)
10149{
10150 struct wireless_dev *wdev = dev->ieee80211_ptr;
10151 struct wiphy *wiphy = wdev->wiphy;
10152 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10153
10154 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10155 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10156}
10157EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10158
10159static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10160 struct net_device *netdev,
10161 struct cfg80211_chan_def *chandef,
10162 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010163{
10164 struct sk_buff *msg;
10165 void *hdr;
10166
Thomas Graf58050fc2012-06-28 03:57:45 +000010167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010168 if (!msg)
10169 return;
10170
10171 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10172 if (!hdr) {
10173 nlmsg_free(msg);
10174 return;
10175 }
10176
Johannes Berg683b6d32012-11-08 21:25:48 +010010177 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10178 goto nla_put_failure;
10179
10180 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010181 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010182
10183 genlmsg_end(msg, hdr);
10184
10185 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10186 nl80211_mlme_mcgrp.id, gfp);
10187 return;
10188
10189 nla_put_failure:
10190 genlmsg_cancel(msg, hdr);
10191 nlmsg_free(msg);
10192}
10193
Johannes Berg947add32013-02-22 22:05:20 +010010194void cfg80211_ch_switch_notify(struct net_device *dev,
10195 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010196{
Johannes Berg947add32013-02-22 22:05:20 +010010197 struct wireless_dev *wdev = dev->ieee80211_ptr;
10198 struct wiphy *wiphy = wdev->wiphy;
10199 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10200
10201 trace_cfg80211_ch_switch_notify(dev, chandef);
10202
10203 wdev_lock(wdev);
10204
10205 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10206 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10207 goto out;
10208
10209 wdev->channel = chandef->chan;
10210 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10211out:
10212 wdev_unlock(wdev);
10213 return;
10214}
10215EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10216
10217void cfg80211_cqm_txe_notify(struct net_device *dev,
10218 const u8 *peer, u32 num_packets,
10219 u32 rate, u32 intvl, gfp_t gfp)
10220{
10221 struct wireless_dev *wdev = dev->ieee80211_ptr;
10222 struct wiphy *wiphy = wdev->wiphy;
10223 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010224 struct sk_buff *msg;
10225 struct nlattr *pinfoattr;
10226 void *hdr;
10227
10228 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10229 if (!msg)
10230 return;
10231
10232 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10233 if (!hdr) {
10234 nlmsg_free(msg);
10235 return;
10236 }
10237
10238 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010239 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010240 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10241 goto nla_put_failure;
10242
10243 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10244 if (!pinfoattr)
10245 goto nla_put_failure;
10246
10247 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10248 goto nla_put_failure;
10249
10250 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10251 goto nla_put_failure;
10252
10253 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10254 goto nla_put_failure;
10255
10256 nla_nest_end(msg, pinfoattr);
10257
10258 genlmsg_end(msg, hdr);
10259
10260 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10261 nl80211_mlme_mcgrp.id, gfp);
10262 return;
10263
10264 nla_put_failure:
10265 genlmsg_cancel(msg, hdr);
10266 nlmsg_free(msg);
10267}
Johannes Berg947add32013-02-22 22:05:20 +010010268EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010269
10270void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010271nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10272 struct cfg80211_chan_def *chandef,
10273 enum nl80211_radar_event event,
10274 struct net_device *netdev, gfp_t gfp)
10275{
10276 struct sk_buff *msg;
10277 void *hdr;
10278
10279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10280 if (!msg)
10281 return;
10282
10283 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10284 if (!hdr) {
10285 nlmsg_free(msg);
10286 return;
10287 }
10288
10289 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10290 goto nla_put_failure;
10291
10292 /* NOP and radar events don't need a netdev parameter */
10293 if (netdev) {
10294 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10295
10296 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10297 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10298 goto nla_put_failure;
10299 }
10300
10301 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10302 goto nla_put_failure;
10303
10304 if (nl80211_send_chandef(msg, chandef))
10305 goto nla_put_failure;
10306
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010307 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010308
10309 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10310 nl80211_mlme_mcgrp.id, gfp);
10311 return;
10312
10313 nla_put_failure:
10314 genlmsg_cancel(msg, hdr);
10315 nlmsg_free(msg);
10316}
10317
Johannes Berg947add32013-02-22 22:05:20 +010010318void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10319 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010320{
Johannes Berg947add32013-02-22 22:05:20 +010010321 struct wireless_dev *wdev = dev->ieee80211_ptr;
10322 struct wiphy *wiphy = wdev->wiphy;
10323 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010324 struct sk_buff *msg;
10325 struct nlattr *pinfoattr;
10326 void *hdr;
10327
Johannes Berg947add32013-02-22 22:05:20 +010010328 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10329
Thomas Graf58050fc2012-06-28 03:57:45 +000010330 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010331 if (!msg)
10332 return;
10333
10334 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10335 if (!hdr) {
10336 nlmsg_free(msg);
10337 return;
10338 }
10339
David S. Miller9360ffd2012-03-29 04:41:26 -040010340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010341 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010342 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10343 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010344
10345 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10346 if (!pinfoattr)
10347 goto nla_put_failure;
10348
David S. Miller9360ffd2012-03-29 04:41:26 -040010349 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10350 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010351
10352 nla_nest_end(msg, pinfoattr);
10353
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010354 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010355
10356 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10357 nl80211_mlme_mcgrp.id, gfp);
10358 return;
10359
10360 nla_put_failure:
10361 genlmsg_cancel(msg, hdr);
10362 nlmsg_free(msg);
10363}
Johannes Berg947add32013-02-22 22:05:20 +010010364EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010365
Johannes Berg7f6cf312011-11-04 11:18:15 +010010366void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10367 u64 cookie, bool acked, gfp_t gfp)
10368{
10369 struct wireless_dev *wdev = dev->ieee80211_ptr;
10370 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10371 struct sk_buff *msg;
10372 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010373
Beni Lev4ee3e062012-08-27 12:49:39 +030010374 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10375
Thomas Graf58050fc2012-06-28 03:57:45 +000010376 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010377
Johannes Berg7f6cf312011-11-04 11:18:15 +010010378 if (!msg)
10379 return;
10380
10381 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10382 if (!hdr) {
10383 nlmsg_free(msg);
10384 return;
10385 }
10386
David S. Miller9360ffd2012-03-29 04:41:26 -040010387 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10388 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10389 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10390 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10391 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10392 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010393
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010394 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010395
10396 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10397 nl80211_mlme_mcgrp.id, gfp);
10398 return;
10399
10400 nla_put_failure:
10401 genlmsg_cancel(msg, hdr);
10402 nlmsg_free(msg);
10403}
10404EXPORT_SYMBOL(cfg80211_probe_status);
10405
Johannes Berg5e7602302011-11-04 11:18:17 +010010406void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10407 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010408 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010409{
10410 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10411 struct sk_buff *msg;
10412 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010413 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010414
Beni Lev4ee3e062012-08-27 12:49:39 +030010415 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10416
Ben Greear37c73b52012-10-26 14:49:25 -070010417 spin_lock_bh(&rdev->beacon_registrations_lock);
10418 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10419 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10420 if (!msg) {
10421 spin_unlock_bh(&rdev->beacon_registrations_lock);
10422 return;
10423 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010424
Ben Greear37c73b52012-10-26 14:49:25 -070010425 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10426 if (!hdr)
10427 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010428
Ben Greear37c73b52012-10-26 14:49:25 -070010429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10430 (freq &&
10431 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10432 (sig_dbm &&
10433 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10434 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10435 goto nla_put_failure;
10436
10437 genlmsg_end(msg, hdr);
10438
10439 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010440 }
Ben Greear37c73b52012-10-26 14:49:25 -070010441 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010442 return;
10443
10444 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010445 spin_unlock_bh(&rdev->beacon_registrations_lock);
10446 if (hdr)
10447 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010448 nlmsg_free(msg);
10449}
10450EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10451
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010452#ifdef CONFIG_PM
10453void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10454 struct cfg80211_wowlan_wakeup *wakeup,
10455 gfp_t gfp)
10456{
10457 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10458 struct sk_buff *msg;
10459 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010460 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010461
10462 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10463
10464 if (wakeup)
10465 size += wakeup->packet_present_len;
10466
10467 msg = nlmsg_new(size, gfp);
10468 if (!msg)
10469 return;
10470
10471 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10472 if (!hdr)
10473 goto free_msg;
10474
10475 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10476 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10477 goto free_msg;
10478
10479 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10480 wdev->netdev->ifindex))
10481 goto free_msg;
10482
10483 if (wakeup) {
10484 struct nlattr *reasons;
10485
10486 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10487
10488 if (wakeup->disconnect &&
10489 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10490 goto free_msg;
10491 if (wakeup->magic_pkt &&
10492 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10493 goto free_msg;
10494 if (wakeup->gtk_rekey_failure &&
10495 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10496 goto free_msg;
10497 if (wakeup->eap_identity_req &&
10498 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10499 goto free_msg;
10500 if (wakeup->four_way_handshake &&
10501 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10502 goto free_msg;
10503 if (wakeup->rfkill_release &&
10504 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10505 goto free_msg;
10506
10507 if (wakeup->pattern_idx >= 0 &&
10508 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10509 wakeup->pattern_idx))
10510 goto free_msg;
10511
Johannes Berg2a0e0472013-01-23 22:57:40 +010010512 if (wakeup->tcp_match)
10513 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10514
10515 if (wakeup->tcp_connlost)
10516 nla_put_flag(msg,
10517 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10518
10519 if (wakeup->tcp_nomoretokens)
10520 nla_put_flag(msg,
10521 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10522
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010523 if (wakeup->packet) {
10524 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10525 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10526
10527 if (!wakeup->packet_80211) {
10528 pkt_attr =
10529 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10530 len_attr =
10531 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10532 }
10533
10534 if (wakeup->packet_len &&
10535 nla_put_u32(msg, len_attr, wakeup->packet_len))
10536 goto free_msg;
10537
10538 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10539 wakeup->packet))
10540 goto free_msg;
10541 }
10542
10543 nla_nest_end(msg, reasons);
10544 }
10545
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010546 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010547
10548 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10549 nl80211_mlme_mcgrp.id, gfp);
10550 return;
10551
10552 free_msg:
10553 nlmsg_free(msg);
10554}
10555EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10556#endif
10557
Jouni Malinen3475b092012-11-16 22:49:57 +020010558void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10559 enum nl80211_tdls_operation oper,
10560 u16 reason_code, gfp_t gfp)
10561{
10562 struct wireless_dev *wdev = dev->ieee80211_ptr;
10563 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10564 struct sk_buff *msg;
10565 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010566
10567 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10568 reason_code);
10569
10570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10571 if (!msg)
10572 return;
10573
10574 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10575 if (!hdr) {
10576 nlmsg_free(msg);
10577 return;
10578 }
10579
10580 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10581 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10582 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10583 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10584 (reason_code > 0 &&
10585 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10586 goto nla_put_failure;
10587
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010588 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010589
10590 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10591 nl80211_mlme_mcgrp.id, gfp);
10592 return;
10593
10594 nla_put_failure:
10595 genlmsg_cancel(msg, hdr);
10596 nlmsg_free(msg);
10597}
10598EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10599
Jouni Malinen026331c2010-02-15 12:53:10 +020010600static int nl80211_netlink_notify(struct notifier_block * nb,
10601 unsigned long state,
10602 void *_notify)
10603{
10604 struct netlink_notify *notify = _notify;
10605 struct cfg80211_registered_device *rdev;
10606 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010607 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010608
10609 if (state != NETLINK_URELEASE)
10610 return NOTIFY_DONE;
10611
10612 rcu_read_lock();
10613
Johannes Berg5e7602302011-11-04 11:18:17 +010010614 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010615 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010616 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010617
10618 spin_lock_bh(&rdev->beacon_registrations_lock);
10619 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10620 list) {
10621 if (reg->nlportid == notify->portid) {
10622 list_del(&reg->list);
10623 kfree(reg);
10624 break;
10625 }
10626 }
10627 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010628 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010629
10630 rcu_read_unlock();
10631
10632 return NOTIFY_DONE;
10633}
10634
10635static struct notifier_block nl80211_netlink_notifier = {
10636 .notifier_call = nl80211_netlink_notify,
10637};
10638
Jouni Malinen355199e2013-02-27 17:14:27 +020010639void cfg80211_ft_event(struct net_device *netdev,
10640 struct cfg80211_ft_event_params *ft_event)
10641{
10642 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10643 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10644 struct sk_buff *msg;
10645 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010646
10647 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10648
10649 if (!ft_event->target_ap)
10650 return;
10651
10652 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10653 if (!msg)
10654 return;
10655
10656 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10657 if (!hdr) {
10658 nlmsg_free(msg);
10659 return;
10660 }
10661
10662 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10663 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10664 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10665 if (ft_event->ies)
10666 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10667 if (ft_event->ric_ies)
10668 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10669 ft_event->ric_ies);
10670
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010671 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010672
10673 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10674 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10675}
10676EXPORT_SYMBOL(cfg80211_ft_event);
10677
Arend van Spriel5de17982013-04-18 15:49:00 +020010678void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10679{
10680 struct cfg80211_registered_device *rdev;
10681 struct sk_buff *msg;
10682 void *hdr;
10683 u32 nlportid;
10684
10685 rdev = wiphy_to_dev(wdev->wiphy);
10686 if (!rdev->crit_proto_nlportid)
10687 return;
10688
10689 nlportid = rdev->crit_proto_nlportid;
10690 rdev->crit_proto_nlportid = 0;
10691
10692 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10693 if (!msg)
10694 return;
10695
10696 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10697 if (!hdr)
10698 goto nla_put_failure;
10699
10700 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10701 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10702 goto nla_put_failure;
10703
10704 genlmsg_end(msg, hdr);
10705
10706 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10707 return;
10708
10709 nla_put_failure:
10710 if (hdr)
10711 genlmsg_cancel(msg, hdr);
10712 nlmsg_free(msg);
10713
10714}
10715EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10716
Johannes Berg55682962007-09-20 13:09:35 -040010717/* initialisation/exit functions */
10718
10719int nl80211_init(void)
10720{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010721 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010722
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010723 err = genl_register_family_with_ops(&nl80211_fam,
10724 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010725 if (err)
10726 return err;
10727
Johannes Berg55682962007-09-20 13:09:35 -040010728 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10729 if (err)
10730 goto err_out;
10731
Johannes Berg2a519312009-02-10 21:25:55 +010010732 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10733 if (err)
10734 goto err_out;
10735
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010736 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10737 if (err)
10738 goto err_out;
10739
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010740 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10741 if (err)
10742 goto err_out;
10743
Johannes Bergaff89a92009-07-01 21:26:51 +020010744#ifdef CONFIG_NL80211_TESTMODE
10745 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10746 if (err)
10747 goto err_out;
10748#endif
10749
Jouni Malinen026331c2010-02-15 12:53:10 +020010750 err = netlink_register_notifier(&nl80211_netlink_notifier);
10751 if (err)
10752 goto err_out;
10753
Johannes Berg55682962007-09-20 13:09:35 -040010754 return 0;
10755 err_out:
10756 genl_unregister_family(&nl80211_fam);
10757 return err;
10758}
10759
10760void nl80211_exit(void)
10761{
Jouni Malinen026331c2010-02-15 12:53:10 +020010762 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010763 genl_unregister_family(&nl80211_fam);
10764}