blob: ef4c312cc92c5b65f9713706743876f920ce0c20 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb132011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700406/* policy for coalesce rule attributes */
407static const struct nla_policy
408nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
409 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
410 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
411 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
412};
413
Johannes Berge5497d72011-07-05 16:35:40 +0200414/* policy for GTK rekey offload attributes */
415static const struct nla_policy
416nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
417 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
418 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
419 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
420};
421
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300422static const struct nla_policy
423nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200424 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300425 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700426 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300427};
428
Johannes Berg97990a02013-04-19 01:02:55 +0200429static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
430 struct netlink_callback *cb,
431 struct cfg80211_registered_device **rdev,
432 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100433{
Johannes Berg67748892010-10-04 21:14:06 +0200434 int err;
435
Johannes Berg67748892010-10-04 21:14:06 +0200436 rtnl_lock();
437
Johannes Berg97990a02013-04-19 01:02:55 +0200438 if (!cb->args[0]) {
439 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
440 nl80211_fam.attrbuf, nl80211_fam.maxattr,
441 nl80211_policy);
442 if (err)
443 goto out_unlock;
444
445 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
446 nl80211_fam.attrbuf);
447 if (IS_ERR(*wdev)) {
448 err = PTR_ERR(*wdev);
449 goto out_unlock;
450 }
451 *rdev = wiphy_to_dev((*wdev)->wiphy);
452 cb->args[0] = (*rdev)->wiphy_idx;
453 cb->args[1] = (*wdev)->identifier;
454 } else {
455 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
456 struct wireless_dev *tmp;
457
458 if (!wiphy) {
459 err = -ENODEV;
460 goto out_unlock;
461 }
462 *rdev = wiphy_to_dev(wiphy);
463 *wdev = NULL;
464
Johannes Berg97990a02013-04-19 01:02:55 +0200465 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
466 if (tmp->identifier == cb->args[1]) {
467 *wdev = tmp;
468 break;
469 }
470 }
Johannes Berg97990a02013-04-19 01:02:55 +0200471
472 if (!*wdev) {
473 err = -ENODEV;
474 goto out_unlock;
475 }
Johannes Berg67748892010-10-04 21:14:06 +0200476 }
477
Johannes Berg67748892010-10-04 21:14:06 +0200478 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200479 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200480 rtnl_unlock();
481 return err;
482}
483
Johannes Berg97990a02013-04-19 01:02:55 +0200484static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 rtnl_unlock();
487}
488
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100489/* IE validation */
490static bool is_valid_ie_attr(const struct nlattr *attr)
491{
492 const u8 *pos;
493 int len;
494
495 if (!attr)
496 return true;
497
498 pos = nla_data(attr);
499 len = nla_len(attr);
500
501 while (len) {
502 u8 elemlen;
503
504 if (len < 2)
505 return false;
506 len -= 2;
507
508 elemlen = pos[1];
509 if (elemlen > len)
510 return false;
511
512 len -= elemlen;
513 pos += 2 + elemlen;
514 }
515
516 return true;
517}
518
Johannes Berg55682962007-09-20 13:09:35 -0400519/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000520static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400521 int flags, u8 cmd)
522{
523 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000524 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400525}
526
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400527static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100528 struct ieee80211_channel *chan,
529 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400530{
David S. Miller9360ffd2012-03-29 04:41:26 -0400531 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
532 chan->center_freq))
533 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400534
David S. Miller9360ffd2012-03-29 04:41:26 -0400535 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
536 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
537 goto nla_put_failure;
538 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
539 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
540 goto nla_put_failure;
541 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
542 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
543 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100544 if (chan->flags & IEEE80211_CHAN_RADAR) {
545 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
546 goto nla_put_failure;
547 if (large) {
548 u32 time;
549
550 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
551
552 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
553 chan->dfs_state))
554 goto nla_put_failure;
555 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
556 time))
557 goto nla_put_failure;
558 }
559 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400560
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100561 if (large) {
562 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
563 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
564 goto nla_put_failure;
565 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
566 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
567 goto nla_put_failure;
568 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
569 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
570 goto nla_put_failure;
571 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
572 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
573 goto nla_put_failure;
574 }
575
David S. Miller9360ffd2012-03-29 04:41:26 -0400576 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
577 DBM_TO_MBM(chan->max_power)))
578 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400579
580 return 0;
581
582 nla_put_failure:
583 return -ENOBUFS;
584}
585
Johannes Berg55682962007-09-20 13:09:35 -0400586/* netlink command implementations */
587
Johannes Bergb9454e82009-07-08 13:29:08 +0200588struct key_parse {
589 struct key_params p;
590 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200591 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200592 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100593 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200594};
595
596static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
597{
598 struct nlattr *tb[NL80211_KEY_MAX + 1];
599 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
600 nl80211_key_policy);
601 if (err)
602 return err;
603
604 k->def = !!tb[NL80211_KEY_DEFAULT];
605 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
606
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100607 if (k->def) {
608 k->def_uni = true;
609 k->def_multi = true;
610 }
611 if (k->defmgmt)
612 k->def_multi = true;
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (tb[NL80211_KEY_IDX])
615 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
616
617 if (tb[NL80211_KEY_DATA]) {
618 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
619 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
620 }
621
622 if (tb[NL80211_KEY_SEQ]) {
623 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
624 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
625 }
626
627 if (tb[NL80211_KEY_CIPHER])
628 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
629
Johannes Berge31b8212010-10-05 19:39:30 +0200630 if (tb[NL80211_KEY_TYPE]) {
631 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
632 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
633 return -EINVAL;
634 }
635
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100636 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
637 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100638 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
639 tb[NL80211_KEY_DEFAULT_TYPES],
640 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100641 if (err)
642 return err;
643
644 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
645 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
646 }
647
Johannes Bergb9454e82009-07-08 13:29:08 +0200648 return 0;
649}
650
651static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
652{
653 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
654 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
655 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
656 }
657
658 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
659 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
660 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
661 }
662
663 if (info->attrs[NL80211_ATTR_KEY_IDX])
664 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
665
666 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
667 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
668
669 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
670 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
671
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100672 if (k->def) {
673 k->def_uni = true;
674 k->def_multi = true;
675 }
676 if (k->defmgmt)
677 k->def_multi = true;
678
Johannes Berge31b8212010-10-05 19:39:30 +0200679 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
680 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
681 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
682 return -EINVAL;
683 }
684
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100685 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
686 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
687 int err = nla_parse_nested(
688 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
689 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
690 nl80211_key_default_policy);
691 if (err)
692 return err;
693
694 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
695 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
696 }
697
Johannes Bergb9454e82009-07-08 13:29:08 +0200698 return 0;
699}
700
701static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
702{
703 int err;
704
705 memset(k, 0, sizeof(*k));
706 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200707 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200708
709 if (info->attrs[NL80211_ATTR_KEY])
710 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
711 else
712 err = nl80211_parse_key_old(info, k);
713
714 if (err)
715 return err;
716
717 if (k->def && k->defmgmt)
718 return -EINVAL;
719
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100720 if (k->defmgmt) {
721 if (k->def_uni || !k->def_multi)
722 return -EINVAL;
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 if (k->idx != -1) {
726 if (k->defmgmt) {
727 if (k->idx < 4 || k->idx > 5)
728 return -EINVAL;
729 } else if (k->def) {
730 if (k->idx < 0 || k->idx > 3)
731 return -EINVAL;
732 } else {
733 if (k->idx < 0 || k->idx > 5)
734 return -EINVAL;
735 }
736 }
737
738 return 0;
739}
740
Johannes Bergfffd0932009-07-08 14:22:54 +0200741static struct cfg80211_cached_keys *
742nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530743 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200744{
745 struct key_parse parse;
746 struct nlattr *key;
747 struct cfg80211_cached_keys *result;
748 int rem, err, def = 0;
749
750 result = kzalloc(sizeof(*result), GFP_KERNEL);
751 if (!result)
752 return ERR_PTR(-ENOMEM);
753
754 result->def = -1;
755 result->defmgmt = -1;
756
757 nla_for_each_nested(key, keys, rem) {
758 memset(&parse, 0, sizeof(parse));
759 parse.idx = -1;
760
761 err = nl80211_parse_key_new(key, &parse);
762 if (err)
763 goto error;
764 err = -EINVAL;
765 if (!parse.p.key)
766 goto error;
767 if (parse.idx < 0 || parse.idx > 4)
768 goto error;
769 if (parse.def) {
770 if (def)
771 goto error;
772 def = 1;
773 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (!parse.def_uni || !parse.def_multi)
775 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200776 } else if (parse.defmgmt)
777 goto error;
778 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200779 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200780 if (err)
781 goto error;
782 result->params[parse.idx].cipher = parse.p.cipher;
783 result->params[parse.idx].key_len = parse.p.key_len;
784 result->params[parse.idx].key = result->data[parse.idx];
785 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530786
787 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
788 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
789 if (no_ht)
790 *no_ht = true;
791 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200792 }
793
794 return result;
795 error:
796 kfree(result);
797 return ERR_PTR(err);
798}
799
800static int nl80211_key_allowed(struct wireless_dev *wdev)
801{
802 ASSERT_WDEV_LOCK(wdev);
803
Johannes Bergfffd0932009-07-08 14:22:54 +0200804 switch (wdev->iftype) {
805 case NL80211_IFTYPE_AP:
806 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700808 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 break;
810 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200811 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200812 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200813 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 return -ENOLINK;
815 break;
816 default:
817 return -EINVAL;
818 }
819
820 return 0;
821}
822
Johannes Berg7527a782011-05-13 10:58:57 +0200823static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
824{
825 struct nlattr *nl_modes = nla_nest_start(msg, attr);
826 int i;
827
828 if (!nl_modes)
829 goto nla_put_failure;
830
831 i = 0;
832 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400833 if ((ifmodes & 1) && nla_put_flag(msg, i))
834 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200835 ifmodes >>= 1;
836 i++;
837 }
838
839 nla_nest_end(msg, nl_modes);
840 return 0;
841
842nla_put_failure:
843 return -ENOBUFS;
844}
845
846static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100847 struct sk_buff *msg,
848 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200849{
850 struct nlattr *nl_combis;
851 int i, j;
852
853 nl_combis = nla_nest_start(msg,
854 NL80211_ATTR_INTERFACE_COMBINATIONS);
855 if (!nl_combis)
856 goto nla_put_failure;
857
858 for (i = 0; i < wiphy->n_iface_combinations; i++) {
859 const struct ieee80211_iface_combination *c;
860 struct nlattr *nl_combi, *nl_limits;
861
862 c = &wiphy->iface_combinations[i];
863
864 nl_combi = nla_nest_start(msg, i + 1);
865 if (!nl_combi)
866 goto nla_put_failure;
867
868 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
869 if (!nl_limits)
870 goto nla_put_failure;
871
872 for (j = 0; j < c->n_limits; j++) {
873 struct nlattr *nl_limit;
874
875 nl_limit = nla_nest_start(msg, j + 1);
876 if (!nl_limit)
877 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400878 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
879 c->limits[j].max))
880 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200881 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
882 c->limits[j].types))
883 goto nla_put_failure;
884 nla_nest_end(msg, nl_limit);
885 }
886
887 nla_nest_end(msg, nl_limits);
888
David S. Miller9360ffd2012-03-29 04:41:26 -0400889 if (c->beacon_int_infra_match &&
890 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
891 goto nla_put_failure;
892 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
893 c->num_different_channels) ||
894 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
895 c->max_interfaces))
896 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100897 if (large &&
898 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
899 c->radar_detect_widths))
900 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200901
902 nla_nest_end(msg, nl_combi);
903 }
904
905 nla_nest_end(msg, nl_combis);
906
907 return 0;
908nla_put_failure:
909 return -ENOBUFS;
910}
911
Johannes Berg3713b4e2013-02-14 16:19:38 +0100912#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100913static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
914 struct sk_buff *msg)
915{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200916 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100917 struct nlattr *nl_tcp;
918
919 if (!tcp)
920 return 0;
921
922 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
923 if (!nl_tcp)
924 return -ENOBUFS;
925
926 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
927 tcp->data_payload_max))
928 return -ENOBUFS;
929
930 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
931 tcp->data_payload_max))
932 return -ENOBUFS;
933
934 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
935 return -ENOBUFS;
936
937 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
938 sizeof(*tcp->tok), tcp->tok))
939 return -ENOBUFS;
940
941 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
942 tcp->data_interval_max))
943 return -ENOBUFS;
944
945 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
946 tcp->wake_payload_max))
947 return -ENOBUFS;
948
949 nla_nest_end(msg, nl_tcp);
950 return 0;
951}
952
Johannes Berg3713b4e2013-02-14 16:19:38 +0100953static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100954 struct cfg80211_registered_device *dev,
955 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100956{
957 struct nlattr *nl_wowlan;
958
Johannes Berg964dc9e2013-06-03 17:25:34 +0200959 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100960 return 0;
961
962 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
963 if (!nl_wowlan)
964 return -ENOBUFS;
965
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200974 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100975 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100979 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200980 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
982 return -ENOBUFS;
983
Johannes Berg964dc9e2013-06-03 17:25:34 +0200984 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700985 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200986 .max_patterns = dev->wiphy.wowlan->n_patterns,
987 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
988 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
989 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990 };
991
992 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
993 sizeof(pat), &pat))
994 return -ENOBUFS;
995 }
996
Johannes Bergb56cf722013-02-20 01:02:38 +0100997 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
998 return -ENOBUFS;
999
Johannes Berg3713b4e2013-02-14 16:19:38 +01001000 nla_nest_end(msg, nl_wowlan);
1001
1002 return 0;
1003}
1004#endif
1005
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001006static int nl80211_send_coalesce(struct sk_buff *msg,
1007 struct cfg80211_registered_device *dev)
1008{
1009 struct nl80211_coalesce_rule_support rule;
1010
1011 if (!dev->wiphy.coalesce)
1012 return 0;
1013
1014 rule.max_rules = dev->wiphy.coalesce->n_rules;
1015 rule.max_delay = dev->wiphy.coalesce->max_delay;
1016 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1017 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1018 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1019 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1020
1021 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1022 return -ENOBUFS;
1023
1024 return 0;
1025}
1026
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1028 struct ieee80211_supported_band *sband)
1029{
1030 struct nlattr *nl_rates, *nl_rate;
1031 struct ieee80211_rate *rate;
1032 int i;
1033
1034 /* add HT info */
1035 if (sband->ht_cap.ht_supported &&
1036 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1037 sizeof(sband->ht_cap.mcs),
1038 &sband->ht_cap.mcs) ||
1039 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1040 sband->ht_cap.cap) ||
1041 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1042 sband->ht_cap.ampdu_factor) ||
1043 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1044 sband->ht_cap.ampdu_density)))
1045 return -ENOBUFS;
1046
1047 /* add VHT info */
1048 if (sband->vht_cap.vht_supported &&
1049 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1050 sizeof(sband->vht_cap.vht_mcs),
1051 &sband->vht_cap.vht_mcs) ||
1052 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1053 sband->vht_cap.cap)))
1054 return -ENOBUFS;
1055
1056 /* add bitrates */
1057 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1058 if (!nl_rates)
1059 return -ENOBUFS;
1060
1061 for (i = 0; i < sband->n_bitrates; i++) {
1062 nl_rate = nla_nest_start(msg, i);
1063 if (!nl_rate)
1064 return -ENOBUFS;
1065
1066 rate = &sband->bitrates[i];
1067 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1068 rate->bitrate))
1069 return -ENOBUFS;
1070 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1071 nla_put_flag(msg,
1072 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1073 return -ENOBUFS;
1074
1075 nla_nest_end(msg, nl_rate);
1076 }
1077
1078 nla_nest_end(msg, nl_rates);
1079
1080 return 0;
1081}
1082
1083static int
1084nl80211_send_mgmt_stypes(struct sk_buff *msg,
1085 const struct ieee80211_txrx_stypes *mgmt_stypes)
1086{
1087 u16 stypes;
1088 struct nlattr *nl_ftypes, *nl_ifs;
1089 enum nl80211_iftype ift;
1090 int i;
1091
1092 if (!mgmt_stypes)
1093 return 0;
1094
1095 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1096 if (!nl_ifs)
1097 return -ENOBUFS;
1098
1099 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1100 nl_ftypes = nla_nest_start(msg, ift);
1101 if (!nl_ftypes)
1102 return -ENOBUFS;
1103 i = 0;
1104 stypes = mgmt_stypes[ift].tx;
1105 while (stypes) {
1106 if ((stypes & 1) &&
1107 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1108 (i << 4) | IEEE80211_FTYPE_MGMT))
1109 return -ENOBUFS;
1110 stypes >>= 1;
1111 i++;
1112 }
1113 nla_nest_end(msg, nl_ftypes);
1114 }
1115
1116 nla_nest_end(msg, nl_ifs);
1117
1118 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1119 if (!nl_ifs)
1120 return -ENOBUFS;
1121
1122 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1123 nl_ftypes = nla_nest_start(msg, ift);
1124 if (!nl_ftypes)
1125 return -ENOBUFS;
1126 i = 0;
1127 stypes = mgmt_stypes[ift].rx;
1128 while (stypes) {
1129 if ((stypes & 1) &&
1130 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1131 (i << 4) | IEEE80211_FTYPE_MGMT))
1132 return -ENOBUFS;
1133 stypes >>= 1;
1134 i++;
1135 }
1136 nla_nest_end(msg, nl_ftypes);
1137 }
1138 nla_nest_end(msg, nl_ifs);
1139
1140 return 0;
1141}
1142
Johannes Berg86e8cf92013-06-19 10:57:22 +02001143struct nl80211_dump_wiphy_state {
1144 s64 filter_wiphy;
1145 long start;
1146 long split_start, band_start, chan_start;
1147 bool split;
1148};
1149
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1151 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001152 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001153{
1154 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001155 struct nlattr *nl_bands, *nl_band;
1156 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001157 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001158 enum ieee80211_band band;
1159 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001160 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001161 const struct ieee80211_txrx_stypes *mgmt_stypes =
1162 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001163 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001164
Eric W. Biederman15e47302012-09-07 20:12:54 +00001165 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001166 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001167 return -ENOBUFS;
1168
Johannes Berg86e8cf92013-06-19 10:57:22 +02001169 if (WARN_ON(!state))
1170 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001171
David S. Miller9360ffd2012-03-29 04:41:26 -04001172 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1174 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001177 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001178
Johannes Berg86e8cf92013-06-19 10:57:22 +02001179 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001180 case 0:
1181 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1182 dev->wiphy.retry_short) ||
1183 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1184 dev->wiphy.retry_long) ||
1185 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1186 dev->wiphy.frag_threshold) ||
1187 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1188 dev->wiphy.rts_threshold) ||
1189 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1190 dev->wiphy.coverage_class) ||
1191 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1192 dev->wiphy.max_scan_ssids) ||
1193 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1194 dev->wiphy.max_sched_scan_ssids) ||
1195 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1196 dev->wiphy.max_scan_ie_len) ||
1197 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1198 dev->wiphy.max_sched_scan_ie_len) ||
1199 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1200 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001201 goto nla_put_failure;
1202
Johannes Berg3713b4e2013-02-14 16:19:38 +01001203 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1204 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1205 goto nla_put_failure;
1206 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1213 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1216 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001220 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001221 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1222 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1223 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001224
Johannes Berg86e8cf92013-06-19 10:57:22 +02001225 state->split_start++;
1226 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001227 break;
1228 case 1:
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001232 goto nla_put_failure;
1233
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001236 goto nla_put_failure;
1237
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1257 int res;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1259 if (!res) {
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1262 tx_ant) ||
1263 nla_put_u32(msg,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1265 rx_ant))
1266 goto nla_put_failure;
1267 }
Johannes Bergee688b002008-01-24 19:38:39 +01001268 }
1269
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270 state->split_start++;
1271 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 break;
1273 case 2:
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001277 state->split_start++;
1278 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 break;
1280 case 3:
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1282 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Johannes Berg86e8cf92013-06-19 10:57:22 +02001285 for (band = state->band_start;
1286 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 struct ieee80211_supported_band *sband;
1288
1289 sband = dev->wiphy.bands[band];
1290
1291 if (!sband)
1292 continue;
1293
1294 nl_band = nla_nest_start(msg, band);
1295 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001296 goto nla_put_failure;
1297
Johannes Berg86e8cf92013-06-19 10:57:22 +02001298 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 case 0:
1300 if (nl80211_send_band_rateinfo(msg, sband))
1301 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001302 state->chan_start++;
1303 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 break;
1305 default:
1306 /* add frequencies */
1307 nl_freqs = nla_nest_start(
1308 msg, NL80211_BAND_ATTR_FREQS);
1309 if (!nl_freqs)
1310 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001311
Johannes Berg86e8cf92013-06-19 10:57:22 +02001312 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 i < sband->n_channels;
1314 i++) {
1315 nl_freq = nla_nest_start(msg, i);
1316 if (!nl_freq)
1317 goto nla_put_failure;
1318
1319 chan = &sband->channels[i];
1320
Johannes Berg86e8cf92013-06-19 10:57:22 +02001321 if (nl80211_msg_put_channel(
1322 msg, chan,
1323 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 goto nla_put_failure;
1325
1326 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 break;
1329 }
1330 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001333 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 nla_nest_end(msg, nl_freqs);
1335 }
1336
1337 nla_nest_end(msg, nl_band);
1338
Johannes Berg86e8cf92013-06-19 10:57:22 +02001339 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 band--;
1343 break;
1344 }
Johannes Bergee688b002008-01-24 19:38:39 +01001345 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001347
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001349 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001351 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001352
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 if (state->band_start == 0 && state->chan_start == 0)
1355 state->split_start++;
1356 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 break;
1358 case 4:
1359 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1360 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001361 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362
1363 i = 0;
1364#define CMD(op, n) \
1365 do { \
1366 if (dev->ops->op) { \
1367 i++; \
1368 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1369 goto nla_put_failure; \
1370 } \
1371 } while (0)
1372
1373 CMD(add_virtual_intf, NEW_INTERFACE);
1374 CMD(change_virtual_intf, SET_INTERFACE);
1375 CMD(add_key, NEW_KEY);
1376 CMD(start_ap, START_AP);
1377 CMD(add_station, NEW_STATION);
1378 CMD(add_mpath, NEW_MPATH);
1379 CMD(update_mesh_config, SET_MESH_CONFIG);
1380 CMD(change_bss, SET_BSS);
1381 CMD(auth, AUTHENTICATE);
1382 CMD(assoc, ASSOCIATE);
1383 CMD(deauth, DEAUTHENTICATE);
1384 CMD(disassoc, DISASSOCIATE);
1385 CMD(join_ibss, JOIN_IBSS);
1386 CMD(join_mesh, JOIN_MESH);
1387 CMD(set_pmksa, SET_PMKSA);
1388 CMD(del_pmksa, DEL_PMKSA);
1389 CMD(flush_pmksa, FLUSH_PMKSA);
1390 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1391 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1392 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1393 CMD(mgmt_tx, FRAME);
1394 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1395 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1396 i++;
1397 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1398 goto nla_put_failure;
1399 }
1400 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1401 dev->ops->join_mesh) {
1402 i++;
1403 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1404 goto nla_put_failure;
1405 }
1406 CMD(set_wds_peer, SET_WDS_PEER);
1407 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1408 CMD(tdls_mgmt, TDLS_MGMT);
1409 CMD(tdls_oper, TDLS_OPER);
1410 }
1411 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1412 CMD(sched_scan_start, START_SCHED_SCAN);
1413 CMD(probe_client, PROBE_CLIENT);
1414 CMD(set_noack_map, SET_NOACK_MAP);
1415 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1416 i++;
1417 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1418 goto nla_put_failure;
1419 }
1420 CMD(start_p2p_device, START_P2P_DEVICE);
1421 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001423 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1424 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1425 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001426
Kalle Valo4745fc02011-11-17 19:06:10 +02001427#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001429#endif
1430
Johannes Berg8fdc6212009-03-14 09:34:01 +01001431#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 if (dev->ops->connect || dev->ops->auth) {
1434 i++;
1435 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001436 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001437 }
1438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 if (dev->ops->disconnect || dev->ops->deauth) {
1440 i++;
1441 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1442 goto nla_put_failure;
1443 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001444
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 state->split_start++;
1447 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 break;
1449 case 5:
1450 if (dev->ops->remain_on_channel &&
1451 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1452 nla_put_u32(msg,
1453 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1454 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001455 goto nla_put_failure;
1456
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1458 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1459 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001460
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1462 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001463 state->split_start++;
1464 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 break;
1466 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001467#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001470 state->split_start++;
1471 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 break;
1473#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001474 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475#endif
1476 case 7:
1477 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1478 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001479 goto nla_put_failure;
1480
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1482 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001484
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->split_start++;
1486 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 break;
1488 case 8:
1489 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1490 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1491 dev->wiphy.ap_sme_capa))
1492 goto nla_put_failure;
1493
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001494 features = dev->wiphy.features;
1495 /*
1496 * We can only add the per-channel limit information if the
1497 * dump is split, otherwise it makes it too big. Therefore
1498 * only advertise it in that case.
1499 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001500 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001501 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1502 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 goto nla_put_failure;
1504
1505 if (dev->wiphy.ht_capa_mod_mask &&
1506 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1507 sizeof(*dev->wiphy.ht_capa_mod_mask),
1508 dev->wiphy.ht_capa_mod_mask))
1509 goto nla_put_failure;
1510
1511 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1512 dev->wiphy.max_acl_mac_addrs &&
1513 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1514 dev->wiphy.max_acl_mac_addrs))
1515 goto nla_put_failure;
1516
1517 /*
1518 * Any information below this point is only available to
1519 * applications that can deal with it being split. This
1520 * helps ensure that newly added capabilities don't break
1521 * older tools by overrunning their buffers.
1522 *
1523 * We still increment split_start so that in the split
1524 * case we'll continue with more data in the next round,
1525 * but break unconditionally so unsplit data stops here.
1526 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 break;
1529 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001530 if (dev->wiphy.extended_capabilities &&
1531 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1532 dev->wiphy.extended_capabilities_len,
1533 dev->wiphy.extended_capabilities) ||
1534 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1535 dev->wiphy.extended_capabilities_len,
1536 dev->wiphy.extended_capabilities_mask)))
1537 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538
Johannes Bergee2aca32013-02-21 17:36:01 +01001539 if (dev->wiphy.vht_capa_mod_mask &&
1540 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1541 sizeof(*dev->wiphy.vht_capa_mod_mask),
1542 dev->wiphy.vht_capa_mod_mask))
1543 goto nla_put_failure;
1544
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001545 state->split_start++;
1546 break;
1547 case 10:
1548 if (nl80211_send_coalesce(msg, dev))
1549 goto nla_put_failure;
1550
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001554 }
Johannes Berg55682962007-09-20 13:09:35 -04001555 return genlmsg_end(msg, hdr);
1556
1557 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001558 genlmsg_cancel(msg, hdr);
1559 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001560}
1561
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1563 struct netlink_callback *cb,
1564 struct nl80211_dump_wiphy_state *state)
1565{
1566 struct nlattr **tb = nl80211_fam.attrbuf;
1567 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1568 tb, nl80211_fam.maxattr, nl80211_policy);
1569 /* ignore parse errors for backward compatibility */
1570 if (ret)
1571 return 0;
1572
1573 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1574 if (tb[NL80211_ATTR_WIPHY])
1575 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1576 if (tb[NL80211_ATTR_WDEV])
1577 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1578 if (tb[NL80211_ATTR_IFINDEX]) {
1579 struct net_device *netdev;
1580 struct cfg80211_registered_device *rdev;
1581 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1582
1583 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1584 if (!netdev)
1585 return -ENODEV;
1586 if (netdev->ieee80211_ptr) {
1587 rdev = wiphy_to_dev(
1588 netdev->ieee80211_ptr->wiphy);
1589 state->filter_wiphy = rdev->wiphy_idx;
1590 }
1591 dev_put(netdev);
1592 }
1593
1594 return 0;
1595}
1596
Johannes Berg55682962007-09-20 13:09:35 -04001597static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1598{
Johannes Berg645e77d2013-03-01 14:03:49 +01001599 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001600 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001601 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001602
Johannes Berg5fe231e2013-05-08 21:45:15 +02001603 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001604 if (!state) {
1605 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001606 if (!state) {
1607 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001610 state->filter_wiphy = -1;
1611 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1612 if (ret) {
1613 kfree(state);
1614 rtnl_unlock();
1615 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 }
1619
Johannes Berg79c97e92009-07-07 03:56:12 +02001620 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001621 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1622 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001624 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001625 if (state->filter_wiphy != -1 &&
1626 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 continue;
1628 /* attempt to fit multiple wiphy data chunks into the skb */
1629 do {
1630 ret = nl80211_send_wiphy(dev, skb,
1631 NETLINK_CB(cb->skb).portid,
1632 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001633 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 if (ret < 0) {
1635 /*
1636 * If sending the wiphy data didn't fit (ENOBUFS
1637 * or EMSGSIZE returned), this SKB is still
1638 * empty (so it's not too big because another
1639 * wiphy dataset is already in the skb) and
1640 * we've not tried to adjust the dump allocation
1641 * yet ... then adjust the alloc size to be
1642 * bigger, and return 1 but with the empty skb.
1643 * This results in an empty message being RX'ed
1644 * in userspace, but that is ignored.
1645 *
1646 * We can then retry with the larger buffer.
1647 */
1648 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1649 !skb->len &&
1650 cb->min_dump_alloc < 4096) {
1651 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001652 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001653 return 1;
1654 }
1655 idx--;
1656 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001657 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001658 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 break;
Johannes Berg55682962007-09-20 13:09:35 -04001660 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001661 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001662
Johannes Berg86e8cf92013-06-19 10:57:22 +02001663 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001664
1665 return skb->len;
1666}
1667
Johannes Berg86e8cf92013-06-19 10:57:22 +02001668static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1669{
1670 kfree((void *)cb->args[0]);
1671 return 0;
1672}
1673
Johannes Berg55682962007-09-20 13:09:35 -04001674static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1675{
1676 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001677 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001678 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001679
Johannes Berg645e77d2013-03-01 14:03:49 +01001680 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001681 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001682 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001683
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001686 nlmsg_free(msg);
1687 return -ENOBUFS;
1688 }
Johannes Berg55682962007-09-20 13:09:35 -04001689
Johannes Berg134e6372009-07-10 09:51:34 +00001690 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001691}
1692
Jouni Malinen31888482008-10-30 16:59:24 +02001693static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1694 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1695 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1696 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1697 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1698 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1699};
1700
1701static int parse_txq_params(struct nlattr *tb[],
1702 struct ieee80211_txq_params *txq_params)
1703{
Johannes Berga3304b02012-03-28 11:04:24 +02001704 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001705 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1706 !tb[NL80211_TXQ_ATTR_AIFS])
1707 return -EINVAL;
1708
Johannes Berga3304b02012-03-28 11:04:24 +02001709 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001710 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1711 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1712 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1713 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1714
Johannes Berga3304b02012-03-28 11:04:24 +02001715 if (txq_params->ac >= NL80211_NUM_ACS)
1716 return -EINVAL;
1717
Jouni Malinen31888482008-10-30 16:59:24 +02001718 return 0;
1719}
1720
Johannes Bergf444de02010-05-05 15:25:02 +02001721static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1722{
1723 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001724 * You can only set the channel explicitly for WDS interfaces,
1725 * all others have their channel managed via their respective
1726 * "establish a connection" command (connect, join, ...)
1727 *
1728 * For AP/GO and mesh mode, the channel can be set with the
1729 * channel userspace API, but is only stored and passed to the
1730 * low-level driver when the AP starts or the mesh is joined.
1731 * This is for backward compatibility, userspace can also give
1732 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001733 *
1734 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001735 * whatever else is going on, so they have their own special
1736 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001737 */
1738 return !wdev ||
1739 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001740 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001741 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1742 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001743}
1744
Johannes Berg683b6d32012-11-08 21:25:48 +01001745static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1746 struct genl_info *info,
1747 struct cfg80211_chan_def *chandef)
1748{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301749 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001750
1751 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1752 return -EINVAL;
1753
1754 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1755
1756 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001757 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1758 chandef->center_freq1 = control_freq;
1759 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001760
1761 /* Primary channel not allowed */
1762 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1763 return -EINVAL;
1764
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001765 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1766 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001767
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001768 chantype = nla_get_u32(
1769 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1770
1771 switch (chantype) {
1772 case NL80211_CHAN_NO_HT:
1773 case NL80211_CHAN_HT20:
1774 case NL80211_CHAN_HT40PLUS:
1775 case NL80211_CHAN_HT40MINUS:
1776 cfg80211_chandef_create(chandef, chandef->chan,
1777 chantype);
1778 break;
1779 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001780 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001781 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001782 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1783 chandef->width =
1784 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1785 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1786 chandef->center_freq1 =
1787 nla_get_u32(
1788 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1789 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1790 chandef->center_freq2 =
1791 nla_get_u32(
1792 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1793 }
1794
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001795 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001796 return -EINVAL;
1797
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001798 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1799 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001800 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001801
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001802 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1803 chandef->width == NL80211_CHAN_WIDTH_10) &&
1804 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1805 return -EINVAL;
1806
Johannes Berg683b6d32012-11-08 21:25:48 +01001807 return 0;
1808}
1809
Johannes Bergf444de02010-05-05 15:25:02 +02001810static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1811 struct wireless_dev *wdev,
1812 struct genl_info *info)
1813{
Johannes Berg683b6d32012-11-08 21:25:48 +01001814 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001815 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001816 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1817
1818 if (wdev)
1819 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001820
Johannes Bergf444de02010-05-05 15:25:02 +02001821 if (!nl80211_can_set_dev_channel(wdev))
1822 return -EOPNOTSUPP;
1823
Johannes Berg683b6d32012-11-08 21:25:48 +01001824 result = nl80211_parse_chandef(rdev, info, &chandef);
1825 if (result)
1826 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001827
Johannes Berge8c9bd52012-06-06 08:18:22 +02001828 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001829 case NL80211_IFTYPE_AP:
1830 case NL80211_IFTYPE_P2P_GO:
1831 if (wdev->beacon_interval) {
1832 result = -EBUSY;
1833 break;
1834 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001835 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001836 result = -EINVAL;
1837 break;
1838 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001839 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001840 result = 0;
1841 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001842 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001843 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001844 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001845 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001846 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001847 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001848 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001849 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001850 }
Johannes Bergf444de02010-05-05 15:25:02 +02001851
1852 return result;
1853}
1854
1855static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1856{
Johannes Berg4c476992010-10-04 21:36:35 +02001857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1858 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001859
Johannes Berg4c476992010-10-04 21:36:35 +02001860 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001861}
1862
Bill Jordane8347eb2010-10-01 13:54:28 -04001863static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1864{
Johannes Berg43b19952010-10-07 13:10:30 +02001865 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1866 struct net_device *dev = info->user_ptr[1];
1867 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001868 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001869
1870 if (!info->attrs[NL80211_ATTR_MAC])
1871 return -EINVAL;
1872
Johannes Berg43b19952010-10-07 13:10:30 +02001873 if (netif_running(dev))
1874 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001875
Johannes Berg43b19952010-10-07 13:10:30 +02001876 if (!rdev->ops->set_wds_peer)
1877 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001878
Johannes Berg43b19952010-10-07 13:10:30 +02001879 if (wdev->iftype != NL80211_IFTYPE_WDS)
1880 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001881
1882 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001883 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001884}
1885
1886
Johannes Berg55682962007-09-20 13:09:35 -04001887static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1888{
1889 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001890 struct net_device *netdev = NULL;
1891 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001892 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001893 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001894 u32 changed;
1895 u8 retry_short = 0, retry_long = 0;
1896 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001897 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001898
Johannes Berg5fe231e2013-05-08 21:45:15 +02001899 ASSERT_RTNL();
1900
Johannes Bergf444de02010-05-05 15:25:02 +02001901 /*
1902 * Try to find the wiphy and netdev. Normally this
1903 * function shouldn't need the netdev, but this is
1904 * done for backward compatibility -- previously
1905 * setting the channel was done per wiphy, but now
1906 * it is per netdev. Previous userland like hostapd
1907 * also passed a netdev to set_wiphy, so that it is
1908 * possible to let that go to the right netdev!
1909 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001910
Johannes Bergf444de02010-05-05 15:25:02 +02001911 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1912 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1913
1914 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001915 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001916 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001917 else
Johannes Bergf444de02010-05-05 15:25:02 +02001918 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001919 }
1920
Johannes Bergf444de02010-05-05 15:25:02 +02001921 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001922 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1923 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001924 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001925 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001926 wdev = NULL;
1927 netdev = NULL;
1928 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001929 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001930 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001931
1932 /*
1933 * end workaround code, by now the rdev is available
1934 * and locked, and wdev may or may not be NULL.
1935 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001936
1937 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001938 result = cfg80211_dev_rename(
1939 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001940
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001941 if (result)
1942 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001943
Jouni Malinen31888482008-10-30 16:59:24 +02001944 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1945 struct ieee80211_txq_params txq_params;
1946 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1947
1948 if (!rdev->ops->set_txq_params) {
1949 result = -EOPNOTSUPP;
1950 goto bad_res;
1951 }
1952
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001953 if (!netdev) {
1954 result = -EINVAL;
1955 goto bad_res;
1956 }
1957
Johannes Berg133a3ff2011-11-03 14:50:13 +01001958 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1959 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1960 result = -EINVAL;
1961 goto bad_res;
1962 }
1963
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001964 if (!netif_running(netdev)) {
1965 result = -ENETDOWN;
1966 goto bad_res;
1967 }
1968
Jouni Malinen31888482008-10-30 16:59:24 +02001969 nla_for_each_nested(nl_txq_params,
1970 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1971 rem_txq_params) {
1972 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1973 nla_data(nl_txq_params),
1974 nla_len(nl_txq_params),
1975 txq_params_policy);
1976 result = parse_txq_params(tb, &txq_params);
1977 if (result)
1978 goto bad_res;
1979
Hila Gonene35e4d22012-06-27 17:19:42 +03001980 result = rdev_set_txq_params(rdev, netdev,
1981 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001982 if (result)
1983 goto bad_res;
1984 }
1985 }
1986
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001987 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001988 result = __nl80211_set_channel(rdev,
1989 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1990 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001991 if (result)
1992 goto bad_res;
1993 }
1994
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001995 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001996 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001997 enum nl80211_tx_power_setting type;
1998 int idx, mbm = 0;
1999
Johannes Bergc8442112012-10-24 10:17:18 +02002000 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2001 txp_wdev = NULL;
2002
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002003 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002004 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002005 goto bad_res;
2006 }
2007
2008 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2009 type = nla_get_u32(info->attrs[idx]);
2010
2011 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2012 (type != NL80211_TX_POWER_AUTOMATIC)) {
2013 result = -EINVAL;
2014 goto bad_res;
2015 }
2016
2017 if (type != NL80211_TX_POWER_AUTOMATIC) {
2018 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2019 mbm = nla_get_u32(info->attrs[idx]);
2020 }
2021
Johannes Bergc8442112012-10-24 10:17:18 +02002022 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002023 if (result)
2024 goto bad_res;
2025 }
2026
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002027 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2028 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2029 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002030 if ((!rdev->wiphy.available_antennas_tx &&
2031 !rdev->wiphy.available_antennas_rx) ||
2032 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002033 result = -EOPNOTSUPP;
2034 goto bad_res;
2035 }
2036
2037 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2038 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2039
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002040 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002041 * available antenna masks, except for the "all" mask */
2042 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2043 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002044 result = -EINVAL;
2045 goto bad_res;
2046 }
2047
Bruno Randolf7f531e02010-12-16 11:30:22 +09002048 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2049 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002050
Hila Gonene35e4d22012-06-27 17:19:42 +03002051 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002052 if (result)
2053 goto bad_res;
2054 }
2055
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056 changed = 0;
2057
2058 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2059 retry_short = nla_get_u8(
2060 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2061 if (retry_short == 0) {
2062 result = -EINVAL;
2063 goto bad_res;
2064 }
2065 changed |= WIPHY_PARAM_RETRY_SHORT;
2066 }
2067
2068 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2069 retry_long = nla_get_u8(
2070 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2071 if (retry_long == 0) {
2072 result = -EINVAL;
2073 goto bad_res;
2074 }
2075 changed |= WIPHY_PARAM_RETRY_LONG;
2076 }
2077
2078 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2079 frag_threshold = nla_get_u32(
2080 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2081 if (frag_threshold < 256) {
2082 result = -EINVAL;
2083 goto bad_res;
2084 }
2085 if (frag_threshold != (u32) -1) {
2086 /*
2087 * Fragments (apart from the last one) are required to
2088 * have even length. Make the fragmentation code
2089 * simpler by stripping LSB should someone try to use
2090 * odd threshold value.
2091 */
2092 frag_threshold &= ~0x1;
2093 }
2094 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2095 }
2096
2097 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2098 rts_threshold = nla_get_u32(
2099 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2100 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2101 }
2102
Lukáš Turek81077e82009-12-21 22:50:47 +01002103 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2104 coverage_class = nla_get_u8(
2105 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2106 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2107 }
2108
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002109 if (changed) {
2110 u8 old_retry_short, old_retry_long;
2111 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002112 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002113
2114 if (!rdev->ops->set_wiphy_params) {
2115 result = -EOPNOTSUPP;
2116 goto bad_res;
2117 }
2118
2119 old_retry_short = rdev->wiphy.retry_short;
2120 old_retry_long = rdev->wiphy.retry_long;
2121 old_frag_threshold = rdev->wiphy.frag_threshold;
2122 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002123 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002124
2125 if (changed & WIPHY_PARAM_RETRY_SHORT)
2126 rdev->wiphy.retry_short = retry_short;
2127 if (changed & WIPHY_PARAM_RETRY_LONG)
2128 rdev->wiphy.retry_long = retry_long;
2129 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2130 rdev->wiphy.frag_threshold = frag_threshold;
2131 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2132 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002133 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2134 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002135
Hila Gonene35e4d22012-06-27 17:19:42 +03002136 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002137 if (result) {
2138 rdev->wiphy.retry_short = old_retry_short;
2139 rdev->wiphy.retry_long = old_retry_long;
2140 rdev->wiphy.frag_threshold = old_frag_threshold;
2141 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002142 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002143 }
2144 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002145
Johannes Berg306d6112008-12-08 12:39:04 +01002146 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002147 if (netdev)
2148 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002149 return result;
2150}
2151
Johannes Berg71bbc992012-06-15 15:30:18 +02002152static inline u64 wdev_id(struct wireless_dev *wdev)
2153{
2154 return (u64)wdev->identifier |
2155 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2156}
Johannes Berg55682962007-09-20 13:09:35 -04002157
Johannes Berg683b6d32012-11-08 21:25:48 +01002158static int nl80211_send_chandef(struct sk_buff *msg,
2159 struct cfg80211_chan_def *chandef)
2160{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002161 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002162
Johannes Berg683b6d32012-11-08 21:25:48 +01002163 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2164 chandef->chan->center_freq))
2165 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002166 switch (chandef->width) {
2167 case NL80211_CHAN_WIDTH_20_NOHT:
2168 case NL80211_CHAN_WIDTH_20:
2169 case NL80211_CHAN_WIDTH_40:
2170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2171 cfg80211_get_chandef_type(chandef)))
2172 return -ENOBUFS;
2173 break;
2174 default:
2175 break;
2176 }
2177 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2178 return -ENOBUFS;
2179 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2180 return -ENOBUFS;
2181 if (chandef->center_freq2 &&
2182 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002183 return -ENOBUFS;
2184 return 0;
2185}
2186
Eric W. Biederman15e47302012-09-07 20:12:54 +00002187static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002188 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002189 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002190{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002191 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002192 void *hdr;
2193
Eric W. Biederman15e47302012-09-07 20:12:54 +00002194 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002195 if (!hdr)
2196 return -1;
2197
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002198 if (dev &&
2199 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002200 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002201 goto nla_put_failure;
2202
2203 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2204 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002205 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002207 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2208 rdev->devlist_generation ^
2209 (cfg80211_rdev_list_generation << 2)))
2210 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002211
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002212 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002213 int ret;
2214 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002215
Johannes Berg683b6d32012-11-08 21:25:48 +01002216 ret = rdev_get_channel(rdev, wdev, &chandef);
2217 if (ret == 0) {
2218 if (nl80211_send_chandef(msg, &chandef))
2219 goto nla_put_failure;
2220 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002221 }
2222
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002223 if (wdev->ssid_len) {
2224 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2225 goto nla_put_failure;
2226 }
2227
Johannes Berg55682962007-09-20 13:09:35 -04002228 return genlmsg_end(msg, hdr);
2229
2230 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002231 genlmsg_cancel(msg, hdr);
2232 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002233}
2234
2235static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2236{
2237 int wp_idx = 0;
2238 int if_idx = 0;
2239 int wp_start = cb->args[0];
2240 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002241 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002242 struct wireless_dev *wdev;
2243
Johannes Berg5fe231e2013-05-08 21:45:15 +02002244 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002245 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2246 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002247 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002248 if (wp_idx < wp_start) {
2249 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002250 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002251 }
Johannes Berg55682962007-09-20 13:09:35 -04002252 if_idx = 0;
2253
Johannes Berg89a54e42012-06-15 14:33:17 +02002254 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002255 if (if_idx < if_start) {
2256 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002257 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002258 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002259 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002260 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002261 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 goto out;
2263 }
2264 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002265 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002266
2267 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002268 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002270 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002271
2272 cb->args[0] = wp_idx;
2273 cb->args[1] = if_idx;
2274
2275 return skb->len;
2276}
2277
2278static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2279{
2280 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002281 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002282 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002283
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002285 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002286 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002287
Eric W. Biederman15e47302012-09-07 20:12:54 +00002288 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002289 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002290 nlmsg_free(msg);
2291 return -ENOBUFS;
2292 }
Johannes Berg55682962007-09-20 13:09:35 -04002293
Johannes Berg134e6372009-07-10 09:51:34 +00002294 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002295}
2296
Michael Wu66f7ac52008-01-31 19:48:22 +01002297static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2298 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2299 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2300 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2301 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2302 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002303 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002304};
2305
2306static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2307{
2308 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2309 int flag;
2310
2311 *mntrflags = 0;
2312
2313 if (!nla)
2314 return -EINVAL;
2315
2316 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2317 nla, mntr_flags_policy))
2318 return -EINVAL;
2319
2320 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2321 if (flags[flag])
2322 *mntrflags |= (1<<flag);
2323
2324 return 0;
2325}
2326
Johannes Berg9bc383d2009-11-19 11:55:19 +01002327static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002328 struct net_device *netdev, u8 use_4addr,
2329 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002330{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002331 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002332 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002333 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002334 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002335 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002336
2337 switch (iftype) {
2338 case NL80211_IFTYPE_AP_VLAN:
2339 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2340 return 0;
2341 break;
2342 case NL80211_IFTYPE_STATION:
2343 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2344 return 0;
2345 break;
2346 default:
2347 break;
2348 }
2349
2350 return -EOPNOTSUPP;
2351}
2352
Johannes Berg55682962007-09-20 13:09:35 -04002353static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2354{
Johannes Berg4c476992010-10-04 21:36:35 +02002355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002356 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002357 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002358 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002359 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002360 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002361 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002362
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002363 memset(&params, 0, sizeof(params));
2364
Johannes Berg04a773a2009-04-19 21:24:32 +02002365 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002366
Johannes Berg723b0382008-09-16 20:22:09 +02002367 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002368 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002369 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002370 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002371 if (ntype > NL80211_IFTYPE_MAX)
2372 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002373 }
2374
Johannes Berg92ffe052008-09-16 20:39:36 +02002375 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002376 struct wireless_dev *wdev = dev->ieee80211_ptr;
2377
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (ntype != NL80211_IFTYPE_MESH_POINT)
2379 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002380 if (netif_running(dev))
2381 return -EBUSY;
2382
2383 wdev_lock(wdev);
2384 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2385 IEEE80211_MAX_MESH_ID_LEN);
2386 wdev->mesh_id_up_len =
2387 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2388 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2389 wdev->mesh_id_up_len);
2390 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002391 }
2392
Felix Fietkau8b787642009-11-10 18:53:10 +01002393 if (info->attrs[NL80211_ATTR_4ADDR]) {
2394 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2395 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002396 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002397 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002398 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002399 } else {
2400 params.use_4addr = -1;
2401 }
2402
Johannes Berg92ffe052008-09-16 20:39:36 +02002403 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002404 if (ntype != NL80211_IFTYPE_MONITOR)
2405 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002406 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2407 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002408 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002409 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002410
2411 flags = &_flags;
2412 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002413 }
Johannes Berg3b858752009-03-12 09:55:09 +01002414
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002415 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2416 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2417 return -EOPNOTSUPP;
2418
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002419 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002420 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002421 else
2422 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002423
Johannes Berg9bc383d2009-11-19 11:55:19 +01002424 if (!err && params.use_4addr != -1)
2425 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2426
Johannes Berg55682962007-09-20 13:09:35 -04002427 return err;
2428}
2429
2430static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2431{
Johannes Berg4c476992010-10-04 21:36:35 +02002432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002433 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002434 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002435 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002436 int err;
2437 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002438 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002439
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002440 memset(&params, 0, sizeof(params));
2441
Johannes Berg55682962007-09-20 13:09:35 -04002442 if (!info->attrs[NL80211_ATTR_IFNAME])
2443 return -EINVAL;
2444
2445 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2446 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2447 if (type > NL80211_IFTYPE_MAX)
2448 return -EINVAL;
2449 }
2450
Johannes Berg79c97e92009-07-07 03:56:12 +02002451 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002452 !(rdev->wiphy.interface_modes & (1 << type)))
2453 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002454
Arend van Spriel1c18f142013-01-08 10:17:27 +01002455 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2456 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2457 ETH_ALEN);
2458 if (!is_valid_ether_addr(params.macaddr))
2459 return -EADDRNOTAVAIL;
2460 }
2461
Johannes Berg9bc383d2009-11-19 11:55:19 +01002462 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002463 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002464 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002465 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002466 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002467 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002468
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2470 if (!msg)
2471 return -ENOMEM;
2472
Michael Wu66f7ac52008-01-31 19:48:22 +01002473 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2474 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2475 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002476
2477 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2478 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2479 return -EOPNOTSUPP;
2480
Hila Gonene35e4d22012-06-27 17:19:42 +03002481 wdev = rdev_add_virtual_intf(rdev,
2482 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2483 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002484 if (IS_ERR(wdev)) {
2485 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002486 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002487 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002488
Johannes Berg98104fde2012-06-16 00:19:54 +02002489 switch (type) {
2490 case NL80211_IFTYPE_MESH_POINT:
2491 if (!info->attrs[NL80211_ATTR_MESH_ID])
2492 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002493 wdev_lock(wdev);
2494 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2495 IEEE80211_MAX_MESH_ID_LEN);
2496 wdev->mesh_id_up_len =
2497 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2498 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2499 wdev->mesh_id_up_len);
2500 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002501 break;
2502 case NL80211_IFTYPE_P2P_DEVICE:
2503 /*
2504 * P2P Device doesn't have a netdev, so doesn't go
2505 * through the netdev notifier and must be added here
2506 */
2507 mutex_init(&wdev->mtx);
2508 INIT_LIST_HEAD(&wdev->event_list);
2509 spin_lock_init(&wdev->event_lock);
2510 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2511 spin_lock_init(&wdev->mgmt_registrations_lock);
2512
Johannes Berg98104fde2012-06-16 00:19:54 +02002513 wdev->identifier = ++rdev->wdev_id;
2514 list_add_rcu(&wdev->list, &rdev->wdev_list);
2515 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002516 break;
2517 default:
2518 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002519 }
2520
Eric W. Biederman15e47302012-09-07 20:12:54 +00002521 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002522 rdev, wdev) < 0) {
2523 nlmsg_free(msg);
2524 return -ENOBUFS;
2525 }
2526
2527 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002528}
2529
2530static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2531{
Johannes Berg4c476992010-10-04 21:36:35 +02002532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002533 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002534
Johannes Berg4c476992010-10-04 21:36:35 +02002535 if (!rdev->ops->del_virtual_intf)
2536 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002537
Johannes Berg84efbb82012-06-16 00:00:26 +02002538 /*
2539 * If we remove a wireless device without a netdev then clear
2540 * user_ptr[1] so that nl80211_post_doit won't dereference it
2541 * to check if it needs to do dev_put(). Otherwise it crashes
2542 * since the wdev has been freed, unlike with a netdev where
2543 * we need the dev_put() for the netdev to really be freed.
2544 */
2545 if (!wdev->netdev)
2546 info->user_ptr[1] = NULL;
2547
Hila Gonene35e4d22012-06-27 17:19:42 +03002548 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002549}
2550
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002551static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2552{
2553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2554 struct net_device *dev = info->user_ptr[1];
2555 u16 noack_map;
2556
2557 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2558 return -EINVAL;
2559
2560 if (!rdev->ops->set_noack_map)
2561 return -EOPNOTSUPP;
2562
2563 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2564
Hila Gonene35e4d22012-06-27 17:19:42 +03002565 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002566}
2567
Johannes Berg41ade002007-12-19 02:03:29 +01002568struct get_key_cookie {
2569 struct sk_buff *msg;
2570 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002571 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002572};
2573
2574static void get_key_callback(void *c, struct key_params *params)
2575{
Johannes Bergb9454e82009-07-08 13:29:08 +02002576 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002577 struct get_key_cookie *cookie = c;
2578
David S. Miller9360ffd2012-03-29 04:41:26 -04002579 if ((params->key &&
2580 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2581 params->key_len, params->key)) ||
2582 (params->seq &&
2583 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2584 params->seq_len, params->seq)) ||
2585 (params->cipher &&
2586 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2587 params->cipher)))
2588 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002589
Johannes Bergb9454e82009-07-08 13:29:08 +02002590 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2591 if (!key)
2592 goto nla_put_failure;
2593
David S. Miller9360ffd2012-03-29 04:41:26 -04002594 if ((params->key &&
2595 nla_put(cookie->msg, NL80211_KEY_DATA,
2596 params->key_len, params->key)) ||
2597 (params->seq &&
2598 nla_put(cookie->msg, NL80211_KEY_SEQ,
2599 params->seq_len, params->seq)) ||
2600 (params->cipher &&
2601 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2602 params->cipher)))
2603 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002604
David S. Miller9360ffd2012-03-29 04:41:26 -04002605 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2606 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002607
2608 nla_nest_end(cookie->msg, key);
2609
Johannes Berg41ade002007-12-19 02:03:29 +01002610 return;
2611 nla_put_failure:
2612 cookie->error = 1;
2613}
2614
2615static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2616{
Johannes Berg4c476992010-10-04 21:36:35 +02002617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002618 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002619 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002620 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002621 const u8 *mac_addr = NULL;
2622 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002623 struct get_key_cookie cookie = {
2624 .error = 0,
2625 };
2626 void *hdr;
2627 struct sk_buff *msg;
2628
2629 if (info->attrs[NL80211_ATTR_KEY_IDX])
2630 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2631
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002632 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002633 return -EINVAL;
2634
2635 if (info->attrs[NL80211_ATTR_MAC])
2636 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2637
Johannes Berge31b8212010-10-05 19:39:30 +02002638 pairwise = !!mac_addr;
2639 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2640 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2641 if (kt >= NUM_NL80211_KEYTYPES)
2642 return -EINVAL;
2643 if (kt != NL80211_KEYTYPE_GROUP &&
2644 kt != NL80211_KEYTYPE_PAIRWISE)
2645 return -EINVAL;
2646 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2647 }
2648
Johannes Berg4c476992010-10-04 21:36:35 +02002649 if (!rdev->ops->get_key)
2650 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002651
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002652 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002653 if (!msg)
2654 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002655
Eric W. Biederman15e47302012-09-07 20:12:54 +00002656 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002657 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (IS_ERR(hdr))
2659 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002660
2661 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002662 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002663
David S. Miller9360ffd2012-03-29 04:41:26 -04002664 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2665 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2666 goto nla_put_failure;
2667 if (mac_addr &&
2668 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2669 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002670
Johannes Berge31b8212010-10-05 19:39:30 +02002671 if (pairwise && mac_addr &&
2672 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2673 return -ENOENT;
2674
Hila Gonene35e4d22012-06-27 17:19:42 +03002675 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2676 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002677
2678 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002679 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002680
2681 if (cookie.error)
2682 goto nla_put_failure;
2683
2684 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002685 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002686
2687 nla_put_failure:
2688 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002689 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002690 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002691 return err;
2692}
2693
2694static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2695{
Johannes Berg4c476992010-10-04 21:36:35 +02002696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002697 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002698 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002699 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002700
Johannes Bergb9454e82009-07-08 13:29:08 +02002701 err = nl80211_parse_key(info, &key);
2702 if (err)
2703 return err;
2704
2705 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002706 return -EINVAL;
2707
Johannes Bergb9454e82009-07-08 13:29:08 +02002708 /* only support setting default key */
2709 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002710 return -EINVAL;
2711
Johannes Bergfffd0932009-07-08 14:22:54 +02002712 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002713
2714 if (key.def) {
2715 if (!rdev->ops->set_default_key) {
2716 err = -EOPNOTSUPP;
2717 goto out;
2718 }
2719
2720 err = nl80211_key_allowed(dev->ieee80211_ptr);
2721 if (err)
2722 goto out;
2723
Hila Gonene35e4d22012-06-27 17:19:42 +03002724 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002725 key.def_uni, key.def_multi);
2726
2727 if (err)
2728 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002729
Johannes Berg3d23e342009-09-29 23:27:28 +02002730#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002731 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002732#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002733 } else {
2734 if (key.def_uni || !key.def_multi) {
2735 err = -EINVAL;
2736 goto out;
2737 }
2738
2739 if (!rdev->ops->set_default_mgmt_key) {
2740 err = -EOPNOTSUPP;
2741 goto out;
2742 }
2743
2744 err = nl80211_key_allowed(dev->ieee80211_ptr);
2745 if (err)
2746 goto out;
2747
Hila Gonene35e4d22012-06-27 17:19:42 +03002748 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002749 if (err)
2750 goto out;
2751
2752#ifdef CONFIG_CFG80211_WEXT
2753 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2754#endif
2755 }
2756
2757 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002758 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002759
Johannes Berg41ade002007-12-19 02:03:29 +01002760 return err;
2761}
2762
2763static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2764{
Johannes Berg4c476992010-10-04 21:36:35 +02002765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002767 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002768 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002769 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Johannes Bergb9454e82009-07-08 13:29:08 +02002771 err = nl80211_parse_key(info, &key);
2772 if (err)
2773 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002774
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002776 return -EINVAL;
2777
Johannes Berg41ade002007-12-19 02:03:29 +01002778 if (info->attrs[NL80211_ATTR_MAC])
2779 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2780
Johannes Berge31b8212010-10-05 19:39:30 +02002781 if (key.type == -1) {
2782 if (mac_addr)
2783 key.type = NL80211_KEYTYPE_PAIRWISE;
2784 else
2785 key.type = NL80211_KEYTYPE_GROUP;
2786 }
2787
2788 /* for now */
2789 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2790 key.type != NL80211_KEYTYPE_GROUP)
2791 return -EINVAL;
2792
Johannes Berg4c476992010-10-04 21:36:35 +02002793 if (!rdev->ops->add_key)
2794 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002795
Johannes Berge31b8212010-10-05 19:39:30 +02002796 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2797 key.type == NL80211_KEYTYPE_PAIRWISE,
2798 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002799 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002800
2801 wdev_lock(dev->ieee80211_ptr);
2802 err = nl80211_key_allowed(dev->ieee80211_ptr);
2803 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002804 err = rdev_add_key(rdev, dev, key.idx,
2805 key.type == NL80211_KEYTYPE_PAIRWISE,
2806 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002807 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002808
Johannes Berg41ade002007-12-19 02:03:29 +01002809 return err;
2810}
2811
2812static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2813{
Johannes Berg4c476992010-10-04 21:36:35 +02002814 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002815 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002816 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002817 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002819
Johannes Bergb9454e82009-07-08 13:29:08 +02002820 err = nl80211_parse_key(info, &key);
2821 if (err)
2822 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002823
2824 if (info->attrs[NL80211_ATTR_MAC])
2825 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2826
Johannes Berge31b8212010-10-05 19:39:30 +02002827 if (key.type == -1) {
2828 if (mac_addr)
2829 key.type = NL80211_KEYTYPE_PAIRWISE;
2830 else
2831 key.type = NL80211_KEYTYPE_GROUP;
2832 }
2833
2834 /* for now */
2835 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2836 key.type != NL80211_KEYTYPE_GROUP)
2837 return -EINVAL;
2838
Johannes Berg4c476992010-10-04 21:36:35 +02002839 if (!rdev->ops->del_key)
2840 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002841
Johannes Bergfffd0932009-07-08 14:22:54 +02002842 wdev_lock(dev->ieee80211_ptr);
2843 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002844
2845 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2846 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2847 err = -ENOENT;
2848
Johannes Bergfffd0932009-07-08 14:22:54 +02002849 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002850 err = rdev_del_key(rdev, dev, key.idx,
2851 key.type == NL80211_KEYTYPE_PAIRWISE,
2852 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002853
Johannes Berg3d23e342009-09-29 23:27:28 +02002854#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002855 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002856 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002857 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002858 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002859 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2860 }
2861#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002862 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002863
Johannes Berg41ade002007-12-19 02:03:29 +01002864 return err;
2865}
2866
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302867/* This function returns an error or the number of nested attributes */
2868static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2869{
2870 struct nlattr *attr;
2871 int n_entries = 0, tmp;
2872
2873 nla_for_each_nested(attr, nl_attr, tmp) {
2874 if (nla_len(attr) != ETH_ALEN)
2875 return -EINVAL;
2876
2877 n_entries++;
2878 }
2879
2880 return n_entries;
2881}
2882
2883/*
2884 * This function parses ACL information and allocates memory for ACL data.
2885 * On successful return, the calling function is responsible to free the
2886 * ACL buffer returned by this function.
2887 */
2888static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2889 struct genl_info *info)
2890{
2891 enum nl80211_acl_policy acl_policy;
2892 struct nlattr *attr;
2893 struct cfg80211_acl_data *acl;
2894 int i = 0, n_entries, tmp;
2895
2896 if (!wiphy->max_acl_mac_addrs)
2897 return ERR_PTR(-EOPNOTSUPP);
2898
2899 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2900 return ERR_PTR(-EINVAL);
2901
2902 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2903 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2904 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2905 return ERR_PTR(-EINVAL);
2906
2907 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2908 return ERR_PTR(-EINVAL);
2909
2910 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2911 if (n_entries < 0)
2912 return ERR_PTR(n_entries);
2913
2914 if (n_entries > wiphy->max_acl_mac_addrs)
2915 return ERR_PTR(-ENOTSUPP);
2916
2917 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2918 GFP_KERNEL);
2919 if (!acl)
2920 return ERR_PTR(-ENOMEM);
2921
2922 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2923 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2924 i++;
2925 }
2926
2927 acl->n_acl_entries = n_entries;
2928 acl->acl_policy = acl_policy;
2929
2930 return acl;
2931}
2932
2933static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2934{
2935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2936 struct net_device *dev = info->user_ptr[1];
2937 struct cfg80211_acl_data *acl;
2938 int err;
2939
2940 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2941 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2942 return -EOPNOTSUPP;
2943
2944 if (!dev->ieee80211_ptr->beacon_interval)
2945 return -EINVAL;
2946
2947 acl = parse_acl_data(&rdev->wiphy, info);
2948 if (IS_ERR(acl))
2949 return PTR_ERR(acl);
2950
2951 err = rdev_set_mac_acl(rdev, dev, acl);
2952
2953 kfree(acl);
2954
2955 return err;
2956}
2957
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002958static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002959 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002960{
Johannes Berg88600202012-02-13 15:17:18 +01002961 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002962
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002963 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2964 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2965 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2966 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002967 return -EINVAL;
2968
Johannes Berg88600202012-02-13 15:17:18 +01002969 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002970
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002971 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2972 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2973 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002974 if (!bcn->head_len)
2975 return -EINVAL;
2976 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002977 }
2978
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002979 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2980 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2981 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002982 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002983 }
2984
Johannes Berg4c476992010-10-04 21:36:35 +02002985 if (!haveinfo)
2986 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002987
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002988 if (attrs[NL80211_ATTR_IE]) {
2989 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2990 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002991 }
2992
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002993 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002994 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002995 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002996 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002997 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002998 }
2999
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003000 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003001 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003003 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003004 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003005 }
3006
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003007 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3008 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3009 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003010 }
3011
Johannes Berg88600202012-02-13 15:17:18 +01003012 return 0;
3013}
3014
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003015static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3016 struct cfg80211_ap_settings *params)
3017{
3018 struct wireless_dev *wdev;
3019 bool ret = false;
3020
Johannes Berg89a54e42012-06-15 14:33:17 +02003021 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003022 if (wdev->iftype != NL80211_IFTYPE_AP &&
3023 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3024 continue;
3025
Johannes Berg683b6d32012-11-08 21:25:48 +01003026 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003027 continue;
3028
Johannes Berg683b6d32012-11-08 21:25:48 +01003029 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003030 ret = true;
3031 break;
3032 }
3033
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003034 return ret;
3035}
3036
Jouni Malinene39e5b52012-09-30 19:29:39 +03003037static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3038 enum nl80211_auth_type auth_type,
3039 enum nl80211_commands cmd)
3040{
3041 if (auth_type > NL80211_AUTHTYPE_MAX)
3042 return false;
3043
3044 switch (cmd) {
3045 case NL80211_CMD_AUTHENTICATE:
3046 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3047 auth_type == NL80211_AUTHTYPE_SAE)
3048 return false;
3049 return true;
3050 case NL80211_CMD_CONNECT:
3051 case NL80211_CMD_START_AP:
3052 /* SAE not supported yet */
3053 if (auth_type == NL80211_AUTHTYPE_SAE)
3054 return false;
3055 return true;
3056 default:
3057 return false;
3058 }
3059}
3060
Johannes Berg88600202012-02-13 15:17:18 +01003061static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3062{
3063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3064 struct net_device *dev = info->user_ptr[1];
3065 struct wireless_dev *wdev = dev->ieee80211_ptr;
3066 struct cfg80211_ap_settings params;
3067 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003068 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003069
3070 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3071 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3072 return -EOPNOTSUPP;
3073
3074 if (!rdev->ops->start_ap)
3075 return -EOPNOTSUPP;
3076
3077 if (wdev->beacon_interval)
3078 return -EALREADY;
3079
3080 memset(&params, 0, sizeof(params));
3081
3082 /* these are required for START_AP */
3083 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3084 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3085 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3086 return -EINVAL;
3087
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003088 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003089 if (err)
3090 return err;
3091
3092 params.beacon_interval =
3093 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3094 params.dtim_period =
3095 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3096
3097 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3098 if (err)
3099 return err;
3100
3101 /*
3102 * In theory, some of these attributes should be required here
3103 * but since they were not used when the command was originally
3104 * added, keep them optional for old user space programs to let
3105 * them continue to work with drivers that do not need the
3106 * additional information -- drivers must check!
3107 */
3108 if (info->attrs[NL80211_ATTR_SSID]) {
3109 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3110 params.ssid_len =
3111 nla_len(info->attrs[NL80211_ATTR_SSID]);
3112 if (params.ssid_len == 0 ||
3113 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3114 return -EINVAL;
3115 }
3116
3117 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3118 params.hidden_ssid = nla_get_u32(
3119 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3120 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3121 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3122 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3123 return -EINVAL;
3124 }
3125
3126 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3127
3128 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3129 params.auth_type = nla_get_u32(
3130 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003131 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3132 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003133 return -EINVAL;
3134 } else
3135 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3136
3137 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3138 NL80211_MAX_NR_CIPHER_SUITES);
3139 if (err)
3140 return err;
3141
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303142 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3143 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3144 return -EOPNOTSUPP;
3145 params.inactivity_timeout = nla_get_u16(
3146 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3147 }
3148
Johannes Berg53cabad2012-11-14 15:17:28 +01003149 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3151 return -EINVAL;
3152 params.p2p_ctwindow =
3153 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3154 if (params.p2p_ctwindow > 127)
3155 return -EINVAL;
3156 if (params.p2p_ctwindow != 0 &&
3157 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3158 return -EINVAL;
3159 }
3160
3161 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3162 u8 tmp;
3163
3164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3165 return -EINVAL;
3166 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3167 if (tmp > 1)
3168 return -EINVAL;
3169 params.p2p_opp_ps = tmp;
3170 if (params.p2p_opp_ps != 0 &&
3171 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3172 return -EINVAL;
3173 }
3174
Johannes Bergaa430da2012-05-16 23:50:18 +02003175 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003176 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3177 if (err)
3178 return err;
3179 } else if (wdev->preset_chandef.chan) {
3180 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003181 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003182 return -EINVAL;
3183
Johannes Berg683b6d32012-11-08 21:25:48 +01003184 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003185 return -EINVAL;
3186
Simon Wunderlich04f39042013-02-08 18:16:19 +01003187 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3188 if (err < 0)
3189 return err;
3190 if (err) {
3191 radar_detect_width = BIT(params.chandef.width);
3192 params.radar_required = true;
3193 }
3194
Simon Wunderlich04f39042013-02-08 18:16:19 +01003195 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3196 params.chandef.chan,
3197 CHAN_MODE_SHARED,
3198 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003199 if (err)
3200 return err;
3201
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303202 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3203 params.acl = parse_acl_data(&rdev->wiphy, info);
3204 if (IS_ERR(params.acl))
3205 return PTR_ERR(params.acl);
3206 }
3207
Hila Gonene35e4d22012-06-27 17:19:42 +03003208 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003209 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003210 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003211 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003212 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003213 wdev->ssid_len = params.ssid_len;
3214 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003215 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303216
3217 kfree(params.acl);
3218
Johannes Berg56d18932011-05-09 18:41:15 +02003219 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003220}
3221
Johannes Berg88600202012-02-13 15:17:18 +01003222static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3223{
3224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3225 struct net_device *dev = info->user_ptr[1];
3226 struct wireless_dev *wdev = dev->ieee80211_ptr;
3227 struct cfg80211_beacon_data params;
3228 int err;
3229
3230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3231 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3232 return -EOPNOTSUPP;
3233
3234 if (!rdev->ops->change_beacon)
3235 return -EOPNOTSUPP;
3236
3237 if (!wdev->beacon_interval)
3238 return -EINVAL;
3239
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003240 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003241 if (err)
3242 return err;
3243
Hila Gonene35e4d22012-06-27 17:19:42 +03003244 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003245}
3246
3247static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003248{
Johannes Berg4c476992010-10-04 21:36:35 +02003249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3250 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003251
Michal Kazior60771782012-06-29 12:46:56 +02003252 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003253}
3254
Johannes Berg5727ef12007-12-19 02:03:34 +01003255static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3256 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3257 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3258 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003259 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003260 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003261 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003262};
3263
Johannes Bergeccb8e82009-05-11 21:57:56 +03003264static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003265 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003266 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003267{
3268 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003269 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003270 int flag;
3271
Johannes Bergeccb8e82009-05-11 21:57:56 +03003272 /*
3273 * Try parsing the new attribute first so userspace
3274 * can specify both for older kernels.
3275 */
3276 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3277 if (nla) {
3278 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003279
Johannes Bergeccb8e82009-05-11 21:57:56 +03003280 sta_flags = nla_data(nla);
3281 params->sta_flags_mask = sta_flags->mask;
3282 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003283 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003284 if ((params->sta_flags_mask |
3285 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3286 return -EINVAL;
3287 return 0;
3288 }
3289
3290 /* if present, parse the old attribute */
3291
3292 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003293 if (!nla)
3294 return 0;
3295
3296 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3297 nla, sta_flags_policy))
3298 return -EINVAL;
3299
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003300 /*
3301 * Only allow certain flags for interface types so that
3302 * other attributes are silently ignored. Remember that
3303 * this is backward compatibility code with old userspace
3304 * and shouldn't be hit in other cases anyway.
3305 */
3306 switch (iftype) {
3307 case NL80211_IFTYPE_AP:
3308 case NL80211_IFTYPE_AP_VLAN:
3309 case NL80211_IFTYPE_P2P_GO:
3310 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3311 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3312 BIT(NL80211_STA_FLAG_WME) |
3313 BIT(NL80211_STA_FLAG_MFP);
3314 break;
3315 case NL80211_IFTYPE_P2P_CLIENT:
3316 case NL80211_IFTYPE_STATION:
3317 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3318 BIT(NL80211_STA_FLAG_TDLS_PEER);
3319 break;
3320 case NL80211_IFTYPE_MESH_POINT:
3321 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3322 BIT(NL80211_STA_FLAG_MFP) |
3323 BIT(NL80211_STA_FLAG_AUTHORIZED);
3324 default:
3325 return -EINVAL;
3326 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003327
Johannes Berg3383b5a2012-05-10 20:14:43 +02003328 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3329 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003330 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003331
Johannes Berg3383b5a2012-05-10 20:14:43 +02003332 /* no longer support new API additions in old API */
3333 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3334 return -EINVAL;
3335 }
3336 }
3337
Johannes Berg5727ef12007-12-19 02:03:34 +01003338 return 0;
3339}
3340
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003341static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3342 int attr)
3343{
3344 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003345 u32 bitrate;
3346 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003347
3348 rate = nla_nest_start(msg, attr);
3349 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003350 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003351
3352 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3353 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003354 /* report 16-bit bitrate only if we can */
3355 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003356 if (bitrate > 0 &&
3357 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3358 return false;
3359 if (bitrate_compat > 0 &&
3360 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3361 return false;
3362
3363 if (info->flags & RATE_INFO_FLAGS_MCS) {
3364 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3365 return false;
3366 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3367 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3368 return false;
3369 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3370 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3371 return false;
3372 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3373 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3374 return false;
3375 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3376 return false;
3377 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3378 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3379 return false;
3380 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3381 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3382 return false;
3383 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3384 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3385 return false;
3386 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3387 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3388 return false;
3389 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3390 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3391 return false;
3392 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003393
3394 nla_nest_end(msg, rate);
3395 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003396}
3397
Felix Fietkau119363c2013-04-22 16:29:30 +02003398static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3399 int id)
3400{
3401 void *attr;
3402 int i = 0;
3403
3404 if (!mask)
3405 return true;
3406
3407 attr = nla_nest_start(msg, id);
3408 if (!attr)
3409 return false;
3410
3411 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3412 if (!(mask & BIT(i)))
3413 continue;
3414
3415 if (nla_put_u8(msg, i, signal[i]))
3416 return false;
3417 }
3418
3419 nla_nest_end(msg, attr);
3420
3421 return true;
3422}
3423
Eric W. Biederman15e47302012-09-07 20:12:54 +00003424static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003425 int flags,
3426 struct cfg80211_registered_device *rdev,
3427 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003428 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003429{
3430 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003431 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003432
Eric W. Biederman15e47302012-09-07 20:12:54 +00003433 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003434 if (!hdr)
3435 return -1;
3436
David S. Miller9360ffd2012-03-29 04:41:26 -04003437 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3438 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3439 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3440 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003441
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003442 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3443 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003444 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003445 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3446 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3447 sinfo->connected_time))
3448 goto nla_put_failure;
3449 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3451 sinfo->inactive_time))
3452 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003453 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3454 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003455 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003456 (u32)sinfo->rx_bytes))
3457 goto nla_put_failure;
3458 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003459 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003460 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3461 (u32)sinfo->tx_bytes))
3462 goto nla_put_failure;
3463 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3464 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003465 sinfo->rx_bytes))
3466 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003467 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3468 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003469 sinfo->tx_bytes))
3470 goto nla_put_failure;
3471 if ((sinfo->filled & STATION_INFO_LLID) &&
3472 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3473 goto nla_put_failure;
3474 if ((sinfo->filled & STATION_INFO_PLID) &&
3475 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3478 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3479 sinfo->plink_state))
3480 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003481 switch (rdev->wiphy.signal_type) {
3482 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003483 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3484 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3485 sinfo->signal))
3486 goto nla_put_failure;
3487 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3488 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3489 sinfo->signal_avg))
3490 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003491 break;
3492 default:
3493 break;
3494 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003495 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3496 if (!nl80211_put_signal(msg, sinfo->chains,
3497 sinfo->chain_signal,
3498 NL80211_STA_INFO_CHAIN_SIGNAL))
3499 goto nla_put_failure;
3500 }
3501 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3502 if (!nl80211_put_signal(msg, sinfo->chains,
3503 sinfo->chain_signal_avg,
3504 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3505 goto nla_put_failure;
3506 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003507 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003508 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3509 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003510 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003511 }
3512 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3513 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3514 NL80211_STA_INFO_RX_BITRATE))
3515 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003516 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003517 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3518 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3519 sinfo->rx_packets))
3520 goto nla_put_failure;
3521 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3522 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3523 sinfo->tx_packets))
3524 goto nla_put_failure;
3525 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3526 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3527 sinfo->tx_retries))
3528 goto nla_put_failure;
3529 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3530 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3531 sinfo->tx_failed))
3532 goto nla_put_failure;
3533 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3534 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3535 sinfo->beacon_loss_count))
3536 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003537 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3538 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3539 sinfo->local_pm))
3540 goto nla_put_failure;
3541 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3542 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3543 sinfo->peer_pm))
3544 goto nla_put_failure;
3545 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3546 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3547 sinfo->nonpeer_pm))
3548 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003549 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3550 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3551 if (!bss_param)
3552 goto nla_put_failure;
3553
David S. Miller9360ffd2012-03-29 04:41:26 -04003554 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3555 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3556 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3557 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3558 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3559 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3560 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3561 sinfo->bss_param.dtim_period) ||
3562 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3563 sinfo->bss_param.beacon_interval))
3564 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003565
3566 nla_nest_end(msg, bss_param);
3567 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003568 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3569 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3570 sizeof(struct nl80211_sta_flag_update),
3571 &sinfo->sta_flags))
3572 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003573 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3574 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3575 sinfo->t_offset))
3576 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003577 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003578
David S. Miller9360ffd2012-03-29 04:41:26 -04003579 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3580 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3581 sinfo->assoc_req_ies))
3582 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003583
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584 return genlmsg_end(msg, hdr);
3585
3586 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003587 genlmsg_cancel(msg, hdr);
3588 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589}
3590
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003592 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003594 struct station_info sinfo;
3595 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003596 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003597 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003598 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003599 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003600
Johannes Berg97990a02013-04-19 01:02:55 +02003601 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003602 if (err)
3603 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003604
Johannes Berg97990a02013-04-19 01:02:55 +02003605 if (!wdev->netdev) {
3606 err = -EINVAL;
3607 goto out_err;
3608 }
3609
Johannes Bergbba95fe2008-07-29 13:22:51 +02003610 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003611 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003612 goto out_err;
3613 }
3614
Johannes Bergbba95fe2008-07-29 13:22:51 +02003615 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003616 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003617 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003618 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003619 if (err == -ENOENT)
3620 break;
3621 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003622 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003623
3624 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003625 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003626 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003627 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003628 &sinfo) < 0)
3629 goto out;
3630
3631 sta_idx++;
3632 }
3633
3634
3635 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003636 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003637 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003638 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003639 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003640
3641 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003642}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003643
Johannes Berg5727ef12007-12-19 02:03:34 +01003644static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3645{
Johannes Berg4c476992010-10-04 21:36:35 +02003646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3647 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003648 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003649 struct sk_buff *msg;
3650 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003651 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003652
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003653 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003654
3655 if (!info->attrs[NL80211_ATTR_MAC])
3656 return -EINVAL;
3657
3658 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3659
Johannes Berg4c476992010-10-04 21:36:35 +02003660 if (!rdev->ops->get_station)
3661 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003662
Hila Gonene35e4d22012-06-27 17:19:42 +03003663 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003664 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003665 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003666
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003668 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003669 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003670
Eric W. Biederman15e47302012-09-07 20:12:54 +00003671 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003672 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003673 nlmsg_free(msg);
3674 return -ENOBUFS;
3675 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003676
Johannes Berg4c476992010-10-04 21:36:35 +02003677 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003678}
3679
Johannes Berg77ee7c82013-02-15 00:48:33 +01003680int cfg80211_check_station_change(struct wiphy *wiphy,
3681 struct station_parameters *params,
3682 enum cfg80211_station_type statype)
3683{
3684 if (params->listen_interval != -1)
3685 return -EINVAL;
3686 if (params->aid)
3687 return -EINVAL;
3688
3689 /* When you run into this, adjust the code below for the new flag */
3690 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3691
3692 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003693 case CFG80211_STA_MESH_PEER_KERNEL:
3694 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003695 /*
3696 * No ignoring the TDLS flag here -- the userspace mesh
3697 * code doesn't have the bug of including TDLS in the
3698 * mask everywhere.
3699 */
3700 if (params->sta_flags_mask &
3701 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3702 BIT(NL80211_STA_FLAG_MFP) |
3703 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3704 return -EINVAL;
3705 break;
3706 case CFG80211_STA_TDLS_PEER_SETUP:
3707 case CFG80211_STA_TDLS_PEER_ACTIVE:
3708 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3709 return -EINVAL;
3710 /* ignore since it can't change */
3711 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3712 break;
3713 default:
3714 /* disallow mesh-specific things */
3715 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3716 return -EINVAL;
3717 if (params->local_pm)
3718 return -EINVAL;
3719 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3720 return -EINVAL;
3721 }
3722
3723 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3724 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3725 /* TDLS can't be set, ... */
3726 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3727 return -EINVAL;
3728 /*
3729 * ... but don't bother the driver with it. This works around
3730 * a hostapd/wpa_supplicant issue -- it always includes the
3731 * TLDS_PEER flag in the mask even for AP mode.
3732 */
3733 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3734 }
3735
3736 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3737 /* reject other things that can't change */
3738 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3739 return -EINVAL;
3740 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3741 return -EINVAL;
3742 if (params->supported_rates)
3743 return -EINVAL;
3744 if (params->ext_capab || params->ht_capa || params->vht_capa)
3745 return -EINVAL;
3746 }
3747
3748 if (statype != CFG80211_STA_AP_CLIENT) {
3749 if (params->vlan)
3750 return -EINVAL;
3751 }
3752
3753 switch (statype) {
3754 case CFG80211_STA_AP_MLME_CLIENT:
3755 /* Use this only for authorizing/unauthorizing a station */
3756 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3757 return -EOPNOTSUPP;
3758 break;
3759 case CFG80211_STA_AP_CLIENT:
3760 /* accept only the listed bits */
3761 if (params->sta_flags_mask &
3762 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3763 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3764 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3765 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3766 BIT(NL80211_STA_FLAG_WME) |
3767 BIT(NL80211_STA_FLAG_MFP)))
3768 return -EINVAL;
3769
3770 /* but authenticated/associated only if driver handles it */
3771 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3772 params->sta_flags_mask &
3773 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3774 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3775 return -EINVAL;
3776 break;
3777 case CFG80211_STA_IBSS:
3778 case CFG80211_STA_AP_STA:
3779 /* reject any changes other than AUTHORIZED */
3780 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3781 return -EINVAL;
3782 break;
3783 case CFG80211_STA_TDLS_PEER_SETUP:
3784 /* reject any changes other than AUTHORIZED or WME */
3785 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3786 BIT(NL80211_STA_FLAG_WME)))
3787 return -EINVAL;
3788 /* force (at least) rates when authorizing */
3789 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3790 !params->supported_rates)
3791 return -EINVAL;
3792 break;
3793 case CFG80211_STA_TDLS_PEER_ACTIVE:
3794 /* reject any changes */
3795 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003796 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003797 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3798 return -EINVAL;
3799 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003800 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003801 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3802 return -EINVAL;
3803 break;
3804 }
3805
3806 return 0;
3807}
3808EXPORT_SYMBOL(cfg80211_check_station_change);
3809
Johannes Berg5727ef12007-12-19 02:03:34 +01003810/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003811 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003812 */
Johannes Berg80b99892011-11-18 16:23:01 +01003813static struct net_device *get_vlan(struct genl_info *info,
3814 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003815{
Johannes Berg463d0182009-07-14 00:33:35 +02003816 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003817 struct net_device *v;
3818 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003819
Johannes Berg80b99892011-11-18 16:23:01 +01003820 if (!vlanattr)
3821 return NULL;
3822
3823 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3824 if (!v)
3825 return ERR_PTR(-ENODEV);
3826
3827 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3828 ret = -EINVAL;
3829 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003830 }
Johannes Berg80b99892011-11-18 16:23:01 +01003831
Johannes Berg77ee7c82013-02-15 00:48:33 +01003832 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3833 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3834 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3835 ret = -EINVAL;
3836 goto error;
3837 }
3838
Johannes Berg80b99892011-11-18 16:23:01 +01003839 if (!netif_running(v)) {
3840 ret = -ENETDOWN;
3841 goto error;
3842 }
3843
3844 return v;
3845 error:
3846 dev_put(v);
3847 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003848}
3849
Jouni Malinendf881292013-02-14 21:10:54 +02003850static struct nla_policy
3851nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3852 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3853 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3854};
3855
Johannes Bergff276692013-02-15 00:09:01 +01003856static int nl80211_parse_sta_wme(struct genl_info *info,
3857 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003858{
Jouni Malinendf881292013-02-14 21:10:54 +02003859 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3860 struct nlattr *nla;
3861 int err;
3862
Jouni Malinendf881292013-02-14 21:10:54 +02003863 /* parse WME attributes if present */
3864 if (!info->attrs[NL80211_ATTR_STA_WME])
3865 return 0;
3866
3867 nla = info->attrs[NL80211_ATTR_STA_WME];
3868 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3869 nl80211_sta_wme_policy);
3870 if (err)
3871 return err;
3872
3873 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3874 params->uapsd_queues = nla_get_u8(
3875 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3876 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3877 return -EINVAL;
3878
3879 if (tb[NL80211_STA_WME_MAX_SP])
3880 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3881
3882 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3883 return -EINVAL;
3884
3885 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3886
3887 return 0;
3888}
3889
Johannes Bergff276692013-02-15 00:09:01 +01003890static int nl80211_set_station_tdls(struct genl_info *info,
3891 struct station_parameters *params)
3892{
3893 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003894 if (info->attrs[NL80211_ATTR_PEER_AID])
3895 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003896 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3897 params->ht_capa =
3898 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3899 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3900 params->vht_capa =
3901 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3902
3903 return nl80211_parse_sta_wme(info, params);
3904}
3905
Johannes Berg5727ef12007-12-19 02:03:34 +01003906static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3907{
Johannes Berg4c476992010-10-04 21:36:35 +02003908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003909 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003910 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003911 u8 *mac_addr;
3912 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003913
3914 memset(&params, 0, sizeof(params));
3915
3916 params.listen_interval = -1;
3917
Johannes Berg77ee7c82013-02-15 00:48:33 +01003918 if (!rdev->ops->change_station)
3919 return -EOPNOTSUPP;
3920
Johannes Berg5727ef12007-12-19 02:03:34 +01003921 if (info->attrs[NL80211_ATTR_STA_AID])
3922 return -EINVAL;
3923
3924 if (!info->attrs[NL80211_ATTR_MAC])
3925 return -EINVAL;
3926
3927 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3928
3929 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3930 params.supported_rates =
3931 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3932 params.supported_rates_len =
3933 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3934 }
3935
Jouni Malinen9d62a982013-02-14 21:10:13 +02003936 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3937 params.capability =
3938 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3939 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3940 }
3941
3942 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3943 params.ext_capab =
3944 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3945 params.ext_capab_len =
3946 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3947 }
3948
Jouni Malinendf881292013-02-14 21:10:54 +02003949 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003950 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03003951
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003952 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003953 return -EINVAL;
3954
Johannes Bergf8bacc22013-02-14 23:27:01 +01003955 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003956 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003957 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3958 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3959 return -EINVAL;
3960 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003961
Johannes Bergf8bacc22013-02-14 23:27:01 +01003962 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003963 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003964 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3965 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3966 return -EINVAL;
3967 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3968 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003969
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003970 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3971 enum nl80211_mesh_power_mode pm = nla_get_u32(
3972 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3973
3974 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3975 pm > NL80211_MESH_POWER_MAX)
3976 return -EINVAL;
3977
3978 params.local_pm = pm;
3979 }
3980
Johannes Berg77ee7c82013-02-15 00:48:33 +01003981 /* Include parameters for TDLS peer (will check later) */
3982 err = nl80211_set_station_tdls(info, &params);
3983 if (err)
3984 return err;
3985
3986 params.vlan = get_vlan(info, rdev);
3987 if (IS_ERR(params.vlan))
3988 return PTR_ERR(params.vlan);
3989
Johannes Berga97f4422009-06-18 17:23:43 +02003990 switch (dev->ieee80211_ptr->iftype) {
3991 case NL80211_IFTYPE_AP:
3992 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003993 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003994 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003995 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003996 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003997 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003998 break;
3999 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004000 err = -EOPNOTSUPP;
4001 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004002 }
4003
Johannes Berg77ee7c82013-02-15 00:48:33 +01004004 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004005 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004006
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004008 if (params.vlan)
4009 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004010
Johannes Berg5727ef12007-12-19 02:03:34 +01004011 return err;
4012}
4013
4014static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4015{
Johannes Berg4c476992010-10-04 21:36:35 +02004016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004017 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004018 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004019 struct station_parameters params;
4020 u8 *mac_addr = NULL;
4021
4022 memset(&params, 0, sizeof(params));
4023
Johannes Berg984c3112013-02-14 23:43:25 +01004024 if (!rdev->ops->add_station)
4025 return -EOPNOTSUPP;
4026
Johannes Berg5727ef12007-12-19 02:03:34 +01004027 if (!info->attrs[NL80211_ATTR_MAC])
4028 return -EINVAL;
4029
Johannes Berg5727ef12007-12-19 02:03:34 +01004030 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4031 return -EINVAL;
4032
4033 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4034 return -EINVAL;
4035
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004036 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4037 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004038 return -EINVAL;
4039
Johannes Berg5727ef12007-12-19 02:03:34 +01004040 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4041 params.supported_rates =
4042 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4043 params.supported_rates_len =
4044 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4045 params.listen_interval =
4046 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004047
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004048 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004049 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004050 else
4051 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004052 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4053 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004054
Jouni Malinen9d62a982013-02-14 21:10:13 +02004055 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4056 params.capability =
4057 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4058 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4059 }
4060
4061 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4062 params.ext_capab =
4063 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4064 params.ext_capab_len =
4065 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4066 }
4067
Jouni Malinen36aedc92008-08-25 11:58:58 +03004068 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4069 params.ht_capa =
4070 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004071
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004072 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4073 params.vht_capa =
4074 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4075
Johannes Bergf8bacc22013-02-14 23:27:01 +01004076 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004077 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004078 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4079 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4080 return -EINVAL;
4081 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004082
Johannes Bergff276692013-02-15 00:09:01 +01004083 err = nl80211_parse_sta_wme(info, &params);
4084 if (err)
4085 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004086
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004087 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004088 return -EINVAL;
4089
Johannes Berg77ee7c82013-02-15 00:48:33 +01004090 /* When you run into this, adjust the code below for the new flag */
4091 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4092
Johannes Bergbdd90d52011-12-14 12:20:27 +01004093 switch (dev->ieee80211_ptr->iftype) {
4094 case NL80211_IFTYPE_AP:
4095 case NL80211_IFTYPE_AP_VLAN:
4096 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004097 /* ignore WME attributes if iface/sta is not capable */
4098 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4099 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4100 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004101
Johannes Bergbdd90d52011-12-14 12:20:27 +01004102 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004103 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4104 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004105 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004106 /* but don't bother the driver with it */
4107 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004108
Johannes Bergd582cff2012-10-26 17:53:44 +02004109 /* allow authenticated/associated only if driver handles it */
4110 if (!(rdev->wiphy.features &
4111 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4112 params.sta_flags_mask &
4113 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4114 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4115 return -EINVAL;
4116
Johannes Bergbdd90d52011-12-14 12:20:27 +01004117 /* must be last in here for error handling */
4118 params.vlan = get_vlan(info, rdev);
4119 if (IS_ERR(params.vlan))
4120 return PTR_ERR(params.vlan);
4121 break;
4122 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004123 /* ignore uAPSD data */
4124 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4125
Johannes Bergd582cff2012-10-26 17:53:44 +02004126 /* associated is disallowed */
4127 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4128 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004129 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004130 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4131 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004132 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004133 break;
4134 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004135 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004136 /* ignore uAPSD data */
4137 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4138
Johannes Berg77ee7c82013-02-15 00:48:33 +01004139 /* these are disallowed */
4140 if (params.sta_flags_mask &
4141 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4142 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004143 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004144 /* Only TDLS peers can be added */
4145 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4146 return -EINVAL;
4147 /* Can only add if TDLS ... */
4148 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4149 return -EOPNOTSUPP;
4150 /* ... with external setup is supported */
4151 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4152 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004153 /*
4154 * Older wpa_supplicant versions always mark the TDLS peer
4155 * as authorized, but it shouldn't yet be.
4156 */
4157 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004158 break;
4159 default:
4160 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004161 }
4162
Johannes Bergbdd90d52011-12-14 12:20:27 +01004163 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004164
Hila Gonene35e4d22012-06-27 17:19:42 +03004165 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004166
Johannes Berg5727ef12007-12-19 02:03:34 +01004167 if (params.vlan)
4168 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004169 return err;
4170}
4171
4172static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4173{
Johannes Berg4c476992010-10-04 21:36:35 +02004174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4175 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004176 u8 *mac_addr = NULL;
4177
4178 if (info->attrs[NL80211_ATTR_MAC])
4179 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4180
Johannes Berge80cf852009-05-11 14:43:13 +02004181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4185 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004186
Johannes Berg4c476992010-10-04 21:36:35 +02004187 if (!rdev->ops->del_station)
4188 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004189
Hila Gonene35e4d22012-06-27 17:19:42 +03004190 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004191}
4192
Eric W. Biederman15e47302012-09-07 20:12:54 +00004193static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004194 int flags, struct net_device *dev,
4195 u8 *dst, u8 *next_hop,
4196 struct mpath_info *pinfo)
4197{
4198 void *hdr;
4199 struct nlattr *pinfoattr;
4200
Eric W. Biederman15e47302012-09-07 20:12:54 +00004201 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004202 if (!hdr)
4203 return -1;
4204
David S. Miller9360ffd2012-03-29 04:41:26 -04004205 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4207 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4208 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4209 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004210
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004211 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4212 if (!pinfoattr)
4213 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004214 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4215 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4216 pinfo->frame_qlen))
4217 goto nla_put_failure;
4218 if (((pinfo->filled & MPATH_INFO_SN) &&
4219 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4220 ((pinfo->filled & MPATH_INFO_METRIC) &&
4221 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4222 pinfo->metric)) ||
4223 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4224 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4225 pinfo->exptime)) ||
4226 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4227 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4228 pinfo->flags)) ||
4229 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4230 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4231 pinfo->discovery_timeout)) ||
4232 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4233 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4234 pinfo->discovery_retries)))
4235 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004236
4237 nla_nest_end(msg, pinfoattr);
4238
4239 return genlmsg_end(msg, hdr);
4240
4241 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004242 genlmsg_cancel(msg, hdr);
4243 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004244}
4245
4246static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004247 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004249 struct mpath_info pinfo;
4250 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004251 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252 u8 dst[ETH_ALEN];
4253 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004254 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004255 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004256
Johannes Berg97990a02013-04-19 01:02:55 +02004257 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004258 if (err)
4259 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004260
4261 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004262 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004263 goto out_err;
4264 }
4265
Johannes Berg97990a02013-04-19 01:02:55 +02004266 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004267 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004268 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004269 }
4270
Johannes Bergbba95fe2008-07-29 13:22:51 +02004271 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004272 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4273 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004274 if (err == -ENOENT)
4275 break;
4276 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004277 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004278
Eric W. Biederman15e47302012-09-07 20:12:54 +00004279 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004280 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004281 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004282 &pinfo) < 0)
4283 goto out;
4284
4285 path_idx++;
4286 }
4287
4288
4289 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004290 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004291 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004292 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004293 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004294 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004295}
4296
4297static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4298{
Johannes Berg4c476992010-10-04 21:36:35 +02004299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004301 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302 struct mpath_info pinfo;
4303 struct sk_buff *msg;
4304 u8 *dst = NULL;
4305 u8 next_hop[ETH_ALEN];
4306
4307 memset(&pinfo, 0, sizeof(pinfo));
4308
4309 if (!info->attrs[NL80211_ATTR_MAC])
4310 return -EINVAL;
4311
4312 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4313
Johannes Berg4c476992010-10-04 21:36:35 +02004314 if (!rdev->ops->get_mpath)
4315 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004316
Johannes Berg4c476992010-10-04 21:36:35 +02004317 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4318 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004319
Hila Gonene35e4d22012-06-27 17:19:42 +03004320 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004322 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004323
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004326 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004327
Eric W. Biederman15e47302012-09-07 20:12:54 +00004328 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004329 dev, dst, next_hop, &pinfo) < 0) {
4330 nlmsg_free(msg);
4331 return -ENOBUFS;
4332 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004333
Johannes Berg4c476992010-10-04 21:36:35 +02004334 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004335}
4336
4337static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4338{
Johannes Berg4c476992010-10-04 21:36:35 +02004339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4340 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004341 u8 *dst = NULL;
4342 u8 *next_hop = NULL;
4343
4344 if (!info->attrs[NL80211_ATTR_MAC])
4345 return -EINVAL;
4346
4347 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4348 return -EINVAL;
4349
4350 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4351 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4352
Johannes Berg4c476992010-10-04 21:36:35 +02004353 if (!rdev->ops->change_mpath)
4354 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004355
Johannes Berg4c476992010-10-04 21:36:35 +02004356 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4357 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358
Hila Gonene35e4d22012-06-27 17:19:42 +03004359 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004360}
Johannes Berg4c476992010-10-04 21:36:35 +02004361
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004362static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4363{
Johannes Berg4c476992010-10-04 21:36:35 +02004364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4365 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004366 u8 *dst = NULL;
4367 u8 *next_hop = NULL;
4368
4369 if (!info->attrs[NL80211_ATTR_MAC])
4370 return -EINVAL;
4371
4372 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4373 return -EINVAL;
4374
4375 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4376 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4377
Johannes Berg4c476992010-10-04 21:36:35 +02004378 if (!rdev->ops->add_mpath)
4379 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004380
Johannes Berg4c476992010-10-04 21:36:35 +02004381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4382 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383
Hila Gonene35e4d22012-06-27 17:19:42 +03004384 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004385}
4386
4387static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4388{
Johannes Berg4c476992010-10-04 21:36:35 +02004389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4390 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391 u8 *dst = NULL;
4392
4393 if (info->attrs[NL80211_ATTR_MAC])
4394 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4395
Johannes Berg4c476992010-10-04 21:36:35 +02004396 if (!rdev->ops->del_mpath)
4397 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004398
Hila Gonene35e4d22012-06-27 17:19:42 +03004399 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400}
4401
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004402static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4403{
Johannes Berg4c476992010-10-04 21:36:35 +02004404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4405 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004406 struct bss_parameters params;
4407
4408 memset(&params, 0, sizeof(params));
4409 /* default to not changing parameters */
4410 params.use_cts_prot = -1;
4411 params.use_short_preamble = -1;
4412 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004413 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004414 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004415 params.p2p_ctwindow = -1;
4416 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004417
4418 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4419 params.use_cts_prot =
4420 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4421 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4422 params.use_short_preamble =
4423 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4424 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4425 params.use_short_slot_time =
4426 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004427 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4428 params.basic_rates =
4429 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4430 params.basic_rates_len =
4431 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4432 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004433 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4434 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004435 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4436 params.ht_opmode =
4437 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004438
Johannes Berg53cabad2012-11-14 15:17:28 +01004439 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4440 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4441 return -EINVAL;
4442 params.p2p_ctwindow =
4443 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4444 if (params.p2p_ctwindow < 0)
4445 return -EINVAL;
4446 if (params.p2p_ctwindow != 0 &&
4447 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4448 return -EINVAL;
4449 }
4450
4451 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4452 u8 tmp;
4453
4454 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4455 return -EINVAL;
4456 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4457 if (tmp > 1)
4458 return -EINVAL;
4459 params.p2p_opp_ps = tmp;
4460 if (params.p2p_opp_ps &&
4461 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4462 return -EINVAL;
4463 }
4464
Johannes Berg4c476992010-10-04 21:36:35 +02004465 if (!rdev->ops->change_bss)
4466 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004467
Johannes Berg074ac8d2010-09-16 14:58:22 +02004468 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004469 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4470 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004471
Hila Gonene35e4d22012-06-27 17:19:42 +03004472 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004473}
4474
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004475static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004476 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4477 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4478 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4479 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4480 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4481 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4482};
4483
4484static int parse_reg_rule(struct nlattr *tb[],
4485 struct ieee80211_reg_rule *reg_rule)
4486{
4487 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4488 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4489
4490 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4491 return -EINVAL;
4492 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4493 return -EINVAL;
4494 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4495 return -EINVAL;
4496 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4497 return -EINVAL;
4498 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4499 return -EINVAL;
4500
4501 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4502
4503 freq_range->start_freq_khz =
4504 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4505 freq_range->end_freq_khz =
4506 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4507 freq_range->max_bandwidth_khz =
4508 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4509
4510 power_rule->max_eirp =
4511 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4512
4513 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4514 power_rule->max_antenna_gain =
4515 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4516
4517 return 0;
4518}
4519
4520static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4521{
4522 int r;
4523 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004524 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004525
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004526 /*
4527 * You should only get this when cfg80211 hasn't yet initialized
4528 * completely when built-in to the kernel right between the time
4529 * window between nl80211_init() and regulatory_init(), if that is
4530 * even possible.
4531 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004532 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004533 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004534
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004535 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4536 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004537
4538 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4539
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004540 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4541 user_reg_hint_type =
4542 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4543 else
4544 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4545
4546 switch (user_reg_hint_type) {
4547 case NL80211_USER_REG_HINT_USER:
4548 case NL80211_USER_REG_HINT_CELL_BASE:
4549 break;
4550 default:
4551 return -EINVAL;
4552 }
4553
4554 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004555
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004556 return r;
4557}
4558
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004559static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004560 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004561{
Johannes Berg4c476992010-10-04 21:36:35 +02004562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004563 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004564 struct wireless_dev *wdev = dev->ieee80211_ptr;
4565 struct mesh_config cur_params;
4566 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004567 void *hdr;
4568 struct nlattr *pinfoattr;
4569 struct sk_buff *msg;
4570
Johannes Berg29cbe682010-12-03 09:20:44 +01004571 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4572 return -EOPNOTSUPP;
4573
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004574 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004575 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004576
Johannes Berg29cbe682010-12-03 09:20:44 +01004577 wdev_lock(wdev);
4578 /* If not connected, get default parameters */
4579 if (!wdev->mesh_id_len)
4580 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4581 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004582 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004583 wdev_unlock(wdev);
4584
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004586 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587
4588 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004590 if (!msg)
4591 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004592 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004593 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004595 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004596 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004597 if (!pinfoattr)
4598 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004599 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4600 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4601 cur_params.dot11MeshRetryTimeout) ||
4602 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4603 cur_params.dot11MeshConfirmTimeout) ||
4604 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4605 cur_params.dot11MeshHoldingTimeout) ||
4606 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4607 cur_params.dot11MeshMaxPeerLinks) ||
4608 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4609 cur_params.dot11MeshMaxRetries) ||
4610 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4611 cur_params.dot11MeshTTL) ||
4612 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4613 cur_params.element_ttl) ||
4614 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4615 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004616 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4617 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004618 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4619 cur_params.dot11MeshHWMPmaxPREQretries) ||
4620 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4621 cur_params.path_refresh_time) ||
4622 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4623 cur_params.min_discovery_timeout) ||
4624 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4625 cur_params.dot11MeshHWMPactivePathTimeout) ||
4626 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4627 cur_params.dot11MeshHWMPpreqMinInterval) ||
4628 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4629 cur_params.dot11MeshHWMPperrMinInterval) ||
4630 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4631 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4632 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4633 cur_params.dot11MeshHWMPRootMode) ||
4634 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4635 cur_params.dot11MeshHWMPRannInterval) ||
4636 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4637 cur_params.dot11MeshGateAnnouncementProtocol) ||
4638 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4639 cur_params.dot11MeshForwarding) ||
4640 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004641 cur_params.rssi_threshold) ||
4642 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004643 cur_params.ht_opmode) ||
4644 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4645 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4646 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004647 cur_params.dot11MeshHWMProotInterval) ||
4648 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004649 cur_params.dot11MeshHWMPconfirmationInterval) ||
4650 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4651 cur_params.power_mode) ||
4652 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004653 cur_params.dot11MeshAwakeWindowDuration) ||
4654 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4655 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004656 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004657 nla_nest_end(msg, pinfoattr);
4658 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004659 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004660
Johannes Berg3b858752009-03-12 09:55:09 +01004661 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004663 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004664 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004665 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004666}
4667
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004668static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004669 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4670 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4671 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4672 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4673 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4674 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004675 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004676 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004677 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004678 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4679 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4680 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4681 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4682 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004683 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004684 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004685 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004686 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004687 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004688 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004689 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4690 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004691 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4692 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004693 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004694 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4695 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004696 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697};
4698
Javier Cardonac80d5452010-12-16 17:37:49 -08004699static const struct nla_policy
4700 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004701 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004702 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4703 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004704 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004705 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004706 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004707 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004709 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004710};
4711
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004712static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004713 struct mesh_config *cfg,
4714 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004715{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004716 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004717 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718
Marco Porschea54fba2013-01-07 16:04:48 +01004719#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4720do { \
4721 if (tb[attr]) { \
4722 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4723 return -EINVAL; \
4724 cfg->param = fn(tb[attr]); \
4725 mask |= (1 << (attr - 1)); \
4726 } \
4727} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004728
4729
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004730 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004731 return -EINVAL;
4732 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004733 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004734 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004735 return -EINVAL;
4736
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004737 /* This makes sure that there aren't more than 32 mesh config
4738 * parameters (otherwise our bitfield scheme would not work.) */
4739 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4740
4741 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004742 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004743 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4744 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004745 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004746 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4747 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004749 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4750 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004752 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4753 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004755 mask, NL80211_MESHCONF_MAX_RETRIES,
4756 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004757 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004758 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004760 mask, NL80211_MESHCONF_ELEMENT_TTL,
4761 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004762 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004763 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4764 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004765 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4766 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004767 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4768 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004769 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004770 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4771 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004772 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004773 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4774 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004775 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004776 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4777 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004778 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4779 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004780 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4781 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004782 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004783 1, 65535, mask,
4784 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004785 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004787 1, 65535, mask,
4788 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004789 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004791 dot11MeshHWMPnetDiameterTraversalTime,
4792 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004793 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4794 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4796 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4797 nla_get_u8);
4798 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4799 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004800 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004801 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004802 dot11MeshGateAnnouncementProtocol, 0, 1,
4803 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004804 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004805 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004806 mask, NL80211_MESHCONF_FORWARDING,
4807 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004808 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004809 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4810 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004811 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004812 mask, NL80211_MESHCONF_HT_OPMODE,
4813 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004814 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004815 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004816 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4817 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004819 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4820 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004822 dot11MeshHWMPconfirmationInterval,
4823 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004824 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4825 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4827 NL80211_MESH_POWER_ACTIVE,
4828 NL80211_MESH_POWER_MAX,
4829 mask, NL80211_MESHCONF_POWER_MODE,
4830 nla_get_u32);
4831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4832 0, 65535, mask,
4833 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4835 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4836 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004837 if (mask_out)
4838 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004839
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840 return 0;
4841
4842#undef FILL_IN_MESH_PARAM_IF_SET
4843}
4844
Javier Cardonac80d5452010-12-16 17:37:49 -08004845static int nl80211_parse_mesh_setup(struct genl_info *info,
4846 struct mesh_setup *setup)
4847{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004849 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4850
4851 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4852 return -EINVAL;
4853 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4854 info->attrs[NL80211_ATTR_MESH_SETUP],
4855 nl80211_mesh_setup_params_policy))
4856 return -EINVAL;
4857
Javier Cardonad299a1f2012-03-31 11:31:33 -07004858 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4859 setup->sync_method =
4860 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4861 IEEE80211_SYNC_METHOD_VENDOR :
4862 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4863
Javier Cardonac80d5452010-12-16 17:37:49 -08004864 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4865 setup->path_sel_proto =
4866 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4867 IEEE80211_PATH_PROTOCOL_VENDOR :
4868 IEEE80211_PATH_PROTOCOL_HWMP;
4869
4870 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4871 setup->path_metric =
4872 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4873 IEEE80211_PATH_METRIC_VENDOR :
4874 IEEE80211_PATH_METRIC_AIRTIME;
4875
Javier Cardona581a8b02011-04-07 15:08:27 -07004876
4877 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004878 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004879 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004880 if (!is_valid_ie_attr(ieattr))
4881 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004882 setup->ie = nla_data(ieattr);
4883 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004884 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004885 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4886 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4887 return -EINVAL;
4888 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004889 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4890 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004891 if (setup->is_secure)
4892 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004893
Colleen Twitty6e16d902013-05-08 11:45:59 -07004894 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4895 if (!setup->user_mpm)
4896 return -EINVAL;
4897 setup->auth_id =
4898 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4899 }
4900
Javier Cardonac80d5452010-12-16 17:37:49 -08004901 return 0;
4902}
4903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004904static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004905 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004906{
4907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4908 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004909 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004910 struct mesh_config cfg;
4911 u32 mask;
4912 int err;
4913
Johannes Berg29cbe682010-12-03 09:20:44 +01004914 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4915 return -EOPNOTSUPP;
4916
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004917 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004918 return -EOPNOTSUPP;
4919
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004920 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004921 if (err)
4922 return err;
4923
Johannes Berg29cbe682010-12-03 09:20:44 +01004924 wdev_lock(wdev);
4925 if (!wdev->mesh_id_len)
4926 err = -ENOLINK;
4927
4928 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004929 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004930
4931 wdev_unlock(wdev);
4932
4933 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004934}
4935
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004936static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4937{
Johannes Berg458f4f92012-12-06 15:47:38 +01004938 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939 struct sk_buff *msg;
4940 void *hdr = NULL;
4941 struct nlattr *nl_reg_rules;
4942 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004943
4944 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004945 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004946
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004947 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004948 if (!msg)
4949 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004950
Eric W. Biederman15e47302012-09-07 20:12:54 +00004951 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004952 NL80211_CMD_GET_REG);
4953 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004954 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004955
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004956 if (reg_last_request_cell_base() &&
4957 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4958 NL80211_USER_REG_HINT_CELL_BASE))
4959 goto nla_put_failure;
4960
Johannes Berg458f4f92012-12-06 15:47:38 +01004961 rcu_read_lock();
4962 regdom = rcu_dereference(cfg80211_regdomain);
4963
4964 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4965 (regdom->dfs_region &&
4966 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4967 goto nla_put_failure_rcu;
4968
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004969 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4970 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004971 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004972
Johannes Berg458f4f92012-12-06 15:47:38 +01004973 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004974 struct nlattr *nl_reg_rule;
4975 const struct ieee80211_reg_rule *reg_rule;
4976 const struct ieee80211_freq_range *freq_range;
4977 const struct ieee80211_power_rule *power_rule;
4978
Johannes Berg458f4f92012-12-06 15:47:38 +01004979 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004980 freq_range = &reg_rule->freq_range;
4981 power_rule = &reg_rule->power_rule;
4982
4983 nl_reg_rule = nla_nest_start(msg, i);
4984 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004985 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004986
David S. Miller9360ffd2012-03-29 04:41:26 -04004987 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4988 reg_rule->flags) ||
4989 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4990 freq_range->start_freq_khz) ||
4991 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4992 freq_range->end_freq_khz) ||
4993 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4994 freq_range->max_bandwidth_khz) ||
4995 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4996 power_rule->max_antenna_gain) ||
4997 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4998 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004999 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005000
5001 nla_nest_end(msg, nl_reg_rule);
5002 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005003 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005004
5005 nla_nest_end(msg, nl_reg_rules);
5006
5007 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005008 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005009
Johannes Berg458f4f92012-12-06 15:47:38 +01005010nla_put_failure_rcu:
5011 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005012nla_put_failure:
5013 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005014put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005015 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005016 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005017}
5018
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005019static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5020{
5021 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5022 struct nlattr *nl_reg_rule;
5023 char *alpha2 = NULL;
5024 int rem_reg_rules = 0, r = 0;
5025 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005026 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005027 struct ieee80211_regdomain *rd = NULL;
5028
5029 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5030 return -EINVAL;
5031
5032 if (!info->attrs[NL80211_ATTR_REG_RULES])
5033 return -EINVAL;
5034
5035 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5036
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005037 if (info->attrs[NL80211_ATTR_DFS_REGION])
5038 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5039
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005040 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005041 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005042 num_rules++;
5043 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005044 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005045 }
5046
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005047 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005048 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005049
5050 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005051 if (!rd)
5052 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005053
5054 rd->n_reg_rules = num_rules;
5055 rd->alpha2[0] = alpha2[0];
5056 rd->alpha2[1] = alpha2[1];
5057
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005058 /*
5059 * Disable DFS master mode if the DFS region was
5060 * not supported or known on this kernel.
5061 */
5062 if (reg_supported_dfs_region(dfs_region))
5063 rd->dfs_region = dfs_region;
5064
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005065 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005066 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005067 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005068 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5069 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005070 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5071 if (r)
5072 goto bad_reg;
5073
5074 rule_idx++;
5075
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005076 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5077 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005078 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005079 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005080 }
5081
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005082 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005083 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005084 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005085
Johannes Bergd2372b32008-10-24 20:32:20 +02005086 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005087 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005088 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005089}
5090
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005091static int validate_scan_freqs(struct nlattr *freqs)
5092{
5093 struct nlattr *attr1, *attr2;
5094 int n_channels = 0, tmp1, tmp2;
5095
5096 nla_for_each_nested(attr1, freqs, tmp1) {
5097 n_channels++;
5098 /*
5099 * Some hardware has a limited channel list for
5100 * scanning, and it is pretty much nonsensical
5101 * to scan for a channel twice, so disallow that
5102 * and don't require drivers to check that the
5103 * channel list they get isn't longer than what
5104 * they can scan, as long as they can scan all
5105 * the channels they registered at once.
5106 */
5107 nla_for_each_nested(attr2, freqs, tmp2)
5108 if (attr1 != attr2 &&
5109 nla_get_u32(attr1) == nla_get_u32(attr2))
5110 return 0;
5111 }
5112
5113 return n_channels;
5114}
5115
Johannes Berg2a519312009-02-10 21:25:55 +01005116static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5117{
Johannes Berg4c476992010-10-04 21:36:35 +02005118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005119 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005120 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005121 struct nlattr *attr;
5122 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005123 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005124 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005125
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005126 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5127 return -EINVAL;
5128
Johannes Berg79c97e92009-07-07 03:56:12 +02005129 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005130
Johannes Berg4c476992010-10-04 21:36:35 +02005131 if (!rdev->ops->scan)
5132 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005133
Johannes Bergf9f47522013-03-19 15:04:07 +01005134 if (rdev->scan_req) {
5135 err = -EBUSY;
5136 goto unlock;
5137 }
Johannes Berg2a519312009-02-10 21:25:55 +01005138
5139 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005140 n_channels = validate_scan_freqs(
5141 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005142 if (!n_channels) {
5143 err = -EINVAL;
5144 goto unlock;
5145 }
Johannes Berg2a519312009-02-10 21:25:55 +01005146 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005147 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005148 n_channels = 0;
5149
Johannes Berg2a519312009-02-10 21:25:55 +01005150 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5151 if (wiphy->bands[band])
5152 n_channels += wiphy->bands[band]->n_channels;
5153 }
5154
5155 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5156 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5157 n_ssids++;
5158
Johannes Bergf9f47522013-03-19 15:04:07 +01005159 if (n_ssids > wiphy->max_scan_ssids) {
5160 err = -EINVAL;
5161 goto unlock;
5162 }
Johannes Berg2a519312009-02-10 21:25:55 +01005163
Jouni Malinen70692ad2009-02-16 19:39:13 +02005164 if (info->attrs[NL80211_ATTR_IE])
5165 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5166 else
5167 ie_len = 0;
5168
Johannes Bergf9f47522013-03-19 15:04:07 +01005169 if (ie_len > wiphy->max_scan_ie_len) {
5170 err = -EINVAL;
5171 goto unlock;
5172 }
Johannes Berg18a83652009-03-31 12:12:05 +02005173
Johannes Berg2a519312009-02-10 21:25:55 +01005174 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005175 + sizeof(*request->ssids) * n_ssids
5176 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005177 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005178 if (!request) {
5179 err = -ENOMEM;
5180 goto unlock;
5181 }
Johannes Berg2a519312009-02-10 21:25:55 +01005182
Johannes Berg2a519312009-02-10 21:25:55 +01005183 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005184 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005185 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005186 if (ie_len) {
5187 if (request->ssids)
5188 request->ie = (void *)(request->ssids + n_ssids);
5189 else
5190 request->ie = (void *)(request->channels + n_channels);
5191 }
Johannes Berg2a519312009-02-10 21:25:55 +01005192
Johannes Berg584991d2009-11-02 13:32:03 +01005193 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005194 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5195 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005196 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005197 struct ieee80211_channel *chan;
5198
5199 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5200
5201 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005202 err = -EINVAL;
5203 goto out_free;
5204 }
Johannes Berg584991d2009-11-02 13:32:03 +01005205
5206 /* ignore disabled channels */
5207 if (chan->flags & IEEE80211_CHAN_DISABLED)
5208 continue;
5209
5210 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005211 i++;
5212 }
5213 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005214 enum ieee80211_band band;
5215
Johannes Berg2a519312009-02-10 21:25:55 +01005216 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005217 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5218 int j;
5219 if (!wiphy->bands[band])
5220 continue;
5221 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005222 struct ieee80211_channel *chan;
5223
5224 chan = &wiphy->bands[band]->channels[j];
5225
5226 if (chan->flags & IEEE80211_CHAN_DISABLED)
5227 continue;
5228
5229 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005230 i++;
5231 }
5232 }
5233 }
5234
Johannes Berg584991d2009-11-02 13:32:03 +01005235 if (!i) {
5236 err = -EINVAL;
5237 goto out_free;
5238 }
5239
5240 request->n_channels = i;
5241
Johannes Berg2a519312009-02-10 21:25:55 +01005242 i = 0;
5243 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5244 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005245 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005246 err = -EINVAL;
5247 goto out_free;
5248 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005249 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005250 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005251 i++;
5252 }
5253 }
5254
Jouni Malinen70692ad2009-02-16 19:39:13 +02005255 if (info->attrs[NL80211_ATTR_IE]) {
5256 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005257 memcpy((void *)request->ie,
5258 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005259 request->ie_len);
5260 }
5261
Johannes Berg34850ab2011-07-18 18:08:35 +02005262 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005263 if (wiphy->bands[i])
5264 request->rates[i] =
5265 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005266
5267 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5268 nla_for_each_nested(attr,
5269 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5270 tmp) {
5271 enum ieee80211_band band = nla_type(attr);
5272
Dan Carpenter84404622011-07-29 11:52:18 +03005273 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005274 err = -EINVAL;
5275 goto out_free;
5276 }
5277 err = ieee80211_get_ratemask(wiphy->bands[band],
5278 nla_data(attr),
5279 nla_len(attr),
5280 &request->rates[band]);
5281 if (err)
5282 goto out_free;
5283 }
5284 }
5285
Sam Leffler46856bb2012-10-11 21:03:32 -07005286 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005287 request->flags = nla_get_u32(
5288 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005289 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5290 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5291 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5292 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005293 err = -EOPNOTSUPP;
5294 goto out_free;
5295 }
5296 }
Sam Lefflered4737712012-10-11 21:03:31 -07005297
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305298 request->no_cck =
5299 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5300
Johannes Bergfd014282012-06-18 19:17:03 +02005301 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005302 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005303 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005304
Johannes Berg79c97e92009-07-07 03:56:12 +02005305 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005306 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005307
Johannes Berg463d0182009-07-14 00:33:35 +02005308 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005309 nl80211_send_scan_start(rdev, wdev);
5310 if (wdev->netdev)
5311 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005312 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005313 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005314 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005315 kfree(request);
5316 }
Johannes Berg3b858752009-03-12 09:55:09 +01005317
Johannes Bergf9f47522013-03-19 15:04:07 +01005318 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005319 return err;
5320}
5321
Luciano Coelho807f8a82011-05-11 17:09:35 +03005322static int nl80211_start_sched_scan(struct sk_buff *skb,
5323 struct genl_info *info)
5324{
5325 struct cfg80211_sched_scan_request *request;
5326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5327 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005328 struct nlattr *attr;
5329 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005330 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005331 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005332 enum ieee80211_band band;
5333 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005334 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005335
5336 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5337 !rdev->ops->sched_scan_start)
5338 return -EOPNOTSUPP;
5339
5340 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5341 return -EINVAL;
5342
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005343 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5344 return -EINVAL;
5345
5346 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5347 if (interval == 0)
5348 return -EINVAL;
5349
Luciano Coelho807f8a82011-05-11 17:09:35 +03005350 wiphy = &rdev->wiphy;
5351
5352 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5353 n_channels = validate_scan_freqs(
5354 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5355 if (!n_channels)
5356 return -EINVAL;
5357 } else {
5358 n_channels = 0;
5359
5360 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5361 if (wiphy->bands[band])
5362 n_channels += wiphy->bands[band]->n_channels;
5363 }
5364
5365 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5366 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5367 tmp)
5368 n_ssids++;
5369
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005370 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005371 return -EINVAL;
5372
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005373 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5374 nla_for_each_nested(attr,
5375 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5376 tmp)
5377 n_match_sets++;
5378
5379 if (n_match_sets > wiphy->max_match_sets)
5380 return -EINVAL;
5381
Luciano Coelho807f8a82011-05-11 17:09:35 +03005382 if (info->attrs[NL80211_ATTR_IE])
5383 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5384 else
5385 ie_len = 0;
5386
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005387 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005388 return -EINVAL;
5389
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005390 if (rdev->sched_scan_req) {
5391 err = -EINPROGRESS;
5392 goto out;
5393 }
5394
Luciano Coelho807f8a82011-05-11 17:09:35 +03005395 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005396 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005397 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005398 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005399 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005400 if (!request) {
5401 err = -ENOMEM;
5402 goto out;
5403 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005404
5405 if (n_ssids)
5406 request->ssids = (void *)&request->channels[n_channels];
5407 request->n_ssids = n_ssids;
5408 if (ie_len) {
5409 if (request->ssids)
5410 request->ie = (void *)(request->ssids + n_ssids);
5411 else
5412 request->ie = (void *)(request->channels + n_channels);
5413 }
5414
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005415 if (n_match_sets) {
5416 if (request->ie)
5417 request->match_sets = (void *)(request->ie + ie_len);
5418 else if (request->ssids)
5419 request->match_sets =
5420 (void *)(request->ssids + n_ssids);
5421 else
5422 request->match_sets =
5423 (void *)(request->channels + n_channels);
5424 }
5425 request->n_match_sets = n_match_sets;
5426
Luciano Coelho807f8a82011-05-11 17:09:35 +03005427 i = 0;
5428 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5429 /* user specified, bail out if channel not found */
5430 nla_for_each_nested(attr,
5431 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5432 tmp) {
5433 struct ieee80211_channel *chan;
5434
5435 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5436
5437 if (!chan) {
5438 err = -EINVAL;
5439 goto out_free;
5440 }
5441
5442 /* ignore disabled channels */
5443 if (chan->flags & IEEE80211_CHAN_DISABLED)
5444 continue;
5445
5446 request->channels[i] = chan;
5447 i++;
5448 }
5449 } else {
5450 /* all channels */
5451 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5452 int j;
5453 if (!wiphy->bands[band])
5454 continue;
5455 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5456 struct ieee80211_channel *chan;
5457
5458 chan = &wiphy->bands[band]->channels[j];
5459
5460 if (chan->flags & IEEE80211_CHAN_DISABLED)
5461 continue;
5462
5463 request->channels[i] = chan;
5464 i++;
5465 }
5466 }
5467 }
5468
5469 if (!i) {
5470 err = -EINVAL;
5471 goto out_free;
5472 }
5473
5474 request->n_channels = i;
5475
5476 i = 0;
5477 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5478 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5479 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005480 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005481 err = -EINVAL;
5482 goto out_free;
5483 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005484 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005485 memcpy(request->ssids[i].ssid, nla_data(attr),
5486 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005487 i++;
5488 }
5489 }
5490
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005491 i = 0;
5492 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5493 nla_for_each_nested(attr,
5494 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5495 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005496 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005497
5498 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5499 nla_data(attr), nla_len(attr),
5500 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005501 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005502 if (ssid) {
5503 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5504 err = -EINVAL;
5505 goto out_free;
5506 }
5507 memcpy(request->match_sets[i].ssid.ssid,
5508 nla_data(ssid), nla_len(ssid));
5509 request->match_sets[i].ssid.ssid_len =
5510 nla_len(ssid);
5511 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005512 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5513 if (rssi)
5514 request->rssi_thold = nla_get_u32(rssi);
5515 else
5516 request->rssi_thold =
5517 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005518 i++;
5519 }
5520 }
5521
Luciano Coelho807f8a82011-05-11 17:09:35 +03005522 if (info->attrs[NL80211_ATTR_IE]) {
5523 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5524 memcpy((void *)request->ie,
5525 nla_data(info->attrs[NL80211_ATTR_IE]),
5526 request->ie_len);
5527 }
5528
Sam Leffler46856bb2012-10-11 21:03:32 -07005529 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005530 request->flags = nla_get_u32(
5531 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005532 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5533 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5534 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5535 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005536 err = -EOPNOTSUPP;
5537 goto out_free;
5538 }
5539 }
Sam Lefflered4737712012-10-11 21:03:31 -07005540
Luciano Coelho807f8a82011-05-11 17:09:35 +03005541 request->dev = dev;
5542 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005543 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005544 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005545
Hila Gonene35e4d22012-06-27 17:19:42 +03005546 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005547 if (!err) {
5548 rdev->sched_scan_req = request;
5549 nl80211_send_sched_scan(rdev, dev,
5550 NL80211_CMD_START_SCHED_SCAN);
5551 goto out;
5552 }
5553
5554out_free:
5555 kfree(request);
5556out:
5557 return err;
5558}
5559
5560static int nl80211_stop_sched_scan(struct sk_buff *skb,
5561 struct genl_info *info)
5562{
5563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5564
5565 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5566 !rdev->ops->sched_scan_stop)
5567 return -EOPNOTSUPP;
5568
Johannes Berg5fe231e2013-05-08 21:45:15 +02005569 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005570}
5571
Simon Wunderlich04f39042013-02-08 18:16:19 +01005572static int nl80211_start_radar_detection(struct sk_buff *skb,
5573 struct genl_info *info)
5574{
5575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5576 struct net_device *dev = info->user_ptr[1];
5577 struct wireless_dev *wdev = dev->ieee80211_ptr;
5578 struct cfg80211_chan_def chandef;
5579 int err;
5580
5581 err = nl80211_parse_chandef(rdev, info, &chandef);
5582 if (err)
5583 return err;
5584
5585 if (wdev->cac_started)
5586 return -EBUSY;
5587
5588 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5589 if (err < 0)
5590 return err;
5591
5592 if (err == 0)
5593 return -EINVAL;
5594
5595 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5596 return -EINVAL;
5597
5598 if (!rdev->ops->start_radar_detection)
5599 return -EOPNOTSUPP;
5600
Simon Wunderlich04f39042013-02-08 18:16:19 +01005601 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5602 chandef.chan, CHAN_MODE_SHARED,
5603 BIT(chandef.width));
5604 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005605 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005606
5607 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5608 if (!err) {
5609 wdev->channel = chandef.chan;
5610 wdev->cac_started = true;
5611 wdev->cac_start_time = jiffies;
5612 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005613 return err;
5614}
5615
Johannes Berg9720bb32011-06-21 09:45:33 +02005616static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5617 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005618 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005619 struct wireless_dev *wdev,
5620 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005621{
Johannes Berg48ab9052009-07-10 18:42:31 +02005622 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005623 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005624 void *hdr;
5625 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005626 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005627
5628 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005629
Eric W. Biederman15e47302012-09-07 20:12:54 +00005630 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005631 NL80211_CMD_NEW_SCAN_RESULTS);
5632 if (!hdr)
5633 return -1;
5634
Johannes Berg9720bb32011-06-21 09:45:33 +02005635 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5636
Johannes Berg97990a02013-04-19 01:02:55 +02005637 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5638 goto nla_put_failure;
5639 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005640 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5641 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005642 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5643 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005644
5645 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5646 if (!bss)
5647 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005648 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005649 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005650 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005651
5652 rcu_read_lock();
5653 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005654 if (ies) {
5655 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5656 goto fail_unlock_rcu;
5657 tsf = true;
5658 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5659 ies->len, ies->data))
5660 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005661 }
5662 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005663 if (ies) {
5664 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5665 goto fail_unlock_rcu;
5666 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5667 ies->len, ies->data))
5668 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005669 }
5670 rcu_read_unlock();
5671
David S. Miller9360ffd2012-03-29 04:41:26 -04005672 if (res->beacon_interval &&
5673 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5674 goto nla_put_failure;
5675 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5676 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005677 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005678 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5679 jiffies_to_msecs(jiffies - intbss->ts)))
5680 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005681
Johannes Berg77965c92009-02-18 18:45:06 +01005682 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005683 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005684 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5685 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005686 break;
5687 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005688 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5689 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005690 break;
5691 default:
5692 break;
5693 }
5694
Johannes Berg48ab9052009-07-10 18:42:31 +02005695 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005696 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005697 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005698 if (intbss == wdev->current_bss &&
5699 nla_put_u32(msg, NL80211_BSS_STATUS,
5700 NL80211_BSS_STATUS_ASSOCIATED))
5701 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005702 break;
5703 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005704 if (intbss == wdev->current_bss &&
5705 nla_put_u32(msg, NL80211_BSS_STATUS,
5706 NL80211_BSS_STATUS_IBSS_JOINED))
5707 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005708 break;
5709 default:
5710 break;
5711 }
5712
Johannes Berg2a519312009-02-10 21:25:55 +01005713 nla_nest_end(msg, bss);
5714
5715 return genlmsg_end(msg, hdr);
5716
Johannes Berg8cef2c92013-02-05 16:54:31 +01005717 fail_unlock_rcu:
5718 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005719 nla_put_failure:
5720 genlmsg_cancel(msg, hdr);
5721 return -EMSGSIZE;
5722}
5723
Johannes Berg97990a02013-04-19 01:02:55 +02005724static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005725{
Johannes Berg48ab9052009-07-10 18:42:31 +02005726 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005727 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005728 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005729 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005730 int err;
5731
Johannes Berg97990a02013-04-19 01:02:55 +02005732 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005733 if (err)
5734 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005735
Johannes Berg48ab9052009-07-10 18:42:31 +02005736 wdev_lock(wdev);
5737 spin_lock_bh(&rdev->bss_lock);
5738 cfg80211_bss_expire(rdev);
5739
Johannes Berg9720bb32011-06-21 09:45:33 +02005740 cb->seq = rdev->bss_generation;
5741
Johannes Berg48ab9052009-07-10 18:42:31 +02005742 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005743 if (++idx <= start)
5744 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005745 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005746 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005747 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005748 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005749 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005750 }
5751 }
5752
Johannes Berg48ab9052009-07-10 18:42:31 +02005753 spin_unlock_bh(&rdev->bss_lock);
5754 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005755
Johannes Berg97990a02013-04-19 01:02:55 +02005756 cb->args[2] = idx;
5757 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005758
Johannes Berg67748892010-10-04 21:14:06 +02005759 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005760}
5761
Eric W. Biederman15e47302012-09-07 20:12:54 +00005762static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005763 int flags, struct net_device *dev,
5764 struct survey_info *survey)
5765{
5766 void *hdr;
5767 struct nlattr *infoattr;
5768
Eric W. Biederman15e47302012-09-07 20:12:54 +00005769 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005770 NL80211_CMD_NEW_SURVEY_RESULTS);
5771 if (!hdr)
5772 return -ENOMEM;
5773
David S. Miller9360ffd2012-03-29 04:41:26 -04005774 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5775 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005776
5777 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5778 if (!infoattr)
5779 goto nla_put_failure;
5780
David S. Miller9360ffd2012-03-29 04:41:26 -04005781 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5782 survey->channel->center_freq))
5783 goto nla_put_failure;
5784
5785 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5786 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5787 goto nla_put_failure;
5788 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5789 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5790 goto nla_put_failure;
5791 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5792 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5793 survey->channel_time))
5794 goto nla_put_failure;
5795 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5796 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5797 survey->channel_time_busy))
5798 goto nla_put_failure;
5799 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5800 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5801 survey->channel_time_ext_busy))
5802 goto nla_put_failure;
5803 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5804 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5805 survey->channel_time_rx))
5806 goto nla_put_failure;
5807 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5808 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5809 survey->channel_time_tx))
5810 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005811
5812 nla_nest_end(msg, infoattr);
5813
5814 return genlmsg_end(msg, hdr);
5815
5816 nla_put_failure:
5817 genlmsg_cancel(msg, hdr);
5818 return -EMSGSIZE;
5819}
5820
5821static int nl80211_dump_survey(struct sk_buff *skb,
5822 struct netlink_callback *cb)
5823{
5824 struct survey_info survey;
5825 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005826 struct wireless_dev *wdev;
5827 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005828 int res;
5829
Johannes Berg97990a02013-04-19 01:02:55 +02005830 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005831 if (res)
5832 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005833
Johannes Berg97990a02013-04-19 01:02:55 +02005834 if (!wdev->netdev) {
5835 res = -EINVAL;
5836 goto out_err;
5837 }
5838
Holger Schurig61fa7132009-11-11 12:25:40 +01005839 if (!dev->ops->dump_survey) {
5840 res = -EOPNOTSUPP;
5841 goto out_err;
5842 }
5843
5844 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005845 struct ieee80211_channel *chan;
5846
Johannes Berg97990a02013-04-19 01:02:55 +02005847 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005848 if (res == -ENOENT)
5849 break;
5850 if (res)
5851 goto out_err;
5852
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005853 /* Survey without a channel doesn't make sense */
5854 if (!survey.channel) {
5855 res = -EINVAL;
5856 goto out;
5857 }
5858
5859 chan = ieee80211_get_channel(&dev->wiphy,
5860 survey.channel->center_freq);
5861 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5862 survey_idx++;
5863 continue;
5864 }
5865
Holger Schurig61fa7132009-11-11 12:25:40 +01005866 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005867 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005868 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005869 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005870 goto out;
5871 survey_idx++;
5872 }
5873
5874 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005875 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005876 res = skb->len;
5877 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005878 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005879 return res;
5880}
5881
Samuel Ortizb23aa672009-07-01 21:26:54 +02005882static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5883{
5884 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5885 NL80211_WPA_VERSION_2));
5886}
5887
Jouni Malinen636a5d32009-03-19 13:39:22 +02005888static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5889{
Johannes Berg4c476992010-10-04 21:36:35 +02005890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5891 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005892 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005893 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5894 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005895 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005896 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005897 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005898
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005899 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5900 return -EINVAL;
5901
5902 if (!info->attrs[NL80211_ATTR_MAC])
5903 return -EINVAL;
5904
Jouni Malinen17780922009-03-27 20:52:47 +02005905 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5906 return -EINVAL;
5907
Johannes Berg19957bb2009-07-02 17:20:43 +02005908 if (!info->attrs[NL80211_ATTR_SSID])
5909 return -EINVAL;
5910
5911 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5912 return -EINVAL;
5913
Johannes Bergfffd0932009-07-08 14:22:54 +02005914 err = nl80211_parse_key(info, &key);
5915 if (err)
5916 return err;
5917
5918 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005919 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5920 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005921 if (!key.p.key || !key.p.key_len)
5922 return -EINVAL;
5923 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5924 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5925 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5926 key.p.key_len != WLAN_KEY_LEN_WEP104))
5927 return -EINVAL;
5928 if (key.idx > 4)
5929 return -EINVAL;
5930 } else {
5931 key.p.key_len = 0;
5932 key.p.key = NULL;
5933 }
5934
Johannes Bergafea0b72010-08-10 09:46:42 +02005935 if (key.idx >= 0) {
5936 int i;
5937 bool ok = false;
5938 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5939 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5940 ok = true;
5941 break;
5942 }
5943 }
Johannes Berg4c476992010-10-04 21:36:35 +02005944 if (!ok)
5945 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005946 }
5947
Johannes Berg4c476992010-10-04 21:36:35 +02005948 if (!rdev->ops->auth)
5949 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005950
Johannes Berg074ac8d2010-09-16 14:58:22 +02005951 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005952 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5953 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005954
Johannes Berg19957bb2009-07-02 17:20:43 +02005955 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005956 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005957 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005958 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5959 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005960
Johannes Berg19957bb2009-07-02 17:20:43 +02005961 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5962 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5963
5964 if (info->attrs[NL80211_ATTR_IE]) {
5965 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5966 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5967 }
5968
5969 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005970 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005971 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005972
Jouni Malinene39e5b52012-09-30 19:29:39 +03005973 if (auth_type == NL80211_AUTHTYPE_SAE &&
5974 !info->attrs[NL80211_ATTR_SAE_DATA])
5975 return -EINVAL;
5976
5977 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5978 if (auth_type != NL80211_AUTHTYPE_SAE)
5979 return -EINVAL;
5980 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5981 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5982 /* need to include at least Auth Transaction and Status Code */
5983 if (sae_data_len < 4)
5984 return -EINVAL;
5985 }
5986
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005987 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5988
Johannes Berg95de8172012-01-20 13:55:25 +01005989 /*
5990 * Since we no longer track auth state, ignore
5991 * requests to only change local state.
5992 */
5993 if (local_state_change)
5994 return 0;
5995
Johannes Berg91bf9b22013-05-15 17:44:01 +02005996 wdev_lock(dev->ieee80211_ptr);
5997 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5998 ssid, ssid_len, ie, ie_len,
5999 key.p.key, key.p.key_len, key.idx,
6000 sae_data, sae_data_len);
6001 wdev_unlock(dev->ieee80211_ptr);
6002 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006003}
6004
Johannes Bergc0692b82010-08-27 14:26:53 +03006005static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6006 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006007 struct cfg80211_crypto_settings *settings,
6008 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006009{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006010 memset(settings, 0, sizeof(*settings));
6011
Samuel Ortizb23aa672009-07-01 21:26:54 +02006012 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6013
Johannes Bergc0692b82010-08-27 14:26:53 +03006014 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6015 u16 proto;
6016 proto = nla_get_u16(
6017 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6018 settings->control_port_ethertype = cpu_to_be16(proto);
6019 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6020 proto != ETH_P_PAE)
6021 return -EINVAL;
6022 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6023 settings->control_port_no_encrypt = true;
6024 } else
6025 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6026
Samuel Ortizb23aa672009-07-01 21:26:54 +02006027 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6028 void *data;
6029 int len, i;
6030
6031 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6032 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6033 settings->n_ciphers_pairwise = len / sizeof(u32);
6034
6035 if (len % sizeof(u32))
6036 return -EINVAL;
6037
Johannes Berg3dc27d22009-07-02 21:36:37 +02006038 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006039 return -EINVAL;
6040
6041 memcpy(settings->ciphers_pairwise, data, len);
6042
6043 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006044 if (!cfg80211_supported_cipher_suite(
6045 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006046 settings->ciphers_pairwise[i]))
6047 return -EINVAL;
6048 }
6049
6050 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6051 settings->cipher_group =
6052 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006053 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6054 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006055 return -EINVAL;
6056 }
6057
6058 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6059 settings->wpa_versions =
6060 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6061 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6062 return -EINVAL;
6063 }
6064
6065 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6066 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006067 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006068
6069 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6070 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6071 settings->n_akm_suites = len / sizeof(u32);
6072
6073 if (len % sizeof(u32))
6074 return -EINVAL;
6075
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006076 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6077 return -EINVAL;
6078
Samuel Ortizb23aa672009-07-01 21:26:54 +02006079 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006080 }
6081
6082 return 0;
6083}
6084
Jouni Malinen636a5d32009-03-19 13:39:22 +02006085static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6086{
Johannes Berg4c476992010-10-04 21:36:35 +02006087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6088 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006089 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006090 struct cfg80211_assoc_request req = {};
6091 const u8 *bssid, *ssid;
6092 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006093
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006094 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6095 return -EINVAL;
6096
6097 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006098 !info->attrs[NL80211_ATTR_SSID] ||
6099 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006100 return -EINVAL;
6101
Johannes Berg4c476992010-10-04 21:36:35 +02006102 if (!rdev->ops->assoc)
6103 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006104
Johannes Berg074ac8d2010-09-16 14:58:22 +02006105 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006106 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6107 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006108
Johannes Berg19957bb2009-07-02 17:20:43 +02006109 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006110
Johannes Berg19957bb2009-07-02 17:20:43 +02006111 chan = ieee80211_get_channel(&rdev->wiphy,
6112 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006113 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6114 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006115
Johannes Berg19957bb2009-07-02 17:20:43 +02006116 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6117 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006118
6119 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006120 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6121 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006122 }
6123
Jouni Malinendc6382c2009-05-06 22:09:37 +03006124 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006125 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006126 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006127 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006128 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006129 else if (mfp != NL80211_MFP_NO)
6130 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006131 }
6132
Johannes Berg3e5d7642009-07-07 14:37:26 +02006133 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006134 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006135
Ben Greear7e7c8922011-11-18 11:31:59 -08006136 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006137 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006138
6139 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006140 memcpy(&req.ht_capa_mask,
6141 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6142 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006143
6144 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006145 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006146 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006147 memcpy(&req.ht_capa,
6148 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6149 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006150 }
6151
Johannes Bergee2aca32013-02-21 17:36:01 +01006152 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006153 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006154
6155 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006156 memcpy(&req.vht_capa_mask,
6157 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6158 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006159
6160 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006161 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006162 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006163 memcpy(&req.vht_capa,
6164 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6165 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006166 }
6167
Johannes Bergf62fab72013-02-21 20:09:09 +01006168 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006169 if (!err) {
6170 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006171 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6172 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006173 wdev_unlock(dev->ieee80211_ptr);
6174 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006175
Jouni Malinen636a5d32009-03-19 13:39:22 +02006176 return err;
6177}
6178
6179static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6180{
Johannes Berg4c476992010-10-04 21:36:35 +02006181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6182 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006183 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006184 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006185 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006186 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006187
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006188 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6189 return -EINVAL;
6190
6191 if (!info->attrs[NL80211_ATTR_MAC])
6192 return -EINVAL;
6193
6194 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6195 return -EINVAL;
6196
Johannes Berg4c476992010-10-04 21:36:35 +02006197 if (!rdev->ops->deauth)
6198 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006199
Johannes Berg074ac8d2010-09-16 14:58:22 +02006200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6202 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006203
Johannes Berg19957bb2009-07-02 17:20:43 +02006204 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006205
Johannes Berg19957bb2009-07-02 17:20:43 +02006206 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6207 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006208 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006209 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006210 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006211
6212 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006213 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6214 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006215 }
6216
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006217 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6218
Johannes Berg91bf9b22013-05-15 17:44:01 +02006219 wdev_lock(dev->ieee80211_ptr);
6220 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6221 local_state_change);
6222 wdev_unlock(dev->ieee80211_ptr);
6223 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006224}
6225
6226static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6227{
Johannes Berg4c476992010-10-04 21:36:35 +02006228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6229 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006230 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006231 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006232 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006233 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006234
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006235 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6236 return -EINVAL;
6237
6238 if (!info->attrs[NL80211_ATTR_MAC])
6239 return -EINVAL;
6240
6241 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6242 return -EINVAL;
6243
Johannes Berg4c476992010-10-04 21:36:35 +02006244 if (!rdev->ops->disassoc)
6245 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006246
Johannes Berg074ac8d2010-09-16 14:58:22 +02006247 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006248 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6249 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006250
Johannes Berg19957bb2009-07-02 17:20:43 +02006251 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006252
Johannes Berg19957bb2009-07-02 17:20:43 +02006253 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6254 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006255 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006256 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006257 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006258
6259 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006260 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6261 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006262 }
6263
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006264 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6265
Johannes Berg91bf9b22013-05-15 17:44:01 +02006266 wdev_lock(dev->ieee80211_ptr);
6267 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6268 local_state_change);
6269 wdev_unlock(dev->ieee80211_ptr);
6270 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006271}
6272
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006273static bool
6274nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6275 int mcast_rate[IEEE80211_NUM_BANDS],
6276 int rateval)
6277{
6278 struct wiphy *wiphy = &rdev->wiphy;
6279 bool found = false;
6280 int band, i;
6281
6282 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6283 struct ieee80211_supported_band *sband;
6284
6285 sband = wiphy->bands[band];
6286 if (!sband)
6287 continue;
6288
6289 for (i = 0; i < sband->n_bitrates; i++) {
6290 if (sband->bitrates[i].bitrate == rateval) {
6291 mcast_rate[band] = i + 1;
6292 found = true;
6293 break;
6294 }
6295 }
6296 }
6297
6298 return found;
6299}
6300
Johannes Berg04a773a2009-04-19 21:24:32 +02006301static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6302{
Johannes Berg4c476992010-10-04 21:36:35 +02006303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6304 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006305 struct cfg80211_ibss_params ibss;
6306 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006307 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006308 int err;
6309
Johannes Berg8e30bc52009-04-22 17:45:38 +02006310 memset(&ibss, 0, sizeof(ibss));
6311
Johannes Berg04a773a2009-04-19 21:24:32 +02006312 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6313 return -EINVAL;
6314
Johannes Berg683b6d32012-11-08 21:25:48 +01006315 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006316 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6317 return -EINVAL;
6318
Johannes Berg8e30bc52009-04-22 17:45:38 +02006319 ibss.beacon_interval = 100;
6320
6321 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6322 ibss.beacon_interval =
6323 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6324 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6325 return -EINVAL;
6326 }
6327
Johannes Berg4c476992010-10-04 21:36:35 +02006328 if (!rdev->ops->join_ibss)
6329 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006330
Johannes Berg4c476992010-10-04 21:36:35 +02006331 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6332 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006333
Johannes Berg79c97e92009-07-07 03:56:12 +02006334 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006335
Johannes Berg39193492011-09-16 13:45:25 +02006336 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006337 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006338
6339 if (!is_valid_ether_addr(ibss.bssid))
6340 return -EINVAL;
6341 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006342 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6343 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6344
6345 if (info->attrs[NL80211_ATTR_IE]) {
6346 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6347 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6348 }
6349
Johannes Berg683b6d32012-11-08 21:25:48 +01006350 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6351 if (err)
6352 return err;
Alexander Simon54858ee2011-11-30 16:56:32 +01006353
Johannes Berg683b6d32012-11-08 21:25:48 +01006354 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee2011-11-30 16:56:32 +01006355 return -EINVAL;
6356
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006357 switch (ibss.chandef.width) {
6358 case NL80211_CHAN_WIDTH_20_NOHT:
6359 break;
6360 case NL80211_CHAN_WIDTH_20:
6361 case NL80211_CHAN_WIDTH_40:
6362 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6363 break;
6364 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006365 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006366 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006367
Johannes Berg04a773a2009-04-19 21:24:32 +02006368 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006369 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006370
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006371 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6372 u8 *rates =
6373 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6374 int n_rates =
6375 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6376 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006377 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006378
Johannes Berg34850ab2011-07-18 18:08:35 +02006379 err = ieee80211_get_ratemask(sband, rates, n_rates,
6380 &ibss.basic_rates);
6381 if (err)
6382 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006383 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006384
Simon Wunderlich803768f2013-06-28 10:39:58 +02006385 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6386 memcpy(&ibss.ht_capa_mask,
6387 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6388 sizeof(ibss.ht_capa_mask));
6389
6390 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6391 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6392 return -EINVAL;
6393 memcpy(&ibss.ht_capa,
6394 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6395 sizeof(ibss.ht_capa));
6396 }
6397
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006398 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6399 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6400 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6401 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006402
Johannes Berg4c476992010-10-04 21:36:35 +02006403 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306404 bool no_ht = false;
6405
Johannes Berg4c476992010-10-04 21:36:35 +02006406 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306407 info->attrs[NL80211_ATTR_KEYS],
6408 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006409 if (IS_ERR(connkeys))
6410 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306411
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006412 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6413 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306414 kfree(connkeys);
6415 return -EINVAL;
6416 }
Johannes Berg4c476992010-10-04 21:36:35 +02006417 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006418
Antonio Quartulli267335d2012-01-31 20:25:47 +01006419 ibss.control_port =
6420 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6421
Johannes Berg4c476992010-10-04 21:36:35 +02006422 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006423 if (err)
6424 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006425 return err;
6426}
6427
6428static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6429{
Johannes Berg4c476992010-10-04 21:36:35 +02006430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6431 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006432
Johannes Berg4c476992010-10-04 21:36:35 +02006433 if (!rdev->ops->leave_ibss)
6434 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006435
Johannes Berg4c476992010-10-04 21:36:35 +02006436 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6437 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006438
Johannes Berg4c476992010-10-04 21:36:35 +02006439 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006440}
6441
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006442static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6443{
6444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6445 struct net_device *dev = info->user_ptr[1];
6446 int mcast_rate[IEEE80211_NUM_BANDS];
6447 u32 nla_rate;
6448 int err;
6449
6450 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6451 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6452 return -EOPNOTSUPP;
6453
6454 if (!rdev->ops->set_mcast_rate)
6455 return -EOPNOTSUPP;
6456
6457 memset(mcast_rate, 0, sizeof(mcast_rate));
6458
6459 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6460 return -EINVAL;
6461
6462 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6463 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6464 return -EINVAL;
6465
6466 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6467
6468 return err;
6469}
6470
6471
Johannes Bergaff89a92009-07-01 21:26:51 +02006472#ifdef CONFIG_NL80211_TESTMODE
6473static struct genl_multicast_group nl80211_testmode_mcgrp = {
6474 .name = "testmode",
6475};
6476
6477static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6478{
Johannes Berg4c476992010-10-04 21:36:35 +02006479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006480 int err;
6481
6482 if (!info->attrs[NL80211_ATTR_TESTDATA])
6483 return -EINVAL;
6484
Johannes Bergaff89a92009-07-01 21:26:51 +02006485 err = -EOPNOTSUPP;
6486 if (rdev->ops->testmode_cmd) {
6487 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006488 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006489 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6490 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6491 rdev->testmode_info = NULL;
6492 }
6493
Johannes Bergaff89a92009-07-01 21:26:51 +02006494 return err;
6495}
6496
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006497static int nl80211_testmode_dump(struct sk_buff *skb,
6498 struct netlink_callback *cb)
6499{
Johannes Berg00918d32011-12-13 17:22:05 +01006500 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006501 int err;
6502 long phy_idx;
6503 void *data = NULL;
6504 int data_len = 0;
6505
Johannes Berg5fe231e2013-05-08 21:45:15 +02006506 rtnl_lock();
6507
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006508 if (cb->args[0]) {
6509 /*
6510 * 0 is a valid index, but not valid for args[0],
6511 * so we need to offset by 1.
6512 */
6513 phy_idx = cb->args[0] - 1;
6514 } else {
6515 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6516 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6517 nl80211_policy);
6518 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006519 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006520
Johannes Berg2bd7e352012-06-15 14:23:16 +02006521 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6522 nl80211_fam.attrbuf);
6523 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006524 err = PTR_ERR(rdev);
6525 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006526 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006527 phy_idx = rdev->wiphy_idx;
6528 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006529
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006530 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6531 cb->args[1] =
6532 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6533 }
6534
6535 if (cb->args[1]) {
6536 data = nla_data((void *)cb->args[1]);
6537 data_len = nla_len((void *)cb->args[1]);
6538 }
6539
Johannes Berg00918d32011-12-13 17:22:05 +01006540 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6541 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006542 err = -ENOENT;
6543 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006544 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006545
Johannes Berg00918d32011-12-13 17:22:05 +01006546 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006547 err = -EOPNOTSUPP;
6548 goto out_err;
6549 }
6550
6551 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006552 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6554 NL80211_CMD_TESTMODE);
6555 struct nlattr *tmdata;
6556
David S. Miller9360ffd2012-03-29 04:41:26 -04006557 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006558 genlmsg_cancel(skb, hdr);
6559 break;
6560 }
6561
6562 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6563 if (!tmdata) {
6564 genlmsg_cancel(skb, hdr);
6565 break;
6566 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006567 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006568 nla_nest_end(skb, tmdata);
6569
6570 if (err == -ENOBUFS || err == -ENOENT) {
6571 genlmsg_cancel(skb, hdr);
6572 break;
6573 } else if (err) {
6574 genlmsg_cancel(skb, hdr);
6575 goto out_err;
6576 }
6577
6578 genlmsg_end(skb, hdr);
6579 }
6580
6581 err = skb->len;
6582 /* see above */
6583 cb->args[0] = phy_idx + 1;
6584 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006585 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006586 return err;
6587}
6588
Johannes Bergaff89a92009-07-01 21:26:51 +02006589static struct sk_buff *
6590__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006591 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006592{
6593 struct sk_buff *skb;
6594 void *hdr;
6595 struct nlattr *data;
6596
6597 skb = nlmsg_new(approxlen + 100, gfp);
6598 if (!skb)
6599 return NULL;
6600
Eric W. Biederman15e47302012-09-07 20:12:54 +00006601 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006602 if (!hdr) {
6603 kfree_skb(skb);
6604 return NULL;
6605 }
6606
David S. Miller9360ffd2012-03-29 04:41:26 -04006607 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6608 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006609 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6610
6611 ((void **)skb->cb)[0] = rdev;
6612 ((void **)skb->cb)[1] = hdr;
6613 ((void **)skb->cb)[2] = data;
6614
6615 return skb;
6616
6617 nla_put_failure:
6618 kfree_skb(skb);
6619 return NULL;
6620}
6621
6622struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6623 int approxlen)
6624{
6625 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6626
6627 if (WARN_ON(!rdev->testmode_info))
6628 return NULL;
6629
6630 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006631 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006632 rdev->testmode_info->snd_seq,
6633 GFP_KERNEL);
6634}
6635EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6636
6637int cfg80211_testmode_reply(struct sk_buff *skb)
6638{
6639 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6640 void *hdr = ((void **)skb->cb)[1];
6641 struct nlattr *data = ((void **)skb->cb)[2];
6642
6643 if (WARN_ON(!rdev->testmode_info)) {
6644 kfree_skb(skb);
6645 return -EINVAL;
6646 }
6647
6648 nla_nest_end(skb, data);
6649 genlmsg_end(skb, hdr);
6650 return genlmsg_reply(skb, rdev->testmode_info);
6651}
6652EXPORT_SYMBOL(cfg80211_testmode_reply);
6653
6654struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6655 int approxlen, gfp_t gfp)
6656{
6657 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6658
6659 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6660}
6661EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6662
6663void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6664{
6665 void *hdr = ((void **)skb->cb)[1];
6666 struct nlattr *data = ((void **)skb->cb)[2];
6667
6668 nla_nest_end(skb, data);
6669 genlmsg_end(skb, hdr);
6670 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6671}
6672EXPORT_SYMBOL(cfg80211_testmode_event);
6673#endif
6674
Samuel Ortizb23aa672009-07-01 21:26:54 +02006675static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6676{
Johannes Berg4c476992010-10-04 21:36:35 +02006677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6678 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006679 struct cfg80211_connect_params connect;
6680 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006681 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006682 int err;
6683
6684 memset(&connect, 0, sizeof(connect));
6685
6686 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6687 return -EINVAL;
6688
6689 if (!info->attrs[NL80211_ATTR_SSID] ||
6690 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6691 return -EINVAL;
6692
6693 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6694 connect.auth_type =
6695 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006696 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6697 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006698 return -EINVAL;
6699 } else
6700 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6701
6702 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6703
Johannes Bergc0692b82010-08-27 14:26:53 +03006704 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006705 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006706 if (err)
6707 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006708
Johannes Berg074ac8d2010-09-16 14:58:22 +02006709 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006710 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6711 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006712
Johannes Berg79c97e92009-07-07 03:56:12 +02006713 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006714
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306715 connect.bg_scan_period = -1;
6716 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6717 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6718 connect.bg_scan_period =
6719 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6720 }
6721
Samuel Ortizb23aa672009-07-01 21:26:54 +02006722 if (info->attrs[NL80211_ATTR_MAC])
6723 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6724 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6725 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6726
6727 if (info->attrs[NL80211_ATTR_IE]) {
6728 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6729 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6730 }
6731
Jouni Malinencee00a92013-01-15 17:15:57 +02006732 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6733 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6734 if (connect.mfp != NL80211_MFP_REQUIRED &&
6735 connect.mfp != NL80211_MFP_NO)
6736 return -EINVAL;
6737 } else {
6738 connect.mfp = NL80211_MFP_NO;
6739 }
6740
Samuel Ortizb23aa672009-07-01 21:26:54 +02006741 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6742 connect.channel =
6743 ieee80211_get_channel(wiphy,
6744 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6745 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006746 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6747 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006748 }
6749
Johannes Bergfffd0932009-07-08 14:22:54 +02006750 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6751 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306752 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006753 if (IS_ERR(connkeys))
6754 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006755 }
6756
Ben Greear7e7c8922011-11-18 11:31:59 -08006757 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6758 connect.flags |= ASSOC_REQ_DISABLE_HT;
6759
6760 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6761 memcpy(&connect.ht_capa_mask,
6762 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6763 sizeof(connect.ht_capa_mask));
6764
6765 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006766 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6767 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006768 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006769 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006770 memcpy(&connect.ht_capa,
6771 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6772 sizeof(connect.ht_capa));
6773 }
6774
Johannes Bergee2aca32013-02-21 17:36:01 +01006775 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6776 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6777
6778 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6779 memcpy(&connect.vht_capa_mask,
6780 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6781 sizeof(connect.vht_capa_mask));
6782
6783 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6784 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6785 kfree(connkeys);
6786 return -EINVAL;
6787 }
6788 memcpy(&connect.vht_capa,
6789 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6790 sizeof(connect.vht_capa));
6791 }
6792
Johannes Berg83739b02013-05-15 17:44:01 +02006793 wdev_lock(dev->ieee80211_ptr);
6794 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6795 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006796 if (err)
6797 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006798 return err;
6799}
6800
6801static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6802{
Johannes Berg4c476992010-10-04 21:36:35 +02006803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6804 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006805 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006806 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006807
6808 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6809 reason = WLAN_REASON_DEAUTH_LEAVING;
6810 else
6811 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6812
6813 if (reason == 0)
6814 return -EINVAL;
6815
Johannes Berg074ac8d2010-09-16 14:58:22 +02006816 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006817 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6818 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006819
Johannes Berg83739b02013-05-15 17:44:01 +02006820 wdev_lock(dev->ieee80211_ptr);
6821 ret = cfg80211_disconnect(rdev, dev, reason, true);
6822 wdev_unlock(dev->ieee80211_ptr);
6823 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006824}
6825
Johannes Berg463d0182009-07-14 00:33:35 +02006826static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6827{
Johannes Berg4c476992010-10-04 21:36:35 +02006828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006829 struct net *net;
6830 int err;
6831 u32 pid;
6832
6833 if (!info->attrs[NL80211_ATTR_PID])
6834 return -EINVAL;
6835
6836 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6837
Johannes Berg463d0182009-07-14 00:33:35 +02006838 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006839 if (IS_ERR(net))
6840 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006841
6842 err = 0;
6843
6844 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006845 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6846 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006847
Johannes Berg463d0182009-07-14 00:33:35 +02006848 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006849 return err;
6850}
6851
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006852static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6853{
Johannes Berg4c476992010-10-04 21:36:35 +02006854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006855 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6856 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006857 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006858 struct cfg80211_pmksa pmksa;
6859
6860 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6861
6862 if (!info->attrs[NL80211_ATTR_MAC])
6863 return -EINVAL;
6864
6865 if (!info->attrs[NL80211_ATTR_PMKID])
6866 return -EINVAL;
6867
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006868 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6869 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6870
Johannes Berg074ac8d2010-09-16 14:58:22 +02006871 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006872 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6873 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006874
6875 switch (info->genlhdr->cmd) {
6876 case NL80211_CMD_SET_PMKSA:
6877 rdev_ops = rdev->ops->set_pmksa;
6878 break;
6879 case NL80211_CMD_DEL_PMKSA:
6880 rdev_ops = rdev->ops->del_pmksa;
6881 break;
6882 default:
6883 WARN_ON(1);
6884 break;
6885 }
6886
Johannes Berg4c476992010-10-04 21:36:35 +02006887 if (!rdev_ops)
6888 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006889
Johannes Berg4c476992010-10-04 21:36:35 +02006890 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006891}
6892
6893static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6894{
Johannes Berg4c476992010-10-04 21:36:35 +02006895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6896 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006897
Johannes Berg074ac8d2010-09-16 14:58:22 +02006898 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006899 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6900 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006901
Johannes Berg4c476992010-10-04 21:36:35 +02006902 if (!rdev->ops->flush_pmksa)
6903 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006904
Hila Gonene35e4d22012-06-27 17:19:42 +03006905 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006906}
6907
Arik Nemtsov109086c2011-09-28 14:12:50 +03006908static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6909{
6910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6911 struct net_device *dev = info->user_ptr[1];
6912 u8 action_code, dialog_token;
6913 u16 status_code;
6914 u8 *peer;
6915
6916 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6917 !rdev->ops->tdls_mgmt)
6918 return -EOPNOTSUPP;
6919
6920 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6921 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6922 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6923 !info->attrs[NL80211_ATTR_IE] ||
6924 !info->attrs[NL80211_ATTR_MAC])
6925 return -EINVAL;
6926
6927 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6928 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6929 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6930 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6931
Hila Gonene35e4d22012-06-27 17:19:42 +03006932 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6933 dialog_token, status_code,
6934 nla_data(info->attrs[NL80211_ATTR_IE]),
6935 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006936}
6937
6938static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6939{
6940 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6941 struct net_device *dev = info->user_ptr[1];
6942 enum nl80211_tdls_operation operation;
6943 u8 *peer;
6944
6945 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6946 !rdev->ops->tdls_oper)
6947 return -EOPNOTSUPP;
6948
6949 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6950 !info->attrs[NL80211_ATTR_MAC])
6951 return -EINVAL;
6952
6953 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6954 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6955
Hila Gonene35e4d22012-06-27 17:19:42 +03006956 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006957}
6958
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006959static int nl80211_remain_on_channel(struct sk_buff *skb,
6960 struct genl_info *info)
6961{
Johannes Berg4c476992010-10-04 21:36:35 +02006962 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006963 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006964 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006965 struct sk_buff *msg;
6966 void *hdr;
6967 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006968 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006969 int err;
6970
6971 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6972 !info->attrs[NL80211_ATTR_DURATION])
6973 return -EINVAL;
6974
6975 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6976
Johannes Berg7c4ef712011-11-18 15:33:48 +01006977 if (!rdev->ops->remain_on_channel ||
6978 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006979 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006980
Johannes Bergebf348f2012-06-01 12:50:54 +02006981 /*
6982 * We should be on that channel for at least a minimum amount of
6983 * time (10ms) but no longer than the driver supports.
6984 */
6985 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6986 duration > rdev->wiphy.max_remain_on_channel_duration)
6987 return -EINVAL;
6988
Johannes Berg683b6d32012-11-08 21:25:48 +01006989 err = nl80211_parse_chandef(rdev, info, &chandef);
6990 if (err)
6991 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006992
6993 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006994 if (!msg)
6995 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006996
Eric W. Biederman15e47302012-09-07 20:12:54 +00006997 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006998 NL80211_CMD_REMAIN_ON_CHANNEL);
6999
7000 if (IS_ERR(hdr)) {
7001 err = PTR_ERR(hdr);
7002 goto free_msg;
7003 }
7004
Johannes Berg683b6d32012-11-08 21:25:48 +01007005 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7006 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007007
7008 if (err)
7009 goto free_msg;
7010
David S. Miller9360ffd2012-03-29 04:41:26 -04007011 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7012 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007013
7014 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007015
7016 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007017
7018 nla_put_failure:
7019 err = -ENOBUFS;
7020 free_msg:
7021 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007022 return err;
7023}
7024
7025static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7026 struct genl_info *info)
7027{
Johannes Berg4c476992010-10-04 21:36:35 +02007028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007029 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007030 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007031
7032 if (!info->attrs[NL80211_ATTR_COOKIE])
7033 return -EINVAL;
7034
Johannes Berg4c476992010-10-04 21:36:35 +02007035 if (!rdev->ops->cancel_remain_on_channel)
7036 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007037
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007038 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7039
Hila Gonene35e4d22012-06-27 17:19:42 +03007040 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007041}
7042
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007043static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7044 u8 *rates, u8 rates_len)
7045{
7046 u8 i;
7047 u32 mask = 0;
7048
7049 for (i = 0; i < rates_len; i++) {
7050 int rate = (rates[i] & 0x7f) * 5;
7051 int ridx;
7052 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7053 struct ieee80211_rate *srate =
7054 &sband->bitrates[ridx];
7055 if (rate == srate->bitrate) {
7056 mask |= 1 << ridx;
7057 break;
7058 }
7059 }
7060 if (ridx == sband->n_bitrates)
7061 return 0; /* rate not found */
7062 }
7063
7064 return mask;
7065}
7066
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007067static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7068 u8 *rates, u8 rates_len,
7069 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7070{
7071 u8 i;
7072
7073 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7074
7075 for (i = 0; i < rates_len; i++) {
7076 int ridx, rbit;
7077
7078 ridx = rates[i] / 8;
7079 rbit = BIT(rates[i] % 8);
7080
7081 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007082 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007083 return false;
7084
7085 /* check availability */
7086 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7087 mcs[ridx] |= rbit;
7088 else
7089 return false;
7090 }
7091
7092 return true;
7093}
7094
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007095static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007096 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7097 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007098 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7099 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007100};
7101
7102static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7103 struct genl_info *info)
7104{
7105 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007107 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007108 int rem, i;
7109 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007110 struct nlattr *tx_rates;
7111 struct ieee80211_supported_band *sband;
7112
7113 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7114 return -EINVAL;
7115
Johannes Berg4c476992010-10-04 21:36:35 +02007116 if (!rdev->ops->set_bitrate_mask)
7117 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007118
7119 memset(&mask, 0, sizeof(mask));
7120 /* Default to all rates enabled */
7121 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7122 sband = rdev->wiphy.bands[i];
7123 mask.control[i].legacy =
7124 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007125 if (sband)
7126 memcpy(mask.control[i].mcs,
7127 sband->ht_cap.mcs.rx_mask,
7128 sizeof(mask.control[i].mcs));
7129 else
7130 memset(mask.control[i].mcs, 0,
7131 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007132 }
7133
7134 /*
7135 * The nested attribute uses enum nl80211_band as the index. This maps
7136 * directly to the enum ieee80211_band values used in cfg80211.
7137 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007138 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007139 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7140 {
7141 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007142 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7143 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007144 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007145 if (sband == NULL)
7146 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007147 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7148 nla_len(tx_rates), nl80211_txattr_policy);
7149 if (tb[NL80211_TXRATE_LEGACY]) {
7150 mask.control[band].legacy = rateset_to_mask(
7151 sband,
7152 nla_data(tb[NL80211_TXRATE_LEGACY]),
7153 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307154 if ((mask.control[band].legacy == 0) &&
7155 nla_len(tb[NL80211_TXRATE_LEGACY]))
7156 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007157 }
7158 if (tb[NL80211_TXRATE_MCS]) {
7159 if (!ht_rateset_to_mask(
7160 sband,
7161 nla_data(tb[NL80211_TXRATE_MCS]),
7162 nla_len(tb[NL80211_TXRATE_MCS]),
7163 mask.control[band].mcs))
7164 return -EINVAL;
7165 }
7166
7167 if (mask.control[band].legacy == 0) {
7168 /* don't allow empty legacy rates if HT
7169 * is not even supported. */
7170 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7171 return -EINVAL;
7172
7173 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7174 if (mask.control[band].mcs[i])
7175 break;
7176
7177 /* legacy and mcs rates may not be both empty */
7178 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007179 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007180 }
7181 }
7182
Hila Gonene35e4d22012-06-27 17:19:42 +03007183 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007184}
7185
Johannes Berg2e161f72010-08-12 15:38:38 +02007186static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007187{
Johannes Berg4c476992010-10-04 21:36:35 +02007188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007189 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007190 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007191
7192 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7193 return -EINVAL;
7194
Johannes Berg2e161f72010-08-12 15:38:38 +02007195 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7196 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007197
Johannes Berg71bbc992012-06-15 15:30:18 +02007198 switch (wdev->iftype) {
7199 case NL80211_IFTYPE_STATION:
7200 case NL80211_IFTYPE_ADHOC:
7201 case NL80211_IFTYPE_P2P_CLIENT:
7202 case NL80211_IFTYPE_AP:
7203 case NL80211_IFTYPE_AP_VLAN:
7204 case NL80211_IFTYPE_MESH_POINT:
7205 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007206 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007207 break;
7208 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007209 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007210 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007211
7212 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007213 if (!rdev->ops->mgmt_tx)
7214 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007215
Eric W. Biederman15e47302012-09-07 20:12:54 +00007216 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007217 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7218 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007219}
7220
Johannes Berg2e161f72010-08-12 15:38:38 +02007221static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007222{
Johannes Berg4c476992010-10-04 21:36:35 +02007223 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007224 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007225 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007226 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007227 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007228 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007229 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007230 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007231 bool offchan, no_cck, dont_wait_for_ack;
7232
7233 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007234
Johannes Berg683b6d32012-11-08 21:25:48 +01007235 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007236 return -EINVAL;
7237
Johannes Berg4c476992010-10-04 21:36:35 +02007238 if (!rdev->ops->mgmt_tx)
7239 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007240
Johannes Berg71bbc992012-06-15 15:30:18 +02007241 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007242 case NL80211_IFTYPE_P2P_DEVICE:
7243 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7244 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007245 case NL80211_IFTYPE_STATION:
7246 case NL80211_IFTYPE_ADHOC:
7247 case NL80211_IFTYPE_P2P_CLIENT:
7248 case NL80211_IFTYPE_AP:
7249 case NL80211_IFTYPE_AP_VLAN:
7250 case NL80211_IFTYPE_MESH_POINT:
7251 case NL80211_IFTYPE_P2P_GO:
7252 break;
7253 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007254 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007255 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007256
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007257 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007258 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007259 return -EINVAL;
7260 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007261
7262 /*
7263 * We should wait on the channel for at least a minimum amount
7264 * of time (10ms) but no longer than the driver supports.
7265 */
7266 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7267 wait > rdev->wiphy.max_remain_on_channel_duration)
7268 return -EINVAL;
7269
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007270 }
7271
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007272 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7273
Johannes Berg7c4ef712011-11-18 15:33:48 +01007274 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7275 return -EINVAL;
7276
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307277 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7278
Antonio Quartulliea141b752013-06-11 14:20:03 +02007279 /* get the channel if any has been specified, otherwise pass NULL to
7280 * the driver. The latter will use the current one
7281 */
7282 chandef.chan = NULL;
7283 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7284 err = nl80211_parse_chandef(rdev, info, &chandef);
7285 if (err)
7286 return err;
7287 }
7288
7289 if (!chandef.chan && offchan)
7290 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007291
Johannes Berge247bd902011-11-04 11:18:21 +01007292 if (!dont_wait_for_ack) {
7293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7294 if (!msg)
7295 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007296
Eric W. Biederman15e47302012-09-07 20:12:54 +00007297 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007298 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007299
Johannes Berge247bd902011-11-04 11:18:21 +01007300 if (IS_ERR(hdr)) {
7301 err = PTR_ERR(hdr);
7302 goto free_msg;
7303 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007304 }
Johannes Berge247bd902011-11-04 11:18:21 +01007305
Johannes Berg683b6d32012-11-08 21:25:48 +01007306 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007307 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7308 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007309 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007310 if (err)
7311 goto free_msg;
7312
Johannes Berge247bd902011-11-04 11:18:21 +01007313 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007314 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7315 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007316
Johannes Berge247bd902011-11-04 11:18:21 +01007317 genlmsg_end(msg, hdr);
7318 return genlmsg_reply(msg, info);
7319 }
7320
7321 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007322
7323 nla_put_failure:
7324 err = -ENOBUFS;
7325 free_msg:
7326 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007327 return err;
7328}
7329
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007330static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7331{
7332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007333 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007334 u64 cookie;
7335
7336 if (!info->attrs[NL80211_ATTR_COOKIE])
7337 return -EINVAL;
7338
7339 if (!rdev->ops->mgmt_tx_cancel_wait)
7340 return -EOPNOTSUPP;
7341
Johannes Berg71bbc992012-06-15 15:30:18 +02007342 switch (wdev->iftype) {
7343 case NL80211_IFTYPE_STATION:
7344 case NL80211_IFTYPE_ADHOC:
7345 case NL80211_IFTYPE_P2P_CLIENT:
7346 case NL80211_IFTYPE_AP:
7347 case NL80211_IFTYPE_AP_VLAN:
7348 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007349 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007350 break;
7351 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007352 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007353 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007354
7355 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7356
Hila Gonene35e4d22012-06-27 17:19:42 +03007357 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007358}
7359
Kalle Valoffb9eb32010-02-17 17:58:10 +02007360static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7361{
Johannes Berg4c476992010-10-04 21:36:35 +02007362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007363 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007364 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007365 u8 ps_state;
7366 bool state;
7367 int err;
7368
Johannes Berg4c476992010-10-04 21:36:35 +02007369 if (!info->attrs[NL80211_ATTR_PS_STATE])
7370 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007371
7372 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7373
Johannes Berg4c476992010-10-04 21:36:35 +02007374 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7375 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007376
7377 wdev = dev->ieee80211_ptr;
7378
Johannes Berg4c476992010-10-04 21:36:35 +02007379 if (!rdev->ops->set_power_mgmt)
7380 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007381
7382 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7383
7384 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007385 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007386
Hila Gonene35e4d22012-06-27 17:19:42 +03007387 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007388 if (!err)
7389 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007390 return err;
7391}
7392
7393static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7394{
Johannes Berg4c476992010-10-04 21:36:35 +02007395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007396 enum nl80211_ps_state ps_state;
7397 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007398 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007399 struct sk_buff *msg;
7400 void *hdr;
7401 int err;
7402
Kalle Valoffb9eb32010-02-17 17:58:10 +02007403 wdev = dev->ieee80211_ptr;
7404
Johannes Berg4c476992010-10-04 21:36:35 +02007405 if (!rdev->ops->set_power_mgmt)
7406 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007407
7408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007409 if (!msg)
7410 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007411
Eric W. Biederman15e47302012-09-07 20:12:54 +00007412 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007413 NL80211_CMD_GET_POWER_SAVE);
7414 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007415 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007416 goto free_msg;
7417 }
7418
7419 if (wdev->ps)
7420 ps_state = NL80211_PS_ENABLED;
7421 else
7422 ps_state = NL80211_PS_DISABLED;
7423
David S. Miller9360ffd2012-03-29 04:41:26 -04007424 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7425 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007426
7427 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007428 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007429
Johannes Berg4c476992010-10-04 21:36:35 +02007430 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007431 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007432 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007433 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007434 return err;
7435}
7436
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007437static struct nla_policy
7438nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7439 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7440 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7441 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007442 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7443 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7444 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007445};
7446
Thomas Pedersen84f10702012-07-12 16:17:33 -07007447static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007448 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007449{
7450 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7451 struct wireless_dev *wdev;
7452 struct net_device *dev = info->user_ptr[1];
7453
Johannes Bergd9d8b012012-11-26 12:51:52 +01007454 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007455 return -EINVAL;
7456
7457 wdev = dev->ieee80211_ptr;
7458
7459 if (!rdev->ops->set_cqm_txe_config)
7460 return -EOPNOTSUPP;
7461
7462 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7463 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7464 return -EOPNOTSUPP;
7465
Hila Gonene35e4d22012-06-27 17:19:42 +03007466 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007467}
7468
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007469static int nl80211_set_cqm_rssi(struct genl_info *info,
7470 s32 threshold, u32 hysteresis)
7471{
Johannes Berg4c476992010-10-04 21:36:35 +02007472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007473 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007474 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007475
7476 if (threshold > 0)
7477 return -EINVAL;
7478
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007479 wdev = dev->ieee80211_ptr;
7480
Johannes Berg4c476992010-10-04 21:36:35 +02007481 if (!rdev->ops->set_cqm_rssi_config)
7482 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007483
Johannes Berg074ac8d2010-09-16 14:58:22 +02007484 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007485 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7486 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007487
Hila Gonene35e4d22012-06-27 17:19:42 +03007488 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007489}
7490
7491static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7492{
7493 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7494 struct nlattr *cqm;
7495 int err;
7496
7497 cqm = info->attrs[NL80211_ATTR_CQM];
7498 if (!cqm) {
7499 err = -EINVAL;
7500 goto out;
7501 }
7502
7503 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7504 nl80211_attr_cqm_policy);
7505 if (err)
7506 goto out;
7507
7508 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7509 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7510 s32 threshold;
7511 u32 hysteresis;
7512 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7513 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7514 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007515 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7516 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7517 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7518 u32 rate, pkts, intvl;
7519 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7520 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7521 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7522 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007523 } else
7524 err = -EINVAL;
7525
7526out:
7527 return err;
7528}
7529
Johannes Berg29cbe682010-12-03 09:20:44 +01007530static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7531{
7532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7533 struct net_device *dev = info->user_ptr[1];
7534 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007535 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007536 int err;
7537
7538 /* start with default */
7539 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007540 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007541
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007542 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007543 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007544 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007545 if (err)
7546 return err;
7547 }
7548
7549 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7550 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7551 return -EINVAL;
7552
Javier Cardonac80d5452010-12-16 17:37:49 -08007553 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7554 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7555
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007556 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7557 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7558 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7559 return -EINVAL;
7560
Marco Porsch9bdbf042013-01-07 16:04:51 +01007561 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7562 setup.beacon_interval =
7563 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7564 if (setup.beacon_interval < 10 ||
7565 setup.beacon_interval > 10000)
7566 return -EINVAL;
7567 }
7568
7569 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7570 setup.dtim_period =
7571 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7572 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7573 return -EINVAL;
7574 }
7575
Javier Cardonac80d5452010-12-16 17:37:49 -08007576 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7577 /* parse additional setup parameters if given */
7578 err = nl80211_parse_mesh_setup(info, &setup);
7579 if (err)
7580 return err;
7581 }
7582
Thomas Pedersend37bb182013-03-04 13:06:13 -08007583 if (setup.user_mpm)
7584 cfg.auto_open_plinks = false;
7585
Johannes Bergcc1d2802012-05-16 23:50:20 +02007586 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007587 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7588 if (err)
7589 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007590 } else {
7591 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007592 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007593 }
7594
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007595 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7596 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7597 int n_rates =
7598 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7599 struct ieee80211_supported_band *sband;
7600
7601 if (!setup.chandef.chan)
7602 return -EINVAL;
7603
7604 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7605
7606 err = ieee80211_get_ratemask(sband, rates, n_rates,
7607 &setup.basic_rates);
7608 if (err)
7609 return err;
7610 }
7611
Javier Cardonac80d5452010-12-16 17:37:49 -08007612 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007613}
7614
7615static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7616{
7617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7618 struct net_device *dev = info->user_ptr[1];
7619
7620 return cfg80211_leave_mesh(rdev, dev);
7621}
7622
Johannes Bergdfb89c52012-06-27 09:23:48 +02007623#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007624static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7625 struct cfg80211_registered_device *rdev)
7626{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007627 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007628 struct nlattr *nl_pats, *nl_pat;
7629 int i, pat_len;
7630
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007631 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007632 return 0;
7633
7634 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7635 if (!nl_pats)
7636 return -ENOBUFS;
7637
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007638 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007639 nl_pat = nla_nest_start(msg, i + 1);
7640 if (!nl_pat)
7641 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007642 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007643 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007644 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007645 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7646 wowlan->patterns[i].pattern) ||
7647 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007648 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007649 return -ENOBUFS;
7650 nla_nest_end(msg, nl_pat);
7651 }
7652 nla_nest_end(msg, nl_pats);
7653
7654 return 0;
7655}
7656
Johannes Berg2a0e0472013-01-23 22:57:40 +01007657static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7658 struct cfg80211_wowlan_tcp *tcp)
7659{
7660 struct nlattr *nl_tcp;
7661
7662 if (!tcp)
7663 return 0;
7664
7665 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7666 if (!nl_tcp)
7667 return -ENOBUFS;
7668
7669 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7670 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7671 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7672 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7673 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7674 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7675 tcp->payload_len, tcp->payload) ||
7676 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7677 tcp->data_interval) ||
7678 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7679 tcp->wake_len, tcp->wake_data) ||
7680 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7681 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7682 return -ENOBUFS;
7683
7684 if (tcp->payload_seq.len &&
7685 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7686 sizeof(tcp->payload_seq), &tcp->payload_seq))
7687 return -ENOBUFS;
7688
7689 if (tcp->payload_tok.len &&
7690 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7691 sizeof(tcp->payload_tok) + tcp->tokens_size,
7692 &tcp->payload_tok))
7693 return -ENOBUFS;
7694
Johannes Berge248ad32013-05-16 10:24:28 +02007695 nla_nest_end(msg, nl_tcp);
7696
Johannes Berg2a0e0472013-01-23 22:57:40 +01007697 return 0;
7698}
7699
Johannes Bergff1b6e62011-05-04 15:37:28 +02007700static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7701{
7702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7703 struct sk_buff *msg;
7704 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007705 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007706
Johannes Berg964dc9e2013-06-03 17:25:34 +02007707 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007708 return -EOPNOTSUPP;
7709
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007710 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007711 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007712 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7713 rdev->wiphy.wowlan_config->tcp->payload_len +
7714 rdev->wiphy.wowlan_config->tcp->wake_len +
7715 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007716 }
7717
7718 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007719 if (!msg)
7720 return -ENOMEM;
7721
Eric W. Biederman15e47302012-09-07 20:12:54 +00007722 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007723 NL80211_CMD_GET_WOWLAN);
7724 if (!hdr)
7725 goto nla_put_failure;
7726
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007727 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007728 struct nlattr *nl_wowlan;
7729
7730 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7731 if (!nl_wowlan)
7732 goto nla_put_failure;
7733
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007734 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007735 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007736 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007737 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007738 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007739 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007740 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007741 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007742 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007743 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007744 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007745 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007746 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007747 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7748 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007749
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007750 if (nl80211_send_wowlan_patterns(msg, rdev))
7751 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007752
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007753 if (nl80211_send_wowlan_tcp(msg,
7754 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007755 goto nla_put_failure;
7756
Johannes Bergff1b6e62011-05-04 15:37:28 +02007757 nla_nest_end(msg, nl_wowlan);
7758 }
7759
7760 genlmsg_end(msg, hdr);
7761 return genlmsg_reply(msg, info);
7762
7763nla_put_failure:
7764 nlmsg_free(msg);
7765 return -ENOBUFS;
7766}
7767
Johannes Berg2a0e0472013-01-23 22:57:40 +01007768static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7769 struct nlattr *attr,
7770 struct cfg80211_wowlan *trig)
7771{
7772 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7773 struct cfg80211_wowlan_tcp *cfg;
7774 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7775 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7776 u32 size;
7777 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7778 int err, port;
7779
Johannes Berg964dc9e2013-06-03 17:25:34 +02007780 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007781 return -EINVAL;
7782
7783 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7784 nla_data(attr), nla_len(attr),
7785 nl80211_wowlan_tcp_policy);
7786 if (err)
7787 return err;
7788
7789 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7790 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7791 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7792 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7793 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7794 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7795 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7796 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7797 return -EINVAL;
7798
7799 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007800 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007801 return -EINVAL;
7802
7803 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007804 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007805 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007806 return -EINVAL;
7807
7808 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007809 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007810 return -EINVAL;
7811
7812 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7813 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7814 return -EINVAL;
7815
7816 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7817 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7818
7819 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7820 tokens_size = tokln - sizeof(*tok);
7821
7822 if (!tok->len || tokens_size % tok->len)
7823 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007824 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007825 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007826 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007827 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007828 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007829 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007830 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007831 return -EINVAL;
7832 if (tok->offset + tok->len > data_size)
7833 return -EINVAL;
7834 }
7835
7836 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7837 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007838 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007839 return -EINVAL;
7840 if (seq->len == 0 || seq->len > 4)
7841 return -EINVAL;
7842 if (seq->len + seq->offset > data_size)
7843 return -EINVAL;
7844 }
7845
7846 size = sizeof(*cfg);
7847 size += data_size;
7848 size += wake_size + wake_mask_size;
7849 size += tokens_size;
7850
7851 cfg = kzalloc(size, GFP_KERNEL);
7852 if (!cfg)
7853 return -ENOMEM;
7854 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7855 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7856 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7857 ETH_ALEN);
7858 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7859 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7860 else
7861 port = 0;
7862#ifdef CONFIG_INET
7863 /* allocate a socket and port for it and use it */
7864 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7865 IPPROTO_TCP, &cfg->sock, 1);
7866 if (err) {
7867 kfree(cfg);
7868 return err;
7869 }
7870 if (inet_csk_get_port(cfg->sock->sk, port)) {
7871 sock_release(cfg->sock);
7872 kfree(cfg);
7873 return -EADDRINUSE;
7874 }
7875 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7876#else
7877 if (!port) {
7878 kfree(cfg);
7879 return -EINVAL;
7880 }
7881 cfg->src_port = port;
7882#endif
7883
7884 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7885 cfg->payload_len = data_size;
7886 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7887 memcpy((void *)cfg->payload,
7888 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7889 data_size);
7890 if (seq)
7891 cfg->payload_seq = *seq;
7892 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7893 cfg->wake_len = wake_size;
7894 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7895 memcpy((void *)cfg->wake_data,
7896 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7897 wake_size);
7898 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7899 data_size + wake_size;
7900 memcpy((void *)cfg->wake_mask,
7901 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7902 wake_mask_size);
7903 if (tok) {
7904 cfg->tokens_size = tokens_size;
7905 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7906 }
7907
7908 trig->tcp = cfg;
7909
7910 return 0;
7911}
7912
Johannes Bergff1b6e62011-05-04 15:37:28 +02007913static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7914{
7915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7916 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007917 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007918 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007919 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007920 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007921 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007922
Johannes Berg964dc9e2013-06-03 17:25:34 +02007923 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007924 return -EOPNOTSUPP;
7925
Johannes Bergae33bd82012-07-12 16:25:02 +02007926 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7927 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007928 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007929 goto set_wakeup;
7930 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007931
7932 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7933 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7934 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7935 nl80211_wowlan_policy);
7936 if (err)
7937 return err;
7938
7939 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7940 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7941 return -EINVAL;
7942 new_triggers.any = true;
7943 }
7944
7945 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7946 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7947 return -EINVAL;
7948 new_triggers.disconnect = true;
7949 }
7950
7951 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7952 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7953 return -EINVAL;
7954 new_triggers.magic_pkt = true;
7955 }
7956
Johannes Berg77dbbb132011-07-13 10:48:55 +02007957 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7958 return -EINVAL;
7959
7960 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7961 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7962 return -EINVAL;
7963 new_triggers.gtk_rekey_failure = true;
7964 }
7965
7966 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7967 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7968 return -EINVAL;
7969 new_triggers.eap_identity_req = true;
7970 }
7971
7972 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7973 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7974 return -EINVAL;
7975 new_triggers.four_way_handshake = true;
7976 }
7977
7978 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7979 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7980 return -EINVAL;
7981 new_triggers.rfkill_release = true;
7982 }
7983
Johannes Bergff1b6e62011-05-04 15:37:28 +02007984 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7985 struct nlattr *pat;
7986 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007987 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007988 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007989
7990 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7991 rem)
7992 n_patterns++;
7993 if (n_patterns > wowlan->n_patterns)
7994 return -EINVAL;
7995
7996 new_triggers.patterns = kcalloc(n_patterns,
7997 sizeof(new_triggers.patterns[0]),
7998 GFP_KERNEL);
7999 if (!new_triggers.patterns)
8000 return -ENOMEM;
8001
8002 new_triggers.n_patterns = n_patterns;
8003 i = 0;
8004
8005 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8006 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008007 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8008 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008009 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008010 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8011 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008012 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008013 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008014 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008015 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008016 goto error;
8017 if (pat_len > wowlan->pattern_max_len ||
8018 pat_len < wowlan->pattern_min_len)
8019 goto error;
8020
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008021 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008022 pkt_offset = 0;
8023 else
8024 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008025 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008026 if (pkt_offset > wowlan->max_pkt_offset)
8027 goto error;
8028 new_triggers.patterns[i].pkt_offset = pkt_offset;
8029
Johannes Bergff1b6e62011-05-04 15:37:28 +02008030 new_triggers.patterns[i].mask =
8031 kmalloc(mask_len + pat_len, GFP_KERNEL);
8032 if (!new_triggers.patterns[i].mask) {
8033 err = -ENOMEM;
8034 goto error;
8035 }
8036 new_triggers.patterns[i].pattern =
8037 new_triggers.patterns[i].mask + mask_len;
8038 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008039 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008040 mask_len);
8041 new_triggers.patterns[i].pattern_len = pat_len;
8042 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008043 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008044 pat_len);
8045 i++;
8046 }
8047 }
8048
Johannes Berg2a0e0472013-01-23 22:57:40 +01008049 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8050 err = nl80211_parse_wowlan_tcp(
8051 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8052 &new_triggers);
8053 if (err)
8054 goto error;
8055 }
8056
Johannes Bergae33bd82012-07-12 16:25:02 +02008057 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8058 if (!ntrig) {
8059 err = -ENOMEM;
8060 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008061 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008062 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008063 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008064
Johannes Bergae33bd82012-07-12 16:25:02 +02008065 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008066 if (rdev->ops->set_wakeup &&
8067 prev_enabled != !!rdev->wiphy.wowlan_config)
8068 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008069
Johannes Bergff1b6e62011-05-04 15:37:28 +02008070 return 0;
8071 error:
8072 for (i = 0; i < new_triggers.n_patterns; i++)
8073 kfree(new_triggers.patterns[i].mask);
8074 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008075 if (new_triggers.tcp && new_triggers.tcp->sock)
8076 sock_release(new_triggers.tcp->sock);
8077 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008078 return err;
8079}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008080#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008081
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008082static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8083 struct cfg80211_registered_device *rdev)
8084{
8085 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8086 int i, j, pat_len;
8087 struct cfg80211_coalesce_rules *rule;
8088
8089 if (!rdev->coalesce->n_rules)
8090 return 0;
8091
8092 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8093 if (!nl_rules)
8094 return -ENOBUFS;
8095
8096 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8097 nl_rule = nla_nest_start(msg, i + 1);
8098 if (!nl_rule)
8099 return -ENOBUFS;
8100
8101 rule = &rdev->coalesce->rules[i];
8102 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8103 rule->delay))
8104 return -ENOBUFS;
8105
8106 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8107 rule->condition))
8108 return -ENOBUFS;
8109
8110 nl_pats = nla_nest_start(msg,
8111 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8112 if (!nl_pats)
8113 return -ENOBUFS;
8114
8115 for (j = 0; j < rule->n_patterns; j++) {
8116 nl_pat = nla_nest_start(msg, j + 1);
8117 if (!nl_pat)
8118 return -ENOBUFS;
8119 pat_len = rule->patterns[j].pattern_len;
8120 if (nla_put(msg, NL80211_PKTPAT_MASK,
8121 DIV_ROUND_UP(pat_len, 8),
8122 rule->patterns[j].mask) ||
8123 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8124 rule->patterns[j].pattern) ||
8125 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8126 rule->patterns[j].pkt_offset))
8127 return -ENOBUFS;
8128 nla_nest_end(msg, nl_pat);
8129 }
8130 nla_nest_end(msg, nl_pats);
8131 nla_nest_end(msg, nl_rule);
8132 }
8133 nla_nest_end(msg, nl_rules);
8134
8135 return 0;
8136}
8137
8138static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8139{
8140 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8141 struct sk_buff *msg;
8142 void *hdr;
8143
8144 if (!rdev->wiphy.coalesce)
8145 return -EOPNOTSUPP;
8146
8147 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8148 if (!msg)
8149 return -ENOMEM;
8150
8151 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8152 NL80211_CMD_GET_COALESCE);
8153 if (!hdr)
8154 goto nla_put_failure;
8155
8156 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8157 goto nla_put_failure;
8158
8159 genlmsg_end(msg, hdr);
8160 return genlmsg_reply(msg, info);
8161
8162nla_put_failure:
8163 nlmsg_free(msg);
8164 return -ENOBUFS;
8165}
8166
8167void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8168{
8169 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8170 int i, j;
8171 struct cfg80211_coalesce_rules *rule;
8172
8173 if (!coalesce)
8174 return;
8175
8176 for (i = 0; i < coalesce->n_rules; i++) {
8177 rule = &coalesce->rules[i];
8178 for (j = 0; j < rule->n_patterns; j++)
8179 kfree(rule->patterns[j].mask);
8180 kfree(rule->patterns);
8181 }
8182 kfree(coalesce->rules);
8183 kfree(coalesce);
8184 rdev->coalesce = NULL;
8185}
8186
8187static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8188 struct nlattr *rule,
8189 struct cfg80211_coalesce_rules *new_rule)
8190{
8191 int err, i;
8192 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8193 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8194 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8195 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8196
8197 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8198 nla_len(rule), nl80211_coalesce_policy);
8199 if (err)
8200 return err;
8201
8202 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8203 new_rule->delay =
8204 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8205 if (new_rule->delay > coalesce->max_delay)
8206 return -EINVAL;
8207
8208 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8209 new_rule->condition =
8210 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8211 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8212 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8213 return -EINVAL;
8214
8215 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8216 return -EINVAL;
8217
8218 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8219 rem)
8220 n_patterns++;
8221 if (n_patterns > coalesce->n_patterns)
8222 return -EINVAL;
8223
8224 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8225 GFP_KERNEL);
8226 if (!new_rule->patterns)
8227 return -ENOMEM;
8228
8229 new_rule->n_patterns = n_patterns;
8230 i = 0;
8231
8232 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8233 rem) {
8234 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8235 nla_len(pat), NULL);
8236 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8237 !pat_tb[NL80211_PKTPAT_PATTERN])
8238 return -EINVAL;
8239 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8240 mask_len = DIV_ROUND_UP(pat_len, 8);
8241 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8242 return -EINVAL;
8243 if (pat_len > coalesce->pattern_max_len ||
8244 pat_len < coalesce->pattern_min_len)
8245 return -EINVAL;
8246
8247 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8248 pkt_offset = 0;
8249 else
8250 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8251 if (pkt_offset > coalesce->max_pkt_offset)
8252 return -EINVAL;
8253 new_rule->patterns[i].pkt_offset = pkt_offset;
8254
8255 new_rule->patterns[i].mask =
8256 kmalloc(mask_len + pat_len, GFP_KERNEL);
8257 if (!new_rule->patterns[i].mask)
8258 return -ENOMEM;
8259 new_rule->patterns[i].pattern =
8260 new_rule->patterns[i].mask + mask_len;
8261 memcpy(new_rule->patterns[i].mask,
8262 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8263 new_rule->patterns[i].pattern_len = pat_len;
8264 memcpy(new_rule->patterns[i].pattern,
8265 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8266 i++;
8267 }
8268
8269 return 0;
8270}
8271
8272static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8273{
8274 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8275 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8276 struct cfg80211_coalesce new_coalesce = {};
8277 struct cfg80211_coalesce *n_coalesce;
8278 int err, rem_rule, n_rules = 0, i, j;
8279 struct nlattr *rule;
8280 struct cfg80211_coalesce_rules *tmp_rule;
8281
8282 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8283 return -EOPNOTSUPP;
8284
8285 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8286 cfg80211_rdev_free_coalesce(rdev);
8287 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8288 return 0;
8289 }
8290
8291 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8292 rem_rule)
8293 n_rules++;
8294 if (n_rules > coalesce->n_rules)
8295 return -EINVAL;
8296
8297 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8298 GFP_KERNEL);
8299 if (!new_coalesce.rules)
8300 return -ENOMEM;
8301
8302 new_coalesce.n_rules = n_rules;
8303 i = 0;
8304
8305 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8306 rem_rule) {
8307 err = nl80211_parse_coalesce_rule(rdev, rule,
8308 &new_coalesce.rules[i]);
8309 if (err)
8310 goto error;
8311
8312 i++;
8313 }
8314
8315 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8316 if (err)
8317 goto error;
8318
8319 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8320 if (!n_coalesce) {
8321 err = -ENOMEM;
8322 goto error;
8323 }
8324 cfg80211_rdev_free_coalesce(rdev);
8325 rdev->coalesce = n_coalesce;
8326
8327 return 0;
8328error:
8329 for (i = 0; i < new_coalesce.n_rules; i++) {
8330 tmp_rule = &new_coalesce.rules[i];
8331 for (j = 0; j < tmp_rule->n_patterns; j++)
8332 kfree(tmp_rule->patterns[j].mask);
8333 kfree(tmp_rule->patterns);
8334 }
8335 kfree(new_coalesce.rules);
8336
8337 return err;
8338}
8339
Johannes Berge5497d72011-07-05 16:35:40 +02008340static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8341{
8342 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8343 struct net_device *dev = info->user_ptr[1];
8344 struct wireless_dev *wdev = dev->ieee80211_ptr;
8345 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8346 struct cfg80211_gtk_rekey_data rekey_data;
8347 int err;
8348
8349 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8350 return -EINVAL;
8351
8352 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8353 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8354 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8355 nl80211_rekey_policy);
8356 if (err)
8357 return err;
8358
8359 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8360 return -ERANGE;
8361 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8362 return -ERANGE;
8363 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8364 return -ERANGE;
8365
8366 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8367 NL80211_KEK_LEN);
8368 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8369 NL80211_KCK_LEN);
8370 memcpy(rekey_data.replay_ctr,
8371 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8372 NL80211_REPLAY_CTR_LEN);
8373
8374 wdev_lock(wdev);
8375 if (!wdev->current_bss) {
8376 err = -ENOTCONN;
8377 goto out;
8378 }
8379
8380 if (!rdev->ops->set_rekey_data) {
8381 err = -EOPNOTSUPP;
8382 goto out;
8383 }
8384
Hila Gonene35e4d22012-06-27 17:19:42 +03008385 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008386 out:
8387 wdev_unlock(wdev);
8388 return err;
8389}
8390
Johannes Berg28946da2011-11-04 11:18:12 +01008391static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8392 struct genl_info *info)
8393{
8394 struct net_device *dev = info->user_ptr[1];
8395 struct wireless_dev *wdev = dev->ieee80211_ptr;
8396
8397 if (wdev->iftype != NL80211_IFTYPE_AP &&
8398 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8399 return -EINVAL;
8400
Eric W. Biederman15e47302012-09-07 20:12:54 +00008401 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008402 return -EBUSY;
8403
Eric W. Biederman15e47302012-09-07 20:12:54 +00008404 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008405 return 0;
8406}
8407
Johannes Berg7f6cf312011-11-04 11:18:15 +01008408static int nl80211_probe_client(struct sk_buff *skb,
8409 struct genl_info *info)
8410{
8411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8412 struct net_device *dev = info->user_ptr[1];
8413 struct wireless_dev *wdev = dev->ieee80211_ptr;
8414 struct sk_buff *msg;
8415 void *hdr;
8416 const u8 *addr;
8417 u64 cookie;
8418 int err;
8419
8420 if (wdev->iftype != NL80211_IFTYPE_AP &&
8421 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8422 return -EOPNOTSUPP;
8423
8424 if (!info->attrs[NL80211_ATTR_MAC])
8425 return -EINVAL;
8426
8427 if (!rdev->ops->probe_client)
8428 return -EOPNOTSUPP;
8429
8430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8431 if (!msg)
8432 return -ENOMEM;
8433
Eric W. Biederman15e47302012-09-07 20:12:54 +00008434 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008435 NL80211_CMD_PROBE_CLIENT);
8436
8437 if (IS_ERR(hdr)) {
8438 err = PTR_ERR(hdr);
8439 goto free_msg;
8440 }
8441
8442 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8443
Hila Gonene35e4d22012-06-27 17:19:42 +03008444 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008445 if (err)
8446 goto free_msg;
8447
David S. Miller9360ffd2012-03-29 04:41:26 -04008448 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8449 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008450
8451 genlmsg_end(msg, hdr);
8452
8453 return genlmsg_reply(msg, info);
8454
8455 nla_put_failure:
8456 err = -ENOBUFS;
8457 free_msg:
8458 nlmsg_free(msg);
8459 return err;
8460}
8461
Johannes Berg5e760232011-11-04 11:18:17 +01008462static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8463{
8464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008465 struct cfg80211_beacon_registration *reg, *nreg;
8466 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008467
8468 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8469 return -EOPNOTSUPP;
8470
Ben Greear37c73b52012-10-26 14:49:25 -07008471 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8472 if (!nreg)
8473 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008474
Ben Greear37c73b52012-10-26 14:49:25 -07008475 /* First, check if already registered. */
8476 spin_lock_bh(&rdev->beacon_registrations_lock);
8477 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8478 if (reg->nlportid == info->snd_portid) {
8479 rv = -EALREADY;
8480 goto out_err;
8481 }
8482 }
8483 /* Add it to the list */
8484 nreg->nlportid = info->snd_portid;
8485 list_add(&nreg->list, &rdev->beacon_registrations);
8486
8487 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008488
8489 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008490out_err:
8491 spin_unlock_bh(&rdev->beacon_registrations_lock);
8492 kfree(nreg);
8493 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008494}
8495
Johannes Berg98104fde2012-06-16 00:19:54 +02008496static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8497{
8498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8499 struct wireless_dev *wdev = info->user_ptr[1];
8500 int err;
8501
8502 if (!rdev->ops->start_p2p_device)
8503 return -EOPNOTSUPP;
8504
8505 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8506 return -EOPNOTSUPP;
8507
8508 if (wdev->p2p_started)
8509 return 0;
8510
Johannes Berg98104fde2012-06-16 00:19:54 +02008511 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008512 if (err)
8513 return err;
8514
Johannes Bergeeb126e2012-10-23 15:16:50 +02008515 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008516 if (err)
8517 return err;
8518
8519 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008520 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008521
8522 return 0;
8523}
8524
8525static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8526{
8527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8528 struct wireless_dev *wdev = info->user_ptr[1];
8529
8530 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8531 return -EOPNOTSUPP;
8532
8533 if (!rdev->ops->stop_p2p_device)
8534 return -EOPNOTSUPP;
8535
Johannes Bergf9f47522013-03-19 15:04:07 +01008536 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008537
8538 return 0;
8539}
8540
Johannes Berg3713b4e2013-02-14 16:19:38 +01008541static int nl80211_get_protocol_features(struct sk_buff *skb,
8542 struct genl_info *info)
8543{
8544 void *hdr;
8545 struct sk_buff *msg;
8546
8547 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8548 if (!msg)
8549 return -ENOMEM;
8550
8551 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8552 NL80211_CMD_GET_PROTOCOL_FEATURES);
8553 if (!hdr)
8554 goto nla_put_failure;
8555
8556 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8557 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8558 goto nla_put_failure;
8559
8560 genlmsg_end(msg, hdr);
8561 return genlmsg_reply(msg, info);
8562
8563 nla_put_failure:
8564 kfree_skb(msg);
8565 return -ENOBUFS;
8566}
8567
Jouni Malinen355199e2013-02-27 17:14:27 +02008568static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8569{
8570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8571 struct cfg80211_update_ft_ies_params ft_params;
8572 struct net_device *dev = info->user_ptr[1];
8573
8574 if (!rdev->ops->update_ft_ies)
8575 return -EOPNOTSUPP;
8576
8577 if (!info->attrs[NL80211_ATTR_MDID] ||
8578 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8579 return -EINVAL;
8580
8581 memset(&ft_params, 0, sizeof(ft_params));
8582 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8583 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8584 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8585
8586 return rdev_update_ft_ies(rdev, dev, &ft_params);
8587}
8588
Arend van Spriel5de17982013-04-18 15:49:00 +02008589static int nl80211_crit_protocol_start(struct sk_buff *skb,
8590 struct genl_info *info)
8591{
8592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8593 struct wireless_dev *wdev = info->user_ptr[1];
8594 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8595 u16 duration;
8596 int ret;
8597
8598 if (!rdev->ops->crit_proto_start)
8599 return -EOPNOTSUPP;
8600
8601 if (WARN_ON(!rdev->ops->crit_proto_stop))
8602 return -EINVAL;
8603
8604 if (rdev->crit_proto_nlportid)
8605 return -EBUSY;
8606
8607 /* determine protocol if provided */
8608 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8609 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8610
8611 if (proto >= NUM_NL80211_CRIT_PROTO)
8612 return -EINVAL;
8613
8614 /* timeout must be provided */
8615 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8616 return -EINVAL;
8617
8618 duration =
8619 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8620
8621 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8622 return -ERANGE;
8623
8624 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8625 if (!ret)
8626 rdev->crit_proto_nlportid = info->snd_portid;
8627
8628 return ret;
8629}
8630
8631static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8632 struct genl_info *info)
8633{
8634 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8635 struct wireless_dev *wdev = info->user_ptr[1];
8636
8637 if (!rdev->ops->crit_proto_stop)
8638 return -EOPNOTSUPP;
8639
8640 if (rdev->crit_proto_nlportid) {
8641 rdev->crit_proto_nlportid = 0;
8642 rdev_crit_proto_stop(rdev, wdev);
8643 }
8644 return 0;
8645}
8646
Johannes Berg4c476992010-10-04 21:36:35 +02008647#define NL80211_FLAG_NEED_WIPHY 0x01
8648#define NL80211_FLAG_NEED_NETDEV 0x02
8649#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008650#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8651#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8652 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008653#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008654/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008655#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8656 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008657
8658static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8659 struct genl_info *info)
8660{
8661 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008662 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008663 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008664 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8665
8666 if (rtnl)
8667 rtnl_lock();
8668
8669 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008670 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008671 if (IS_ERR(rdev)) {
8672 if (rtnl)
8673 rtnl_unlock();
8674 return PTR_ERR(rdev);
8675 }
8676 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008677 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8678 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008679 ASSERT_RTNL();
8680
Johannes Berg89a54e42012-06-15 14:33:17 +02008681 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8682 info->attrs);
8683 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008684 if (rtnl)
8685 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008686 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008687 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008688
Johannes Berg89a54e42012-06-15 14:33:17 +02008689 dev = wdev->netdev;
8690 rdev = wiphy_to_dev(wdev->wiphy);
8691
Johannes Berg1bf614e2012-06-15 15:23:36 +02008692 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8693 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008694 if (rtnl)
8695 rtnl_unlock();
8696 return -EINVAL;
8697 }
8698
8699 info->user_ptr[1] = dev;
8700 } else {
8701 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008702 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008703
Johannes Berg1bf614e2012-06-15 15:23:36 +02008704 if (dev) {
8705 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8706 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008707 if (rtnl)
8708 rtnl_unlock();
8709 return -ENETDOWN;
8710 }
8711
8712 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008713 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8714 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008715 if (rtnl)
8716 rtnl_unlock();
8717 return -ENETDOWN;
8718 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008719 }
8720
Johannes Berg4c476992010-10-04 21:36:35 +02008721 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008722 }
8723
8724 return 0;
8725}
8726
8727static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8728 struct genl_info *info)
8729{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008730 if (info->user_ptr[1]) {
8731 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8732 struct wireless_dev *wdev = info->user_ptr[1];
8733
8734 if (wdev->netdev)
8735 dev_put(wdev->netdev);
8736 } else {
8737 dev_put(info->user_ptr[1]);
8738 }
8739 }
Johannes Berg4c476992010-10-04 21:36:35 +02008740 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8741 rtnl_unlock();
8742}
8743
Johannes Berg55682962007-09-20 13:09:35 -04008744static struct genl_ops nl80211_ops[] = {
8745 {
8746 .cmd = NL80211_CMD_GET_WIPHY,
8747 .doit = nl80211_get_wiphy,
8748 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008749 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008750 .policy = nl80211_policy,
8751 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008752 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8753 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008754 },
8755 {
8756 .cmd = NL80211_CMD_SET_WIPHY,
8757 .doit = nl80211_set_wiphy,
8758 .policy = nl80211_policy,
8759 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008760 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008761 },
8762 {
8763 .cmd = NL80211_CMD_GET_INTERFACE,
8764 .doit = nl80211_get_interface,
8765 .dumpit = nl80211_dump_interface,
8766 .policy = nl80211_policy,
8767 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008768 .internal_flags = NL80211_FLAG_NEED_WDEV |
8769 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008770 },
8771 {
8772 .cmd = NL80211_CMD_SET_INTERFACE,
8773 .doit = nl80211_set_interface,
8774 .policy = nl80211_policy,
8775 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008776 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8777 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008778 },
8779 {
8780 .cmd = NL80211_CMD_NEW_INTERFACE,
8781 .doit = nl80211_new_interface,
8782 .policy = nl80211_policy,
8783 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008784 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8785 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008786 },
8787 {
8788 .cmd = NL80211_CMD_DEL_INTERFACE,
8789 .doit = nl80211_del_interface,
8790 .policy = nl80211_policy,
8791 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008792 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008793 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008794 },
Johannes Berg41ade002007-12-19 02:03:29 +01008795 {
8796 .cmd = NL80211_CMD_GET_KEY,
8797 .doit = nl80211_get_key,
8798 .policy = nl80211_policy,
8799 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008801 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008802 },
8803 {
8804 .cmd = NL80211_CMD_SET_KEY,
8805 .doit = nl80211_set_key,
8806 .policy = nl80211_policy,
8807 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008808 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008809 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008810 },
8811 {
8812 .cmd = NL80211_CMD_NEW_KEY,
8813 .doit = nl80211_new_key,
8814 .policy = nl80211_policy,
8815 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008816 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008817 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008818 },
8819 {
8820 .cmd = NL80211_CMD_DEL_KEY,
8821 .doit = nl80211_del_key,
8822 .policy = nl80211_policy,
8823 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008825 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008826 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008827 {
8828 .cmd = NL80211_CMD_SET_BEACON,
8829 .policy = nl80211_policy,
8830 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008831 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008832 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008833 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008834 },
8835 {
Johannes Berg88600202012-02-13 15:17:18 +01008836 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008837 .policy = nl80211_policy,
8838 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008839 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008840 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008841 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008842 },
8843 {
Johannes Berg88600202012-02-13 15:17:18 +01008844 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008845 .policy = nl80211_policy,
8846 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008847 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008849 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008850 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008851 {
8852 .cmd = NL80211_CMD_GET_STATION,
8853 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008854 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008855 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008856 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8857 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008858 },
8859 {
8860 .cmd = NL80211_CMD_SET_STATION,
8861 .doit = nl80211_set_station,
8862 .policy = nl80211_policy,
8863 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008864 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008865 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008866 },
8867 {
8868 .cmd = NL80211_CMD_NEW_STATION,
8869 .doit = nl80211_new_station,
8870 .policy = nl80211_policy,
8871 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008872 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008873 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008874 },
8875 {
8876 .cmd = NL80211_CMD_DEL_STATION,
8877 .doit = nl80211_del_station,
8878 .policy = nl80211_policy,
8879 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008880 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008881 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008882 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008883 {
8884 .cmd = NL80211_CMD_GET_MPATH,
8885 .doit = nl80211_get_mpath,
8886 .dumpit = nl80211_dump_mpath,
8887 .policy = nl80211_policy,
8888 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008889 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008890 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008891 },
8892 {
8893 .cmd = NL80211_CMD_SET_MPATH,
8894 .doit = nl80211_set_mpath,
8895 .policy = nl80211_policy,
8896 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008897 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008898 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008899 },
8900 {
8901 .cmd = NL80211_CMD_NEW_MPATH,
8902 .doit = nl80211_new_mpath,
8903 .policy = nl80211_policy,
8904 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008905 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008906 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008907 },
8908 {
8909 .cmd = NL80211_CMD_DEL_MPATH,
8910 .doit = nl80211_del_mpath,
8911 .policy = nl80211_policy,
8912 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008913 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008914 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008915 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008916 {
8917 .cmd = NL80211_CMD_SET_BSS,
8918 .doit = nl80211_set_bss,
8919 .policy = nl80211_policy,
8920 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008921 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008922 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008923 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008924 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008925 .cmd = NL80211_CMD_GET_REG,
8926 .doit = nl80211_get_reg,
8927 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008928 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008929 /* can be retrieved by unprivileged users */
8930 },
8931 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008932 .cmd = NL80211_CMD_SET_REG,
8933 .doit = nl80211_set_reg,
8934 .policy = nl80211_policy,
8935 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008936 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008937 },
8938 {
8939 .cmd = NL80211_CMD_REQ_SET_REG,
8940 .doit = nl80211_req_set_reg,
8941 .policy = nl80211_policy,
8942 .flags = GENL_ADMIN_PERM,
8943 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008944 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008945 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8946 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008947 .policy = nl80211_policy,
8948 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008949 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008950 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008951 },
8952 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008953 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8954 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008955 .policy = nl80211_policy,
8956 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008957 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008958 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008959 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008960 {
Johannes Berg2a519312009-02-10 21:25:55 +01008961 .cmd = NL80211_CMD_TRIGGER_SCAN,
8962 .doit = nl80211_trigger_scan,
8963 .policy = nl80211_policy,
8964 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008965 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008966 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008967 },
8968 {
8969 .cmd = NL80211_CMD_GET_SCAN,
8970 .policy = nl80211_policy,
8971 .dumpit = nl80211_dump_scan,
8972 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008973 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008974 .cmd = NL80211_CMD_START_SCHED_SCAN,
8975 .doit = nl80211_start_sched_scan,
8976 .policy = nl80211_policy,
8977 .flags = GENL_ADMIN_PERM,
8978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8979 NL80211_FLAG_NEED_RTNL,
8980 },
8981 {
8982 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8983 .doit = nl80211_stop_sched_scan,
8984 .policy = nl80211_policy,
8985 .flags = GENL_ADMIN_PERM,
8986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8987 NL80211_FLAG_NEED_RTNL,
8988 },
8989 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008990 .cmd = NL80211_CMD_AUTHENTICATE,
8991 .doit = nl80211_authenticate,
8992 .policy = nl80211_policy,
8993 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008994 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008995 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008996 },
8997 {
8998 .cmd = NL80211_CMD_ASSOCIATE,
8999 .doit = nl80211_associate,
9000 .policy = nl80211_policy,
9001 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009003 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009004 },
9005 {
9006 .cmd = NL80211_CMD_DEAUTHENTICATE,
9007 .doit = nl80211_deauthenticate,
9008 .policy = nl80211_policy,
9009 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009010 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009011 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009012 },
9013 {
9014 .cmd = NL80211_CMD_DISASSOCIATE,
9015 .doit = nl80211_disassociate,
9016 .policy = nl80211_policy,
9017 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009018 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009019 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009020 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009021 {
9022 .cmd = NL80211_CMD_JOIN_IBSS,
9023 .doit = nl80211_join_ibss,
9024 .policy = nl80211_policy,
9025 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009026 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009027 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009028 },
9029 {
9030 .cmd = NL80211_CMD_LEAVE_IBSS,
9031 .doit = nl80211_leave_ibss,
9032 .policy = nl80211_policy,
9033 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009034 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009035 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009036 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009037#ifdef CONFIG_NL80211_TESTMODE
9038 {
9039 .cmd = NL80211_CMD_TESTMODE,
9040 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009041 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009042 .policy = nl80211_policy,
9043 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009044 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9045 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009046 },
9047#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009048 {
9049 .cmd = NL80211_CMD_CONNECT,
9050 .doit = nl80211_connect,
9051 .policy = nl80211_policy,
9052 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009053 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009054 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009055 },
9056 {
9057 .cmd = NL80211_CMD_DISCONNECT,
9058 .doit = nl80211_disconnect,
9059 .policy = nl80211_policy,
9060 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009061 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009062 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009063 },
Johannes Berg463d0182009-07-14 00:33:35 +02009064 {
9065 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9066 .doit = nl80211_wiphy_netns,
9067 .policy = nl80211_policy,
9068 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009069 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9070 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009071 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009072 {
9073 .cmd = NL80211_CMD_GET_SURVEY,
9074 .policy = nl80211_policy,
9075 .dumpit = nl80211_dump_survey,
9076 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009077 {
9078 .cmd = NL80211_CMD_SET_PMKSA,
9079 .doit = nl80211_setdel_pmksa,
9080 .policy = nl80211_policy,
9081 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009083 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009084 },
9085 {
9086 .cmd = NL80211_CMD_DEL_PMKSA,
9087 .doit = nl80211_setdel_pmksa,
9088 .policy = nl80211_policy,
9089 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009091 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009092 },
9093 {
9094 .cmd = NL80211_CMD_FLUSH_PMKSA,
9095 .doit = nl80211_flush_pmksa,
9096 .policy = nl80211_policy,
9097 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009098 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009099 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009100 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009101 {
9102 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9103 .doit = nl80211_remain_on_channel,
9104 .policy = nl80211_policy,
9105 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009106 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009107 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009108 },
9109 {
9110 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9111 .doit = nl80211_cancel_remain_on_channel,
9112 .policy = nl80211_policy,
9113 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009114 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009115 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009116 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009117 {
9118 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9119 .doit = nl80211_set_tx_bitrate_mask,
9120 .policy = nl80211_policy,
9121 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009122 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9123 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009124 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009125 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009126 .cmd = NL80211_CMD_REGISTER_FRAME,
9127 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009128 .policy = nl80211_policy,
9129 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009130 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009131 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009132 },
9133 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009134 .cmd = NL80211_CMD_FRAME,
9135 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009136 .policy = nl80211_policy,
9137 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009138 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009139 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009140 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009141 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009142 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9143 .doit = nl80211_tx_mgmt_cancel_wait,
9144 .policy = nl80211_policy,
9145 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009146 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009147 NL80211_FLAG_NEED_RTNL,
9148 },
9149 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009150 .cmd = NL80211_CMD_SET_POWER_SAVE,
9151 .doit = nl80211_set_power_save,
9152 .policy = nl80211_policy,
9153 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009154 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9155 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009156 },
9157 {
9158 .cmd = NL80211_CMD_GET_POWER_SAVE,
9159 .doit = nl80211_get_power_save,
9160 .policy = nl80211_policy,
9161 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009162 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9163 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009164 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009165 {
9166 .cmd = NL80211_CMD_SET_CQM,
9167 .doit = nl80211_set_cqm,
9168 .policy = nl80211_policy,
9169 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009170 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9171 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009172 },
Johannes Bergf444de02010-05-05 15:25:02 +02009173 {
9174 .cmd = NL80211_CMD_SET_CHANNEL,
9175 .doit = nl80211_set_channel,
9176 .policy = nl80211_policy,
9177 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009178 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9179 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009180 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009181 {
9182 .cmd = NL80211_CMD_SET_WDS_PEER,
9183 .doit = nl80211_set_wds_peer,
9184 .policy = nl80211_policy,
9185 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009186 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9187 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009188 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009189 {
9190 .cmd = NL80211_CMD_JOIN_MESH,
9191 .doit = nl80211_join_mesh,
9192 .policy = nl80211_policy,
9193 .flags = GENL_ADMIN_PERM,
9194 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9195 NL80211_FLAG_NEED_RTNL,
9196 },
9197 {
9198 .cmd = NL80211_CMD_LEAVE_MESH,
9199 .doit = nl80211_leave_mesh,
9200 .policy = nl80211_policy,
9201 .flags = GENL_ADMIN_PERM,
9202 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9203 NL80211_FLAG_NEED_RTNL,
9204 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009205#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009206 {
9207 .cmd = NL80211_CMD_GET_WOWLAN,
9208 .doit = nl80211_get_wowlan,
9209 .policy = nl80211_policy,
9210 /* can be retrieved by unprivileged users */
9211 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9212 NL80211_FLAG_NEED_RTNL,
9213 },
9214 {
9215 .cmd = NL80211_CMD_SET_WOWLAN,
9216 .doit = nl80211_set_wowlan,
9217 .policy = nl80211_policy,
9218 .flags = GENL_ADMIN_PERM,
9219 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9220 NL80211_FLAG_NEED_RTNL,
9221 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009222#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009223 {
9224 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9225 .doit = nl80211_set_rekey_data,
9226 .policy = nl80211_policy,
9227 .flags = GENL_ADMIN_PERM,
9228 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9229 NL80211_FLAG_NEED_RTNL,
9230 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009231 {
9232 .cmd = NL80211_CMD_TDLS_MGMT,
9233 .doit = nl80211_tdls_mgmt,
9234 .policy = nl80211_policy,
9235 .flags = GENL_ADMIN_PERM,
9236 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9237 NL80211_FLAG_NEED_RTNL,
9238 },
9239 {
9240 .cmd = NL80211_CMD_TDLS_OPER,
9241 .doit = nl80211_tdls_oper,
9242 .policy = nl80211_policy,
9243 .flags = GENL_ADMIN_PERM,
9244 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9245 NL80211_FLAG_NEED_RTNL,
9246 },
Johannes Berg28946da2011-11-04 11:18:12 +01009247 {
9248 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9249 .doit = nl80211_register_unexpected_frame,
9250 .policy = nl80211_policy,
9251 .flags = GENL_ADMIN_PERM,
9252 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9253 NL80211_FLAG_NEED_RTNL,
9254 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009255 {
9256 .cmd = NL80211_CMD_PROBE_CLIENT,
9257 .doit = nl80211_probe_client,
9258 .policy = nl80211_policy,
9259 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009260 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009261 NL80211_FLAG_NEED_RTNL,
9262 },
Johannes Berg5e760232011-11-04 11:18:17 +01009263 {
9264 .cmd = NL80211_CMD_REGISTER_BEACONS,
9265 .doit = nl80211_register_beacons,
9266 .policy = nl80211_policy,
9267 .flags = GENL_ADMIN_PERM,
9268 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9269 NL80211_FLAG_NEED_RTNL,
9270 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009271 {
9272 .cmd = NL80211_CMD_SET_NOACK_MAP,
9273 .doit = nl80211_set_noack_map,
9274 .policy = nl80211_policy,
9275 .flags = GENL_ADMIN_PERM,
9276 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9277 NL80211_FLAG_NEED_RTNL,
9278 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009279 {
9280 .cmd = NL80211_CMD_START_P2P_DEVICE,
9281 .doit = nl80211_start_p2p_device,
9282 .policy = nl80211_policy,
9283 .flags = GENL_ADMIN_PERM,
9284 .internal_flags = NL80211_FLAG_NEED_WDEV |
9285 NL80211_FLAG_NEED_RTNL,
9286 },
9287 {
9288 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9289 .doit = nl80211_stop_p2p_device,
9290 .policy = nl80211_policy,
9291 .flags = GENL_ADMIN_PERM,
9292 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9293 NL80211_FLAG_NEED_RTNL,
9294 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009295 {
9296 .cmd = NL80211_CMD_SET_MCAST_RATE,
9297 .doit = nl80211_set_mcast_rate,
9298 .policy = nl80211_policy,
9299 .flags = GENL_ADMIN_PERM,
9300 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9301 NL80211_FLAG_NEED_RTNL,
9302 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309303 {
9304 .cmd = NL80211_CMD_SET_MAC_ACL,
9305 .doit = nl80211_set_mac_acl,
9306 .policy = nl80211_policy,
9307 .flags = GENL_ADMIN_PERM,
9308 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9309 NL80211_FLAG_NEED_RTNL,
9310 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009311 {
9312 .cmd = NL80211_CMD_RADAR_DETECT,
9313 .doit = nl80211_start_radar_detection,
9314 .policy = nl80211_policy,
9315 .flags = GENL_ADMIN_PERM,
9316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9317 NL80211_FLAG_NEED_RTNL,
9318 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009319 {
9320 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9321 .doit = nl80211_get_protocol_features,
9322 .policy = nl80211_policy,
9323 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009324 {
9325 .cmd = NL80211_CMD_UPDATE_FT_IES,
9326 .doit = nl80211_update_ft_ies,
9327 .policy = nl80211_policy,
9328 .flags = GENL_ADMIN_PERM,
9329 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9330 NL80211_FLAG_NEED_RTNL,
9331 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009332 {
9333 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9334 .doit = nl80211_crit_protocol_start,
9335 .policy = nl80211_policy,
9336 .flags = GENL_ADMIN_PERM,
9337 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9338 NL80211_FLAG_NEED_RTNL,
9339 },
9340 {
9341 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9342 .doit = nl80211_crit_protocol_stop,
9343 .policy = nl80211_policy,
9344 .flags = GENL_ADMIN_PERM,
9345 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9346 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009347 },
9348 {
9349 .cmd = NL80211_CMD_GET_COALESCE,
9350 .doit = nl80211_get_coalesce,
9351 .policy = nl80211_policy,
9352 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9353 NL80211_FLAG_NEED_RTNL,
9354 },
9355 {
9356 .cmd = NL80211_CMD_SET_COALESCE,
9357 .doit = nl80211_set_coalesce,
9358 .policy = nl80211_policy,
9359 .flags = GENL_ADMIN_PERM,
9360 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9361 NL80211_FLAG_NEED_RTNL,
Arend van Spriel5de17982013-04-18 15:49:00 +02009362 }
Johannes Berg55682962007-09-20 13:09:35 -04009363};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009364
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009365static struct genl_multicast_group nl80211_mlme_mcgrp = {
9366 .name = "mlme",
9367};
Johannes Berg55682962007-09-20 13:09:35 -04009368
9369/* multicast groups */
9370static struct genl_multicast_group nl80211_config_mcgrp = {
9371 .name = "config",
9372};
Johannes Berg2a519312009-02-10 21:25:55 +01009373static struct genl_multicast_group nl80211_scan_mcgrp = {
9374 .name = "scan",
9375};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009376static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9377 .name = "regulatory",
9378};
Johannes Berg55682962007-09-20 13:09:35 -04009379
9380/* notification functions */
9381
9382void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9383{
9384 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009385 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009386
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009387 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009388 if (!msg)
9389 return;
9390
Johannes Berg86e8cf92013-06-19 10:57:22 +02009391 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009392 nlmsg_free(msg);
9393 return;
9394 }
9395
Johannes Berg463d0182009-07-14 00:33:35 +02009396 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9397 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009398}
9399
Johannes Berg362a4152009-05-24 16:43:15 +02009400static int nl80211_add_scan_req(struct sk_buff *msg,
9401 struct cfg80211_registered_device *rdev)
9402{
9403 struct cfg80211_scan_request *req = rdev->scan_req;
9404 struct nlattr *nest;
9405 int i;
9406
9407 if (WARN_ON(!req))
9408 return 0;
9409
9410 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9411 if (!nest)
9412 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009413 for (i = 0; i < req->n_ssids; i++) {
9414 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9415 goto nla_put_failure;
9416 }
Johannes Berg362a4152009-05-24 16:43:15 +02009417 nla_nest_end(msg, nest);
9418
9419 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9420 if (!nest)
9421 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009422 for (i = 0; i < req->n_channels; i++) {
9423 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9424 goto nla_put_failure;
9425 }
Johannes Berg362a4152009-05-24 16:43:15 +02009426 nla_nest_end(msg, nest);
9427
David S. Miller9360ffd2012-03-29 04:41:26 -04009428 if (req->ie &&
9429 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9430 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009431
Sam Lefflered4737712012-10-11 21:03:31 -07009432 if (req->flags)
9433 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9434
Johannes Berg362a4152009-05-24 16:43:15 +02009435 return 0;
9436 nla_put_failure:
9437 return -ENOBUFS;
9438}
9439
Johannes Berga538e2d2009-06-16 19:56:42 +02009440static int nl80211_send_scan_msg(struct sk_buff *msg,
9441 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009442 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009443 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009444 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009445{
9446 void *hdr;
9447
Eric W. Biederman15e47302012-09-07 20:12:54 +00009448 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009449 if (!hdr)
9450 return -1;
9451
David S. Miller9360ffd2012-03-29 04:41:26 -04009452 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009453 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9454 wdev->netdev->ifindex)) ||
9455 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009456 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009457
Johannes Berg362a4152009-05-24 16:43:15 +02009458 /* ignore errors and send incomplete event anyway */
9459 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009460
9461 return genlmsg_end(msg, hdr);
9462
9463 nla_put_failure:
9464 genlmsg_cancel(msg, hdr);
9465 return -EMSGSIZE;
9466}
9467
Luciano Coelho807f8a82011-05-11 17:09:35 +03009468static int
9469nl80211_send_sched_scan_msg(struct sk_buff *msg,
9470 struct cfg80211_registered_device *rdev,
9471 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009472 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009473{
9474 void *hdr;
9475
Eric W. Biederman15e47302012-09-07 20:12:54 +00009476 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009477 if (!hdr)
9478 return -1;
9479
David S. Miller9360ffd2012-03-29 04:41:26 -04009480 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9481 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9482 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009483
9484 return genlmsg_end(msg, hdr);
9485
9486 nla_put_failure:
9487 genlmsg_cancel(msg, hdr);
9488 return -EMSGSIZE;
9489}
9490
Johannes Berga538e2d2009-06-16 19:56:42 +02009491void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009492 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009493{
9494 struct sk_buff *msg;
9495
Thomas Graf58050fc2012-06-28 03:57:45 +00009496 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009497 if (!msg)
9498 return;
9499
Johannes Bergfd014282012-06-18 19:17:03 +02009500 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009501 NL80211_CMD_TRIGGER_SCAN) < 0) {
9502 nlmsg_free(msg);
9503 return;
9504 }
9505
Johannes Berg463d0182009-07-14 00:33:35 +02009506 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9507 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009508}
9509
Johannes Berg2a519312009-02-10 21:25:55 +01009510void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009511 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009512{
9513 struct sk_buff *msg;
9514
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009516 if (!msg)
9517 return;
9518
Johannes Bergfd014282012-06-18 19:17:03 +02009519 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009520 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009521 nlmsg_free(msg);
9522 return;
9523 }
9524
Johannes Berg463d0182009-07-14 00:33:35 +02009525 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9526 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009527}
9528
9529void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009530 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009531{
9532 struct sk_buff *msg;
9533
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009534 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009535 if (!msg)
9536 return;
9537
Johannes Bergfd014282012-06-18 19:17:03 +02009538 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009539 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009540 nlmsg_free(msg);
9541 return;
9542 }
9543
Johannes Berg463d0182009-07-14 00:33:35 +02009544 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9545 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009546}
9547
Luciano Coelho807f8a82011-05-11 17:09:35 +03009548void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9549 struct net_device *netdev)
9550{
9551 struct sk_buff *msg;
9552
9553 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9554 if (!msg)
9555 return;
9556
9557 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9558 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9559 nlmsg_free(msg);
9560 return;
9561 }
9562
9563 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9564 nl80211_scan_mcgrp.id, GFP_KERNEL);
9565}
9566
9567void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9568 struct net_device *netdev, u32 cmd)
9569{
9570 struct sk_buff *msg;
9571
Thomas Graf58050fc2012-06-28 03:57:45 +00009572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009573 if (!msg)
9574 return;
9575
9576 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9577 nlmsg_free(msg);
9578 return;
9579 }
9580
9581 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9582 nl80211_scan_mcgrp.id, GFP_KERNEL);
9583}
9584
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009585/*
9586 * This can happen on global regulatory changes or device specific settings
9587 * based on custom world regulatory domains.
9588 */
9589void nl80211_send_reg_change_event(struct regulatory_request *request)
9590{
9591 struct sk_buff *msg;
9592 void *hdr;
9593
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009595 if (!msg)
9596 return;
9597
9598 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9599 if (!hdr) {
9600 nlmsg_free(msg);
9601 return;
9602 }
9603
9604 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009605 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9606 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009607
David S. Miller9360ffd2012-03-29 04:41:26 -04009608 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9609 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9610 NL80211_REGDOM_TYPE_WORLD))
9611 goto nla_put_failure;
9612 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9613 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9614 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9615 goto nla_put_failure;
9616 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9617 request->intersect) {
9618 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9619 NL80211_REGDOM_TYPE_INTERSECTION))
9620 goto nla_put_failure;
9621 } else {
9622 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9623 NL80211_REGDOM_TYPE_COUNTRY) ||
9624 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9625 request->alpha2))
9626 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009627 }
9628
Johannes Bergf4173762012-12-03 18:23:37 +01009629 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009630 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9631 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009632
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009633 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009634
Johannes Bergbc43b282009-07-25 10:54:13 +02009635 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009636 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009637 GFP_ATOMIC);
9638 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009639
9640 return;
9641
9642nla_put_failure:
9643 genlmsg_cancel(msg, hdr);
9644 nlmsg_free(msg);
9645}
9646
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009647static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9648 struct net_device *netdev,
9649 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009650 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009651{
9652 struct sk_buff *msg;
9653 void *hdr;
9654
Johannes Berge6d6e342009-07-01 21:26:47 +02009655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009656 if (!msg)
9657 return;
9658
9659 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9660 if (!hdr) {
9661 nlmsg_free(msg);
9662 return;
9663 }
9664
David S. Miller9360ffd2012-03-29 04:41:26 -04009665 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9666 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9667 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9668 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009669
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009670 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009671
Johannes Berg463d0182009-07-14 00:33:35 +02009672 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9673 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009674 return;
9675
9676 nla_put_failure:
9677 genlmsg_cancel(msg, hdr);
9678 nlmsg_free(msg);
9679}
9680
9681void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009682 struct net_device *netdev, const u8 *buf,
9683 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009684{
9685 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009686 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009687}
9688
9689void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9690 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009691 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009692{
Johannes Berge6d6e342009-07-01 21:26:47 +02009693 nl80211_send_mlme_event(rdev, netdev, buf, len,
9694 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009695}
9696
Jouni Malinen53b46b82009-03-27 20:53:56 +02009697void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009698 struct net_device *netdev, const u8 *buf,
9699 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009700{
9701 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009702 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009703}
9704
Jouni Malinen53b46b82009-03-27 20:53:56 +02009705void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9706 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009707 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009708{
9709 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009710 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009711}
9712
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009713void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9714 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009715{
Johannes Berg947add32013-02-22 22:05:20 +01009716 struct wireless_dev *wdev = dev->ieee80211_ptr;
9717 struct wiphy *wiphy = wdev->wiphy;
9718 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009719 const struct ieee80211_mgmt *mgmt = (void *)buf;
9720 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009721
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009722 if (WARN_ON(len < 2))
9723 return;
9724
9725 if (ieee80211_is_deauth(mgmt->frame_control))
9726 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9727 else
9728 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9729
9730 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9731 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009732}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009733EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009734
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009735static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9736 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009737 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009738{
9739 struct sk_buff *msg;
9740 void *hdr;
9741
Johannes Berge6d6e342009-07-01 21:26:47 +02009742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009743 if (!msg)
9744 return;
9745
9746 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9747 if (!hdr) {
9748 nlmsg_free(msg);
9749 return;
9750 }
9751
David S. Miller9360ffd2012-03-29 04:41:26 -04009752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9753 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9754 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9755 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9756 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009757
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009758 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009759
Johannes Berg463d0182009-07-14 00:33:35 +02009760 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9761 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009762 return;
9763
9764 nla_put_failure:
9765 genlmsg_cancel(msg, hdr);
9766 nlmsg_free(msg);
9767}
9768
9769void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009770 struct net_device *netdev, const u8 *addr,
9771 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009772{
9773 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009774 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009775}
9776
9777void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009778 struct net_device *netdev, const u8 *addr,
9779 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009780{
Johannes Berge6d6e342009-07-01 21:26:47 +02009781 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9782 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009783}
9784
Samuel Ortizb23aa672009-07-01 21:26:54 +02009785void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9786 struct net_device *netdev, const u8 *bssid,
9787 const u8 *req_ie, size_t req_ie_len,
9788 const u8 *resp_ie, size_t resp_ie_len,
9789 u16 status, gfp_t gfp)
9790{
9791 struct sk_buff *msg;
9792 void *hdr;
9793
Thomas Graf58050fc2012-06-28 03:57:45 +00009794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009795 if (!msg)
9796 return;
9797
9798 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9799 if (!hdr) {
9800 nlmsg_free(msg);
9801 return;
9802 }
9803
David S. Miller9360ffd2012-03-29 04:41:26 -04009804 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9805 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9806 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9807 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9808 (req_ie &&
9809 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9810 (resp_ie &&
9811 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9812 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009813
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009814 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009815
Johannes Berg463d0182009-07-14 00:33:35 +02009816 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9817 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009818 return;
9819
9820 nla_put_failure:
9821 genlmsg_cancel(msg, hdr);
9822 nlmsg_free(msg);
9823
9824}
9825
9826void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9827 struct net_device *netdev, const u8 *bssid,
9828 const u8 *req_ie, size_t req_ie_len,
9829 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9830{
9831 struct sk_buff *msg;
9832 void *hdr;
9833
Thomas Graf58050fc2012-06-28 03:57:45 +00009834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009835 if (!msg)
9836 return;
9837
9838 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9839 if (!hdr) {
9840 nlmsg_free(msg);
9841 return;
9842 }
9843
David S. Miller9360ffd2012-03-29 04:41:26 -04009844 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9845 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9846 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9847 (req_ie &&
9848 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9849 (resp_ie &&
9850 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9851 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009852
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009853 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009854
Johannes Berg463d0182009-07-14 00:33:35 +02009855 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9856 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009857 return;
9858
9859 nla_put_failure:
9860 genlmsg_cancel(msg, hdr);
9861 nlmsg_free(msg);
9862
9863}
9864
9865void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9866 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +02009867 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009868{
9869 struct sk_buff *msg;
9870 void *hdr;
9871
Thomas Graf58050fc2012-06-28 03:57:45 +00009872 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009873 if (!msg)
9874 return;
9875
9876 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9877 if (!hdr) {
9878 nlmsg_free(msg);
9879 return;
9880 }
9881
David S. Miller9360ffd2012-03-29 04:41:26 -04009882 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9883 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9884 (from_ap && reason &&
9885 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9886 (from_ap &&
9887 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9888 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9889 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009890
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009891 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009892
Johannes Berg463d0182009-07-14 00:33:35 +02009893 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9894 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009895 return;
9896
9897 nla_put_failure:
9898 genlmsg_cancel(msg, hdr);
9899 nlmsg_free(msg);
9900
9901}
9902
Johannes Berg04a773a2009-04-19 21:24:32 +02009903void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9904 struct net_device *netdev, const u8 *bssid,
9905 gfp_t gfp)
9906{
9907 struct sk_buff *msg;
9908 void *hdr;
9909
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009910 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009911 if (!msg)
9912 return;
9913
9914 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9915 if (!hdr) {
9916 nlmsg_free(msg);
9917 return;
9918 }
9919
David S. Miller9360ffd2012-03-29 04:41:26 -04009920 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9921 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9922 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9923 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009924
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009925 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009926
Johannes Berg463d0182009-07-14 00:33:35 +02009927 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9928 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009929 return;
9930
9931 nla_put_failure:
9932 genlmsg_cancel(msg, hdr);
9933 nlmsg_free(msg);
9934}
9935
Johannes Berg947add32013-02-22 22:05:20 +01009936void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9937 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009938{
Johannes Berg947add32013-02-22 22:05:20 +01009939 struct wireless_dev *wdev = dev->ieee80211_ptr;
9940 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009941 struct sk_buff *msg;
9942 void *hdr;
9943
Johannes Berg947add32013-02-22 22:05:20 +01009944 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9945 return;
9946
9947 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9948
Javier Cardonac93b5e72011-04-07 15:08:34 -07009949 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9950 if (!msg)
9951 return;
9952
9953 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9954 if (!hdr) {
9955 nlmsg_free(msg);
9956 return;
9957 }
9958
David S. Miller9360ffd2012-03-29 04:41:26 -04009959 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009960 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9961 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009962 (ie_len && ie &&
9963 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9964 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009965
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009966 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009967
9968 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9969 nl80211_mlme_mcgrp.id, gfp);
9970 return;
9971
9972 nla_put_failure:
9973 genlmsg_cancel(msg, hdr);
9974 nlmsg_free(msg);
9975}
Johannes Berg947add32013-02-22 22:05:20 +01009976EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009977
Jouni Malinena3b8b052009-03-27 21:59:49 +02009978void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9979 struct net_device *netdev, const u8 *addr,
9980 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009981 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009982{
9983 struct sk_buff *msg;
9984 void *hdr;
9985
Johannes Berge6d6e342009-07-01 21:26:47 +02009986 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009987 if (!msg)
9988 return;
9989
9990 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9991 if (!hdr) {
9992 nlmsg_free(msg);
9993 return;
9994 }
9995
David S. Miller9360ffd2012-03-29 04:41:26 -04009996 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9997 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9998 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9999 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10000 (key_id != -1 &&
10001 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10002 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10003 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010004
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010005 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010006
Johannes Berg463d0182009-07-14 00:33:35 +020010007 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10008 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010009 return;
10010
10011 nla_put_failure:
10012 genlmsg_cancel(msg, hdr);
10013 nlmsg_free(msg);
10014}
10015
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010016void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10017 struct ieee80211_channel *channel_before,
10018 struct ieee80211_channel *channel_after)
10019{
10020 struct sk_buff *msg;
10021 void *hdr;
10022 struct nlattr *nl_freq;
10023
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010025 if (!msg)
10026 return;
10027
10028 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10029 if (!hdr) {
10030 nlmsg_free(msg);
10031 return;
10032 }
10033
10034 /*
10035 * Since we are applying the beacon hint to a wiphy we know its
10036 * wiphy_idx is valid
10037 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010038 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10039 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010040
10041 /* Before */
10042 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10043 if (!nl_freq)
10044 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010045 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010046 goto nla_put_failure;
10047 nla_nest_end(msg, nl_freq);
10048
10049 /* After */
10050 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10051 if (!nl_freq)
10052 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010053 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010054 goto nla_put_failure;
10055 nla_nest_end(msg, nl_freq);
10056
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010057 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010058
Johannes Berg463d0182009-07-14 00:33:35 +020010059 rcu_read_lock();
10060 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10061 GFP_ATOMIC);
10062 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010063
10064 return;
10065
10066nla_put_failure:
10067 genlmsg_cancel(msg, hdr);
10068 nlmsg_free(msg);
10069}
10070
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010071static void nl80211_send_remain_on_chan_event(
10072 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010073 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010074 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010075 unsigned int duration, gfp_t gfp)
10076{
10077 struct sk_buff *msg;
10078 void *hdr;
10079
10080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10081 if (!msg)
10082 return;
10083
10084 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10085 if (!hdr) {
10086 nlmsg_free(msg);
10087 return;
10088 }
10089
David S. Miller9360ffd2012-03-29 04:41:26 -040010090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010091 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10092 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010093 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010094 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010095 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10096 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010097 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10098 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010099
David S. Miller9360ffd2012-03-29 04:41:26 -040010100 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10101 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10102 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010103
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010104 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010105
10106 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10107 nl80211_mlme_mcgrp.id, gfp);
10108 return;
10109
10110 nla_put_failure:
10111 genlmsg_cancel(msg, hdr);
10112 nlmsg_free(msg);
10113}
10114
Johannes Berg947add32013-02-22 22:05:20 +010010115void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10116 struct ieee80211_channel *chan,
10117 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010118{
Johannes Berg947add32013-02-22 22:05:20 +010010119 struct wiphy *wiphy = wdev->wiphy;
10120 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10121
10122 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010123 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010124 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010125 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010126}
Johannes Berg947add32013-02-22 22:05:20 +010010127EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010128
Johannes Berg947add32013-02-22 22:05:20 +010010129void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10130 struct ieee80211_channel *chan,
10131 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010132{
Johannes Berg947add32013-02-22 22:05:20 +010010133 struct wiphy *wiphy = wdev->wiphy;
10134 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10135
10136 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010137 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010138 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010139}
Johannes Berg947add32013-02-22 22:05:20 +010010140EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010141
Johannes Berg947add32013-02-22 22:05:20 +010010142void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10143 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010144{
Johannes Berg947add32013-02-22 22:05:20 +010010145 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10146 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010147 struct sk_buff *msg;
10148
Johannes Berg947add32013-02-22 22:05:20 +010010149 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10150
Thomas Graf58050fc2012-06-28 03:57:45 +000010151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010152 if (!msg)
10153 return;
10154
John W. Linville66266b32012-03-15 13:25:41 -040010155 if (nl80211_send_station(msg, 0, 0, 0,
10156 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010157 nlmsg_free(msg);
10158 return;
10159 }
10160
10161 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10162 nl80211_mlme_mcgrp.id, gfp);
10163}
Johannes Berg947add32013-02-22 22:05:20 +010010164EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010165
Johannes Berg947add32013-02-22 22:05:20 +010010166void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010167{
Johannes Berg947add32013-02-22 22:05:20 +010010168 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10169 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010170 struct sk_buff *msg;
10171 void *hdr;
10172
Johannes Berg947add32013-02-22 22:05:20 +010010173 trace_cfg80211_del_sta(dev, mac_addr);
10174
Thomas Graf58050fc2012-06-28 03:57:45 +000010175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010176 if (!msg)
10177 return;
10178
10179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10180 if (!hdr) {
10181 nlmsg_free(msg);
10182 return;
10183 }
10184
David S. Miller9360ffd2012-03-29 04:41:26 -040010185 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10186 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10187 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010188
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010189 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010190
10191 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10192 nl80211_mlme_mcgrp.id, gfp);
10193 return;
10194
10195 nla_put_failure:
10196 genlmsg_cancel(msg, hdr);
10197 nlmsg_free(msg);
10198}
Johannes Berg947add32013-02-22 22:05:20 +010010199EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010200
Johannes Berg947add32013-02-22 22:05:20 +010010201void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10202 enum nl80211_connect_failed_reason reason,
10203 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010204{
Johannes Berg947add32013-02-22 22:05:20 +010010205 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10206 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010207 struct sk_buff *msg;
10208 void *hdr;
10209
10210 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10211 if (!msg)
10212 return;
10213
10214 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10215 if (!hdr) {
10216 nlmsg_free(msg);
10217 return;
10218 }
10219
10220 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10221 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10222 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10223 goto nla_put_failure;
10224
10225 genlmsg_end(msg, hdr);
10226
10227 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10228 nl80211_mlme_mcgrp.id, gfp);
10229 return;
10230
10231 nla_put_failure:
10232 genlmsg_cancel(msg, hdr);
10233 nlmsg_free(msg);
10234}
Johannes Berg947add32013-02-22 22:05:20 +010010235EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010236
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010237static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10238 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010239{
10240 struct wireless_dev *wdev = dev->ieee80211_ptr;
10241 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10242 struct sk_buff *msg;
10243 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010244 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010245
Eric W. Biederman15e47302012-09-07 20:12:54 +000010246 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010247 return false;
10248
10249 msg = nlmsg_new(100, gfp);
10250 if (!msg)
10251 return true;
10252
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010253 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010254 if (!hdr) {
10255 nlmsg_free(msg);
10256 return true;
10257 }
10258
David S. Miller9360ffd2012-03-29 04:41:26 -040010259 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10260 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10261 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10262 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010263
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010264 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010265 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010266 return true;
10267
10268 nla_put_failure:
10269 genlmsg_cancel(msg, hdr);
10270 nlmsg_free(msg);
10271 return true;
10272}
10273
Johannes Berg947add32013-02-22 22:05:20 +010010274bool cfg80211_rx_spurious_frame(struct net_device *dev,
10275 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010276{
Johannes Berg947add32013-02-22 22:05:20 +010010277 struct wireless_dev *wdev = dev->ieee80211_ptr;
10278 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010279
Johannes Berg947add32013-02-22 22:05:20 +010010280 trace_cfg80211_rx_spurious_frame(dev, addr);
10281
10282 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10283 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10284 trace_cfg80211_return_bool(false);
10285 return false;
10286 }
10287 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10288 addr, gfp);
10289 trace_cfg80211_return_bool(ret);
10290 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010291}
Johannes Berg947add32013-02-22 22:05:20 +010010292EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10293
10294bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10295 const u8 *addr, gfp_t gfp)
10296{
10297 struct wireless_dev *wdev = dev->ieee80211_ptr;
10298 bool ret;
10299
10300 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10301
10302 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10303 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10304 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10305 trace_cfg80211_return_bool(false);
10306 return false;
10307 }
10308 ret = __nl80211_unexpected_frame(dev,
10309 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10310 addr, gfp);
10311 trace_cfg80211_return_bool(ret);
10312 return ret;
10313}
10314EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010315
Johannes Berg2e161f72010-08-12 15:38:38 +020010316int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010317 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010318 int freq, int sig_dbm,
10319 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010320{
Johannes Berg71bbc992012-06-15 15:30:18 +020010321 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010322 struct sk_buff *msg;
10323 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010324
10325 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10326 if (!msg)
10327 return -ENOMEM;
10328
Johannes Berg2e161f72010-08-12 15:38:38 +020010329 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010330 if (!hdr) {
10331 nlmsg_free(msg);
10332 return -ENOMEM;
10333 }
10334
David S. Miller9360ffd2012-03-29 04:41:26 -040010335 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010336 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10337 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010338 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010339 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10340 (sig_dbm &&
10341 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10342 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10343 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010344
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010345 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010346
Eric W. Biederman15e47302012-09-07 20:12:54 +000010347 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010348
10349 nla_put_failure:
10350 genlmsg_cancel(msg, hdr);
10351 nlmsg_free(msg);
10352 return -ENOBUFS;
10353}
10354
Johannes Berg947add32013-02-22 22:05:20 +010010355void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10356 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010357{
Johannes Berg947add32013-02-22 22:05:20 +010010358 struct wiphy *wiphy = wdev->wiphy;
10359 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010360 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010361 struct sk_buff *msg;
10362 void *hdr;
10363
Johannes Berg947add32013-02-22 22:05:20 +010010364 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10365
Jouni Malinen026331c2010-02-15 12:53:10 +020010366 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10367 if (!msg)
10368 return;
10369
Johannes Berg2e161f72010-08-12 15:38:38 +020010370 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010371 if (!hdr) {
10372 nlmsg_free(msg);
10373 return;
10374 }
10375
David S. Miller9360ffd2012-03-29 04:41:26 -040010376 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010377 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10378 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010379 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010380 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10381 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10382 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10383 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010384
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010385 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010386
10387 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10388 return;
10389
10390 nla_put_failure:
10391 genlmsg_cancel(msg, hdr);
10392 nlmsg_free(msg);
10393}
Johannes Berg947add32013-02-22 22:05:20 +010010394EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010395
Johannes Berg947add32013-02-22 22:05:20 +010010396void cfg80211_cqm_rssi_notify(struct net_device *dev,
10397 enum nl80211_cqm_rssi_threshold_event rssi_event,
10398 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010399{
Johannes Berg947add32013-02-22 22:05:20 +010010400 struct wireless_dev *wdev = dev->ieee80211_ptr;
10401 struct wiphy *wiphy = wdev->wiphy;
10402 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010403 struct sk_buff *msg;
10404 struct nlattr *pinfoattr;
10405 void *hdr;
10406
Johannes Berg947add32013-02-22 22:05:20 +010010407 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10408
Thomas Graf58050fc2012-06-28 03:57:45 +000010409 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010410 if (!msg)
10411 return;
10412
10413 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10414 if (!hdr) {
10415 nlmsg_free(msg);
10416 return;
10417 }
10418
David S. Miller9360ffd2012-03-29 04:41:26 -040010419 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010420 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010421 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010422
10423 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10424 if (!pinfoattr)
10425 goto nla_put_failure;
10426
David S. Miller9360ffd2012-03-29 04:41:26 -040010427 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10428 rssi_event))
10429 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010430
10431 nla_nest_end(msg, pinfoattr);
10432
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010433 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010434
10435 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10436 nl80211_mlme_mcgrp.id, gfp);
10437 return;
10438
10439 nla_put_failure:
10440 genlmsg_cancel(msg, hdr);
10441 nlmsg_free(msg);
10442}
Johannes Berg947add32013-02-22 22:05:20 +010010443EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010444
Johannes Berg947add32013-02-22 22:05:20 +010010445static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10446 struct net_device *netdev, const u8 *bssid,
10447 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010448{
10449 struct sk_buff *msg;
10450 struct nlattr *rekey_attr;
10451 void *hdr;
10452
Thomas Graf58050fc2012-06-28 03:57:45 +000010453 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010454 if (!msg)
10455 return;
10456
10457 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10458 if (!hdr) {
10459 nlmsg_free(msg);
10460 return;
10461 }
10462
David S. Miller9360ffd2012-03-29 04:41:26 -040010463 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10464 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10465 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10466 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010467
10468 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10469 if (!rekey_attr)
10470 goto nla_put_failure;
10471
David S. Miller9360ffd2012-03-29 04:41:26 -040010472 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10473 NL80211_REPLAY_CTR_LEN, replay_ctr))
10474 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010475
10476 nla_nest_end(msg, rekey_attr);
10477
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010478 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010479
10480 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10481 nl80211_mlme_mcgrp.id, gfp);
10482 return;
10483
10484 nla_put_failure:
10485 genlmsg_cancel(msg, hdr);
10486 nlmsg_free(msg);
10487}
10488
Johannes Berg947add32013-02-22 22:05:20 +010010489void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10490 const u8 *replay_ctr, gfp_t gfp)
10491{
10492 struct wireless_dev *wdev = dev->ieee80211_ptr;
10493 struct wiphy *wiphy = wdev->wiphy;
10494 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10495
10496 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10497 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10498}
10499EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10500
10501static void
10502nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10503 struct net_device *netdev, int index,
10504 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010505{
10506 struct sk_buff *msg;
10507 struct nlattr *attr;
10508 void *hdr;
10509
Thomas Graf58050fc2012-06-28 03:57:45 +000010510 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010511 if (!msg)
10512 return;
10513
10514 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10515 if (!hdr) {
10516 nlmsg_free(msg);
10517 return;
10518 }
10519
David S. Miller9360ffd2012-03-29 04:41:26 -040010520 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10521 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10522 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010523
10524 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10525 if (!attr)
10526 goto nla_put_failure;
10527
David S. Miller9360ffd2012-03-29 04:41:26 -040010528 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10529 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10530 (preauth &&
10531 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10532 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010533
10534 nla_nest_end(msg, attr);
10535
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010536 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010537
10538 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10539 nl80211_mlme_mcgrp.id, gfp);
10540 return;
10541
10542 nla_put_failure:
10543 genlmsg_cancel(msg, hdr);
10544 nlmsg_free(msg);
10545}
10546
Johannes Berg947add32013-02-22 22:05:20 +010010547void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10548 const u8 *bssid, bool preauth, gfp_t gfp)
10549{
10550 struct wireless_dev *wdev = dev->ieee80211_ptr;
10551 struct wiphy *wiphy = wdev->wiphy;
10552 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10553
10554 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10555 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10556}
10557EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10558
10559static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10560 struct net_device *netdev,
10561 struct cfg80211_chan_def *chandef,
10562 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010563{
10564 struct sk_buff *msg;
10565 void *hdr;
10566
Thomas Graf58050fc2012-06-28 03:57:45 +000010567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010568 if (!msg)
10569 return;
10570
10571 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10572 if (!hdr) {
10573 nlmsg_free(msg);
10574 return;
10575 }
10576
Johannes Berg683b6d32012-11-08 21:25:48 +010010577 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10578 goto nla_put_failure;
10579
10580 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010581 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010582
10583 genlmsg_end(msg, hdr);
10584
10585 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10586 nl80211_mlme_mcgrp.id, gfp);
10587 return;
10588
10589 nla_put_failure:
10590 genlmsg_cancel(msg, hdr);
10591 nlmsg_free(msg);
10592}
10593
Johannes Berg947add32013-02-22 22:05:20 +010010594void cfg80211_ch_switch_notify(struct net_device *dev,
10595 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010596{
Johannes Berg947add32013-02-22 22:05:20 +010010597 struct wireless_dev *wdev = dev->ieee80211_ptr;
10598 struct wiphy *wiphy = wdev->wiphy;
10599 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10600
10601 trace_cfg80211_ch_switch_notify(dev, chandef);
10602
10603 wdev_lock(wdev);
10604
10605 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10606 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10607 goto out;
10608
10609 wdev->channel = chandef->chan;
10610 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10611out:
10612 wdev_unlock(wdev);
10613 return;
10614}
10615EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10616
10617void cfg80211_cqm_txe_notify(struct net_device *dev,
10618 const u8 *peer, u32 num_packets,
10619 u32 rate, u32 intvl, gfp_t gfp)
10620{
10621 struct wireless_dev *wdev = dev->ieee80211_ptr;
10622 struct wiphy *wiphy = wdev->wiphy;
10623 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010624 struct sk_buff *msg;
10625 struct nlattr *pinfoattr;
10626 void *hdr;
10627
10628 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10629 if (!msg)
10630 return;
10631
10632 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10633 if (!hdr) {
10634 nlmsg_free(msg);
10635 return;
10636 }
10637
10638 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010639 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010640 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10641 goto nla_put_failure;
10642
10643 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10644 if (!pinfoattr)
10645 goto nla_put_failure;
10646
10647 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10648 goto nla_put_failure;
10649
10650 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10651 goto nla_put_failure;
10652
10653 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10654 goto nla_put_failure;
10655
10656 nla_nest_end(msg, pinfoattr);
10657
10658 genlmsg_end(msg, hdr);
10659
10660 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10661 nl80211_mlme_mcgrp.id, gfp);
10662 return;
10663
10664 nla_put_failure:
10665 genlmsg_cancel(msg, hdr);
10666 nlmsg_free(msg);
10667}
Johannes Berg947add32013-02-22 22:05:20 +010010668EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010669
10670void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010671nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10672 struct cfg80211_chan_def *chandef,
10673 enum nl80211_radar_event event,
10674 struct net_device *netdev, gfp_t gfp)
10675{
10676 struct sk_buff *msg;
10677 void *hdr;
10678
10679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10680 if (!msg)
10681 return;
10682
10683 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10684 if (!hdr) {
10685 nlmsg_free(msg);
10686 return;
10687 }
10688
10689 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10690 goto nla_put_failure;
10691
10692 /* NOP and radar events don't need a netdev parameter */
10693 if (netdev) {
10694 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10695
10696 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10697 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10698 goto nla_put_failure;
10699 }
10700
10701 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10702 goto nla_put_failure;
10703
10704 if (nl80211_send_chandef(msg, chandef))
10705 goto nla_put_failure;
10706
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010707 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010708
10709 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10710 nl80211_mlme_mcgrp.id, gfp);
10711 return;
10712
10713 nla_put_failure:
10714 genlmsg_cancel(msg, hdr);
10715 nlmsg_free(msg);
10716}
10717
Johannes Berg947add32013-02-22 22:05:20 +010010718void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10719 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010720{
Johannes Berg947add32013-02-22 22:05:20 +010010721 struct wireless_dev *wdev = dev->ieee80211_ptr;
10722 struct wiphy *wiphy = wdev->wiphy;
10723 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010724 struct sk_buff *msg;
10725 struct nlattr *pinfoattr;
10726 void *hdr;
10727
Johannes Berg947add32013-02-22 22:05:20 +010010728 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10729
Thomas Graf58050fc2012-06-28 03:57:45 +000010730 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010731 if (!msg)
10732 return;
10733
10734 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10735 if (!hdr) {
10736 nlmsg_free(msg);
10737 return;
10738 }
10739
David S. Miller9360ffd2012-03-29 04:41:26 -040010740 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010741 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010742 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10743 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010744
10745 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10746 if (!pinfoattr)
10747 goto nla_put_failure;
10748
David S. Miller9360ffd2012-03-29 04:41:26 -040010749 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10750 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010751
10752 nla_nest_end(msg, pinfoattr);
10753
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010754 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010755
10756 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10757 nl80211_mlme_mcgrp.id, gfp);
10758 return;
10759
10760 nla_put_failure:
10761 genlmsg_cancel(msg, hdr);
10762 nlmsg_free(msg);
10763}
Johannes Berg947add32013-02-22 22:05:20 +010010764EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010765
Johannes Berg7f6cf312011-11-04 11:18:15 +010010766void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10767 u64 cookie, bool acked, gfp_t gfp)
10768{
10769 struct wireless_dev *wdev = dev->ieee80211_ptr;
10770 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10771 struct sk_buff *msg;
10772 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010773
Beni Lev4ee3e062012-08-27 12:49:39 +030010774 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10775
Thomas Graf58050fc2012-06-28 03:57:45 +000010776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010777
Johannes Berg7f6cf312011-11-04 11:18:15 +010010778 if (!msg)
10779 return;
10780
10781 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10782 if (!hdr) {
10783 nlmsg_free(msg);
10784 return;
10785 }
10786
David S. Miller9360ffd2012-03-29 04:41:26 -040010787 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10788 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10789 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10790 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10791 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10792 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010793
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010794 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010795
10796 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10797 nl80211_mlme_mcgrp.id, gfp);
10798 return;
10799
10800 nla_put_failure:
10801 genlmsg_cancel(msg, hdr);
10802 nlmsg_free(msg);
10803}
10804EXPORT_SYMBOL(cfg80211_probe_status);
10805
Johannes Berg5e760232011-11-04 11:18:17 +010010806void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10807 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010808 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010809{
10810 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10811 struct sk_buff *msg;
10812 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010813 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010814
Beni Lev4ee3e062012-08-27 12:49:39 +030010815 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10816
Ben Greear37c73b52012-10-26 14:49:25 -070010817 spin_lock_bh(&rdev->beacon_registrations_lock);
10818 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10819 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10820 if (!msg) {
10821 spin_unlock_bh(&rdev->beacon_registrations_lock);
10822 return;
10823 }
Johannes Berg5e760232011-11-04 11:18:17 +010010824
Ben Greear37c73b52012-10-26 14:49:25 -070010825 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10826 if (!hdr)
10827 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010828
Ben Greear37c73b52012-10-26 14:49:25 -070010829 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10830 (freq &&
10831 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10832 (sig_dbm &&
10833 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10834 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10835 goto nla_put_failure;
10836
10837 genlmsg_end(msg, hdr);
10838
10839 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010840 }
Ben Greear37c73b52012-10-26 14:49:25 -070010841 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010842 return;
10843
10844 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010845 spin_unlock_bh(&rdev->beacon_registrations_lock);
10846 if (hdr)
10847 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010848 nlmsg_free(msg);
10849}
10850EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10851
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010852#ifdef CONFIG_PM
10853void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10854 struct cfg80211_wowlan_wakeup *wakeup,
10855 gfp_t gfp)
10856{
10857 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10858 struct sk_buff *msg;
10859 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010860 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010861
10862 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10863
10864 if (wakeup)
10865 size += wakeup->packet_present_len;
10866
10867 msg = nlmsg_new(size, gfp);
10868 if (!msg)
10869 return;
10870
10871 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10872 if (!hdr)
10873 goto free_msg;
10874
10875 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10876 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10877 goto free_msg;
10878
10879 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10880 wdev->netdev->ifindex))
10881 goto free_msg;
10882
10883 if (wakeup) {
10884 struct nlattr *reasons;
10885
10886 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10887
10888 if (wakeup->disconnect &&
10889 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10890 goto free_msg;
10891 if (wakeup->magic_pkt &&
10892 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10893 goto free_msg;
10894 if (wakeup->gtk_rekey_failure &&
10895 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10896 goto free_msg;
10897 if (wakeup->eap_identity_req &&
10898 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10899 goto free_msg;
10900 if (wakeup->four_way_handshake &&
10901 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10902 goto free_msg;
10903 if (wakeup->rfkill_release &&
10904 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10905 goto free_msg;
10906
10907 if (wakeup->pattern_idx >= 0 &&
10908 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10909 wakeup->pattern_idx))
10910 goto free_msg;
10911
Johannes Berg2a0e0472013-01-23 22:57:40 +010010912 if (wakeup->tcp_match)
10913 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10914
10915 if (wakeup->tcp_connlost)
10916 nla_put_flag(msg,
10917 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10918
10919 if (wakeup->tcp_nomoretokens)
10920 nla_put_flag(msg,
10921 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10922
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010923 if (wakeup->packet) {
10924 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10925 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10926
10927 if (!wakeup->packet_80211) {
10928 pkt_attr =
10929 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10930 len_attr =
10931 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10932 }
10933
10934 if (wakeup->packet_len &&
10935 nla_put_u32(msg, len_attr, wakeup->packet_len))
10936 goto free_msg;
10937
10938 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10939 wakeup->packet))
10940 goto free_msg;
10941 }
10942
10943 nla_nest_end(msg, reasons);
10944 }
10945
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010946 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010947
10948 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10949 nl80211_mlme_mcgrp.id, gfp);
10950 return;
10951
10952 free_msg:
10953 nlmsg_free(msg);
10954}
10955EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10956#endif
10957
Jouni Malinen3475b092012-11-16 22:49:57 +020010958void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10959 enum nl80211_tdls_operation oper,
10960 u16 reason_code, gfp_t gfp)
10961{
10962 struct wireless_dev *wdev = dev->ieee80211_ptr;
10963 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10964 struct sk_buff *msg;
10965 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010966
10967 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10968 reason_code);
10969
10970 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10971 if (!msg)
10972 return;
10973
10974 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10975 if (!hdr) {
10976 nlmsg_free(msg);
10977 return;
10978 }
10979
10980 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10981 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10982 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10983 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10984 (reason_code > 0 &&
10985 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10986 goto nla_put_failure;
10987
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010988 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010989
10990 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10991 nl80211_mlme_mcgrp.id, gfp);
10992 return;
10993
10994 nla_put_failure:
10995 genlmsg_cancel(msg, hdr);
10996 nlmsg_free(msg);
10997}
10998EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10999
Jouni Malinen026331c2010-02-15 12:53:10 +020011000static int nl80211_netlink_notify(struct notifier_block * nb,
11001 unsigned long state,
11002 void *_notify)
11003{
11004 struct netlink_notify *notify = _notify;
11005 struct cfg80211_registered_device *rdev;
11006 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011007 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011008
11009 if (state != NETLINK_URELEASE)
11010 return NOTIFY_DONE;
11011
11012 rcu_read_lock();
11013
Johannes Berg5e760232011-11-04 11:18:17 +010011014 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011015 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011016 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011017
11018 spin_lock_bh(&rdev->beacon_registrations_lock);
11019 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11020 list) {
11021 if (reg->nlportid == notify->portid) {
11022 list_del(&reg->list);
11023 kfree(reg);
11024 break;
11025 }
11026 }
11027 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011028 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011029
11030 rcu_read_unlock();
11031
11032 return NOTIFY_DONE;
11033}
11034
11035static struct notifier_block nl80211_netlink_notifier = {
11036 .notifier_call = nl80211_netlink_notify,
11037};
11038
Jouni Malinen355199e2013-02-27 17:14:27 +020011039void cfg80211_ft_event(struct net_device *netdev,
11040 struct cfg80211_ft_event_params *ft_event)
11041{
11042 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11043 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11044 struct sk_buff *msg;
11045 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011046
11047 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11048
11049 if (!ft_event->target_ap)
11050 return;
11051
11052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11053 if (!msg)
11054 return;
11055
11056 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11057 if (!hdr) {
11058 nlmsg_free(msg);
11059 return;
11060 }
11061
11062 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11063 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11064 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11065 if (ft_event->ies)
11066 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11067 if (ft_event->ric_ies)
11068 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11069 ft_event->ric_ies);
11070
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011071 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011072
11073 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11074 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11075}
11076EXPORT_SYMBOL(cfg80211_ft_event);
11077
Arend van Spriel5de17982013-04-18 15:49:00 +020011078void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11079{
11080 struct cfg80211_registered_device *rdev;
11081 struct sk_buff *msg;
11082 void *hdr;
11083 u32 nlportid;
11084
11085 rdev = wiphy_to_dev(wdev->wiphy);
11086 if (!rdev->crit_proto_nlportid)
11087 return;
11088
11089 nlportid = rdev->crit_proto_nlportid;
11090 rdev->crit_proto_nlportid = 0;
11091
11092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11093 if (!msg)
11094 return;
11095
11096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11097 if (!hdr)
11098 goto nla_put_failure;
11099
11100 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11101 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11102 goto nla_put_failure;
11103
11104 genlmsg_end(msg, hdr);
11105
11106 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11107 return;
11108
11109 nla_put_failure:
11110 if (hdr)
11111 genlmsg_cancel(msg, hdr);
11112 nlmsg_free(msg);
11113
11114}
11115EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11116
Johannes Berg55682962007-09-20 13:09:35 -040011117/* initialisation/exit functions */
11118
11119int nl80211_init(void)
11120{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011121 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011122
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011123 err = genl_register_family_with_ops(&nl80211_fam,
11124 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011125 if (err)
11126 return err;
11127
Johannes Berg55682962007-09-20 13:09:35 -040011128 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11129 if (err)
11130 goto err_out;
11131
Johannes Berg2a519312009-02-10 21:25:55 +010011132 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11133 if (err)
11134 goto err_out;
11135
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011136 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11137 if (err)
11138 goto err_out;
11139
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011140 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11141 if (err)
11142 goto err_out;
11143
Johannes Bergaff89a92009-07-01 21:26:51 +020011144#ifdef CONFIG_NL80211_TESTMODE
11145 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11146 if (err)
11147 goto err_out;
11148#endif
11149
Jouni Malinen026331c2010-02-15 12:53:10 +020011150 err = netlink_register_notifier(&nl80211_netlink_notifier);
11151 if (err)
11152 goto err_out;
11153
Johannes Berg55682962007-09-20 13:09:35 -040011154 return 0;
11155 err_out:
11156 genl_unregister_family(&nl80211_fam);
11157 return err;
11158}
11159
11160void nl80211_exit(void)
11161{
Jouni Malinen026331c2010-02-15 12:53:10 +020011162 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011163 genl_unregister_family(&nl80211_fam);
11164}