blob: 1ad11de6dd2f2bb15930b21eeb2274b031048185 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200352 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
353 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
354 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
355 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
356 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530357 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
358 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200359 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400360};
361
Johannes Berge31b8212010-10-05 19:39:30 +0200362/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000363static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200364 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200365 [NL80211_KEY_IDX] = { .type = NLA_U8 },
366 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200367 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200368 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
369 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200370 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100371 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
372};
373
374/* policy for the key default flags */
375static const struct nla_policy
376nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
377 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
378 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200379};
380
Johannes Bergff1b6e62011-05-04 15:37:28 +0200381/* policy for WoWLAN attributes */
382static const struct nla_policy
383nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
384 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
385 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200388 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
389 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
390 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
391 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100392 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
393};
394
395static const struct nla_policy
396nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
397 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
398 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
399 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
400 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
401 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
402 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
404 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
405 },
406 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
407 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
408 },
409 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
410 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
411 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200412};
413
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700414/* policy for coalesce rule attributes */
415static const struct nla_policy
416nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
417 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
418 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
419 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
420};
421
Johannes Berge5497d72011-07-05 16:35:40 +0200422/* policy for GTK rekey offload attributes */
423static const struct nla_policy
424nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
425 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
426 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
427 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
428};
429
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300430static const struct nla_policy
431nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200432 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300433 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700434 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300435};
436
Johannes Berg97990a02013-04-19 01:02:55 +0200437static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
438 struct netlink_callback *cb,
439 struct cfg80211_registered_device **rdev,
440 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100441{
Johannes Berg67748892010-10-04 21:14:06 +0200442 int err;
443
Johannes Berg67748892010-10-04 21:14:06 +0200444 rtnl_lock();
445
Johannes Berg97990a02013-04-19 01:02:55 +0200446 if (!cb->args[0]) {
447 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
448 nl80211_fam.attrbuf, nl80211_fam.maxattr,
449 nl80211_policy);
450 if (err)
451 goto out_unlock;
452
453 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
454 nl80211_fam.attrbuf);
455 if (IS_ERR(*wdev)) {
456 err = PTR_ERR(*wdev);
457 goto out_unlock;
458 }
459 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200460 /* 0 is the first index - add 1 to parse only once */
461 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200462 cb->args[1] = (*wdev)->identifier;
463 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200464 /* subtract the 1 again here */
465 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200466 struct wireless_dev *tmp;
467
468 if (!wiphy) {
469 err = -ENODEV;
470 goto out_unlock;
471 }
472 *rdev = wiphy_to_dev(wiphy);
473 *wdev = NULL;
474
Johannes Berg97990a02013-04-19 01:02:55 +0200475 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
476 if (tmp->identifier == cb->args[1]) {
477 *wdev = tmp;
478 break;
479 }
480 }
Johannes Berg97990a02013-04-19 01:02:55 +0200481
482 if (!*wdev) {
483 err = -ENODEV;
484 goto out_unlock;
485 }
Johannes Berg67748892010-10-04 21:14:06 +0200486 }
487
Johannes Berg67748892010-10-04 21:14:06 +0200488 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200489 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200490 rtnl_unlock();
491 return err;
492}
493
Johannes Berg97990a02013-04-19 01:02:55 +0200494static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200495{
Johannes Berg67748892010-10-04 21:14:06 +0200496 rtnl_unlock();
497}
498
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100499/* IE validation */
500static bool is_valid_ie_attr(const struct nlattr *attr)
501{
502 const u8 *pos;
503 int len;
504
505 if (!attr)
506 return true;
507
508 pos = nla_data(attr);
509 len = nla_len(attr);
510
511 while (len) {
512 u8 elemlen;
513
514 if (len < 2)
515 return false;
516 len -= 2;
517
518 elemlen = pos[1];
519 if (elemlen > len)
520 return false;
521
522 len -= elemlen;
523 pos += 2 + elemlen;
524 }
525
526 return true;
527}
528
Johannes Berg55682962007-09-20 13:09:35 -0400529/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000530static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400531 int flags, u8 cmd)
532{
533 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000534 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400535}
536
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400537static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100538 struct ieee80211_channel *chan,
539 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400540{
David S. Miller9360ffd2012-03-29 04:41:26 -0400541 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
542 chan->center_freq))
543 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400544
David S. Miller9360ffd2012-03-29 04:41:26 -0400545 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
546 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
547 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200548 if (chan->flags & IEEE80211_CHAN_NO_IR) {
549 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
550 goto nla_put_failure;
551 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
552 goto nla_put_failure;
553 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100554 if (chan->flags & IEEE80211_CHAN_RADAR) {
555 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
556 goto nla_put_failure;
557 if (large) {
558 u32 time;
559
560 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
561
562 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
563 chan->dfs_state))
564 goto nla_put_failure;
565 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
566 time))
567 goto nla_put_failure;
568 }
569 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400570
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100571 if (large) {
572 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
573 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
574 goto nla_put_failure;
575 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
576 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
577 goto nla_put_failure;
578 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
579 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
580 goto nla_put_failure;
581 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
582 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
583 goto nla_put_failure;
584 }
585
David S. Miller9360ffd2012-03-29 04:41:26 -0400586 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
587 DBM_TO_MBM(chan->max_power)))
588 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400589
590 return 0;
591
592 nla_put_failure:
593 return -ENOBUFS;
594}
595
Johannes Berg55682962007-09-20 13:09:35 -0400596/* netlink command implementations */
597
Johannes Bergb9454e82009-07-08 13:29:08 +0200598struct key_parse {
599 struct key_params p;
600 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200601 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200602 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100603 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200604};
605
606static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
607{
608 struct nlattr *tb[NL80211_KEY_MAX + 1];
609 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
610 nl80211_key_policy);
611 if (err)
612 return err;
613
614 k->def = !!tb[NL80211_KEY_DEFAULT];
615 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
616
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100617 if (k->def) {
618 k->def_uni = true;
619 k->def_multi = true;
620 }
621 if (k->defmgmt)
622 k->def_multi = true;
623
Johannes Bergb9454e82009-07-08 13:29:08 +0200624 if (tb[NL80211_KEY_IDX])
625 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
626
627 if (tb[NL80211_KEY_DATA]) {
628 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
629 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
630 }
631
632 if (tb[NL80211_KEY_SEQ]) {
633 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
634 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
635 }
636
637 if (tb[NL80211_KEY_CIPHER])
638 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
639
Johannes Berge31b8212010-10-05 19:39:30 +0200640 if (tb[NL80211_KEY_TYPE]) {
641 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
642 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
643 return -EINVAL;
644 }
645
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100646 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
647 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100648 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
649 tb[NL80211_KEY_DEFAULT_TYPES],
650 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100651 if (err)
652 return err;
653
654 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
655 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
656 }
657
Johannes Bergb9454e82009-07-08 13:29:08 +0200658 return 0;
659}
660
661static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
662{
663 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
664 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
665 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
666 }
667
668 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
669 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
670 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
671 }
672
673 if (info->attrs[NL80211_ATTR_KEY_IDX])
674 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
675
676 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
677 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
678
679 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
680 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
681
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100682 if (k->def) {
683 k->def_uni = true;
684 k->def_multi = true;
685 }
686 if (k->defmgmt)
687 k->def_multi = true;
688
Johannes Berge31b8212010-10-05 19:39:30 +0200689 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
690 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
691 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
692 return -EINVAL;
693 }
694
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100695 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
696 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
697 int err = nla_parse_nested(
698 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
699 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
700 nl80211_key_default_policy);
701 if (err)
702 return err;
703
704 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
705 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
706 }
707
Johannes Bergb9454e82009-07-08 13:29:08 +0200708 return 0;
709}
710
711static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
712{
713 int err;
714
715 memset(k, 0, sizeof(*k));
716 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200717 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200718
719 if (info->attrs[NL80211_ATTR_KEY])
720 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
721 else
722 err = nl80211_parse_key_old(info, k);
723
724 if (err)
725 return err;
726
727 if (k->def && k->defmgmt)
728 return -EINVAL;
729
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100730 if (k->defmgmt) {
731 if (k->def_uni || !k->def_multi)
732 return -EINVAL;
733 }
734
Johannes Bergb9454e82009-07-08 13:29:08 +0200735 if (k->idx != -1) {
736 if (k->defmgmt) {
737 if (k->idx < 4 || k->idx > 5)
738 return -EINVAL;
739 } else if (k->def) {
740 if (k->idx < 0 || k->idx > 3)
741 return -EINVAL;
742 } else {
743 if (k->idx < 0 || k->idx > 5)
744 return -EINVAL;
745 }
746 }
747
748 return 0;
749}
750
Johannes Bergfffd0932009-07-08 14:22:54 +0200751static struct cfg80211_cached_keys *
752nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530753 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200754{
755 struct key_parse parse;
756 struct nlattr *key;
757 struct cfg80211_cached_keys *result;
758 int rem, err, def = 0;
759
760 result = kzalloc(sizeof(*result), GFP_KERNEL);
761 if (!result)
762 return ERR_PTR(-ENOMEM);
763
764 result->def = -1;
765 result->defmgmt = -1;
766
767 nla_for_each_nested(key, keys, rem) {
768 memset(&parse, 0, sizeof(parse));
769 parse.idx = -1;
770
771 err = nl80211_parse_key_new(key, &parse);
772 if (err)
773 goto error;
774 err = -EINVAL;
775 if (!parse.p.key)
776 goto error;
777 if (parse.idx < 0 || parse.idx > 4)
778 goto error;
779 if (parse.def) {
780 if (def)
781 goto error;
782 def = 1;
783 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100784 if (!parse.def_uni || !parse.def_multi)
785 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200786 } else if (parse.defmgmt)
787 goto error;
788 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200789 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200790 if (err)
791 goto error;
792 result->params[parse.idx].cipher = parse.p.cipher;
793 result->params[parse.idx].key_len = parse.p.key_len;
794 result->params[parse.idx].key = result->data[parse.idx];
795 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530796
797 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
798 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
799 if (no_ht)
800 *no_ht = true;
801 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200802 }
803
804 return result;
805 error:
806 kfree(result);
807 return ERR_PTR(err);
808}
809
810static int nl80211_key_allowed(struct wireless_dev *wdev)
811{
812 ASSERT_WDEV_LOCK(wdev);
813
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 switch (wdev->iftype) {
815 case NL80211_IFTYPE_AP:
816 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200817 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700818 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200819 break;
820 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200821 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200822 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200823 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200824 return -ENOLINK;
825 break;
826 default:
827 return -EINVAL;
828 }
829
830 return 0;
831}
832
Johannes Berg7527a782011-05-13 10:58:57 +0200833static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
834{
835 struct nlattr *nl_modes = nla_nest_start(msg, attr);
836 int i;
837
838 if (!nl_modes)
839 goto nla_put_failure;
840
841 i = 0;
842 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400843 if ((ifmodes & 1) && nla_put_flag(msg, i))
844 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200845 ifmodes >>= 1;
846 i++;
847 }
848
849 nla_nest_end(msg, nl_modes);
850 return 0;
851
852nla_put_failure:
853 return -ENOBUFS;
854}
855
856static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100857 struct sk_buff *msg,
858 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200859{
860 struct nlattr *nl_combis;
861 int i, j;
862
863 nl_combis = nla_nest_start(msg,
864 NL80211_ATTR_INTERFACE_COMBINATIONS);
865 if (!nl_combis)
866 goto nla_put_failure;
867
868 for (i = 0; i < wiphy->n_iface_combinations; i++) {
869 const struct ieee80211_iface_combination *c;
870 struct nlattr *nl_combi, *nl_limits;
871
872 c = &wiphy->iface_combinations[i];
873
874 nl_combi = nla_nest_start(msg, i + 1);
875 if (!nl_combi)
876 goto nla_put_failure;
877
878 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
879 if (!nl_limits)
880 goto nla_put_failure;
881
882 for (j = 0; j < c->n_limits; j++) {
883 struct nlattr *nl_limit;
884
885 nl_limit = nla_nest_start(msg, j + 1);
886 if (!nl_limit)
887 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400888 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
889 c->limits[j].max))
890 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200891 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
892 c->limits[j].types))
893 goto nla_put_failure;
894 nla_nest_end(msg, nl_limit);
895 }
896
897 nla_nest_end(msg, nl_limits);
898
David S. Miller9360ffd2012-03-29 04:41:26 -0400899 if (c->beacon_int_infra_match &&
900 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
901 goto nla_put_failure;
902 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
903 c->num_different_channels) ||
904 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
905 c->max_interfaces))
906 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100907 if (large &&
908 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
909 c->radar_detect_widths))
910 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200911
912 nla_nest_end(msg, nl_combi);
913 }
914
915 nla_nest_end(msg, nl_combis);
916
917 return 0;
918nla_put_failure:
919 return -ENOBUFS;
920}
921
Johannes Berg3713b4e2013-02-14 16:19:38 +0100922#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100923static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
924 struct sk_buff *msg)
925{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200926 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100927 struct nlattr *nl_tcp;
928
929 if (!tcp)
930 return 0;
931
932 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
933 if (!nl_tcp)
934 return -ENOBUFS;
935
936 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
937 tcp->data_payload_max))
938 return -ENOBUFS;
939
940 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
941 tcp->data_payload_max))
942 return -ENOBUFS;
943
944 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
945 return -ENOBUFS;
946
947 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
948 sizeof(*tcp->tok), tcp->tok))
949 return -ENOBUFS;
950
951 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
952 tcp->data_interval_max))
953 return -ENOBUFS;
954
955 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
956 tcp->wake_payload_max))
957 return -ENOBUFS;
958
959 nla_nest_end(msg, nl_tcp);
960 return 0;
961}
962
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100964 struct cfg80211_registered_device *dev,
965 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100966{
967 struct nlattr *nl_wowlan;
968
Johannes Berg964dc9e2013-06-03 17:25:34 +0200969 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100970 return 0;
971
972 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
973 if (!nl_wowlan)
974 return -ENOBUFS;
975
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100979 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200980 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200982 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100983 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200984 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100985 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200986 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100987 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200988 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100989 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200990 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100991 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
992 return -ENOBUFS;
993
Johannes Berg964dc9e2013-06-03 17:25:34 +0200994 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700995 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200996 .max_patterns = dev->wiphy.wowlan->n_patterns,
997 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
998 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
999 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001000 };
1001
1002 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1003 sizeof(pat), &pat))
1004 return -ENOBUFS;
1005 }
1006
Johannes Bergb56cf722013-02-20 01:02:38 +01001007 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1008 return -ENOBUFS;
1009
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 nla_nest_end(msg, nl_wowlan);
1011
1012 return 0;
1013}
1014#endif
1015
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001016static int nl80211_send_coalesce(struct sk_buff *msg,
1017 struct cfg80211_registered_device *dev)
1018{
1019 struct nl80211_coalesce_rule_support rule;
1020
1021 if (!dev->wiphy.coalesce)
1022 return 0;
1023
1024 rule.max_rules = dev->wiphy.coalesce->n_rules;
1025 rule.max_delay = dev->wiphy.coalesce->max_delay;
1026 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1027 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1028 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1029 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1030
1031 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1032 return -ENOBUFS;
1033
1034 return 0;
1035}
1036
Johannes Berg3713b4e2013-02-14 16:19:38 +01001037static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1038 struct ieee80211_supported_band *sband)
1039{
1040 struct nlattr *nl_rates, *nl_rate;
1041 struct ieee80211_rate *rate;
1042 int i;
1043
1044 /* add HT info */
1045 if (sband->ht_cap.ht_supported &&
1046 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1047 sizeof(sband->ht_cap.mcs),
1048 &sband->ht_cap.mcs) ||
1049 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1050 sband->ht_cap.cap) ||
1051 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1052 sband->ht_cap.ampdu_factor) ||
1053 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1054 sband->ht_cap.ampdu_density)))
1055 return -ENOBUFS;
1056
1057 /* add VHT info */
1058 if (sband->vht_cap.vht_supported &&
1059 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1060 sizeof(sband->vht_cap.vht_mcs),
1061 &sband->vht_cap.vht_mcs) ||
1062 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1063 sband->vht_cap.cap)))
1064 return -ENOBUFS;
1065
1066 /* add bitrates */
1067 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1068 if (!nl_rates)
1069 return -ENOBUFS;
1070
1071 for (i = 0; i < sband->n_bitrates; i++) {
1072 nl_rate = nla_nest_start(msg, i);
1073 if (!nl_rate)
1074 return -ENOBUFS;
1075
1076 rate = &sband->bitrates[i];
1077 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1078 rate->bitrate))
1079 return -ENOBUFS;
1080 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1081 nla_put_flag(msg,
1082 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1083 return -ENOBUFS;
1084
1085 nla_nest_end(msg, nl_rate);
1086 }
1087
1088 nla_nest_end(msg, nl_rates);
1089
1090 return 0;
1091}
1092
1093static int
1094nl80211_send_mgmt_stypes(struct sk_buff *msg,
1095 const struct ieee80211_txrx_stypes *mgmt_stypes)
1096{
1097 u16 stypes;
1098 struct nlattr *nl_ftypes, *nl_ifs;
1099 enum nl80211_iftype ift;
1100 int i;
1101
1102 if (!mgmt_stypes)
1103 return 0;
1104
1105 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1106 if (!nl_ifs)
1107 return -ENOBUFS;
1108
1109 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1110 nl_ftypes = nla_nest_start(msg, ift);
1111 if (!nl_ftypes)
1112 return -ENOBUFS;
1113 i = 0;
1114 stypes = mgmt_stypes[ift].tx;
1115 while (stypes) {
1116 if ((stypes & 1) &&
1117 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1118 (i << 4) | IEEE80211_FTYPE_MGMT))
1119 return -ENOBUFS;
1120 stypes >>= 1;
1121 i++;
1122 }
1123 nla_nest_end(msg, nl_ftypes);
1124 }
1125
1126 nla_nest_end(msg, nl_ifs);
1127
1128 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1129 if (!nl_ifs)
1130 return -ENOBUFS;
1131
1132 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1133 nl_ftypes = nla_nest_start(msg, ift);
1134 if (!nl_ftypes)
1135 return -ENOBUFS;
1136 i = 0;
1137 stypes = mgmt_stypes[ift].rx;
1138 while (stypes) {
1139 if ((stypes & 1) &&
1140 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1141 (i << 4) | IEEE80211_FTYPE_MGMT))
1142 return -ENOBUFS;
1143 stypes >>= 1;
1144 i++;
1145 }
1146 nla_nest_end(msg, nl_ftypes);
1147 }
1148 nla_nest_end(msg, nl_ifs);
1149
1150 return 0;
1151}
1152
Johannes Berg86e8cf92013-06-19 10:57:22 +02001153struct nl80211_dump_wiphy_state {
1154 s64 filter_wiphy;
1155 long start;
1156 long split_start, band_start, chan_start;
1157 bool split;
1158};
1159
Johannes Berg3713b4e2013-02-14 16:19:38 +01001160static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1161 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001162 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001163{
1164 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001165 struct nlattr *nl_bands, *nl_band;
1166 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001167 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001168 enum ieee80211_band band;
1169 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001170 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001171 const struct ieee80211_txrx_stypes *mgmt_stypes =
1172 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001173 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001174
Eric W. Biederman15e47302012-09-07 20:12:54 +00001175 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001176 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001177 return -ENOBUFS;
1178
Johannes Berg86e8cf92013-06-19 10:57:22 +02001179 if (WARN_ON(!state))
1180 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001181
David S. Miller9360ffd2012-03-29 04:41:26 -04001182 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001183 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1184 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001185 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001186 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001187 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001188
Johannes Berg86e8cf92013-06-19 10:57:22 +02001189 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001190 case 0:
1191 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1192 dev->wiphy.retry_short) ||
1193 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1194 dev->wiphy.retry_long) ||
1195 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1196 dev->wiphy.frag_threshold) ||
1197 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1198 dev->wiphy.rts_threshold) ||
1199 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1200 dev->wiphy.coverage_class) ||
1201 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1202 dev->wiphy.max_scan_ssids) ||
1203 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1204 dev->wiphy.max_sched_scan_ssids) ||
1205 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1206 dev->wiphy.max_scan_ie_len) ||
1207 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1208 dev->wiphy.max_sched_scan_ie_len) ||
1209 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1210 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001211 goto nla_put_failure;
1212
Johannes Berg3713b4e2013-02-14 16:19:38 +01001213 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1214 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1215 goto nla_put_failure;
1216 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1217 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1218 goto nla_put_failure;
1219 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1220 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1221 goto nla_put_failure;
1222 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1223 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1224 goto nla_put_failure;
1225 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1226 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1227 goto nla_put_failure;
1228 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1229 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001230 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001231 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1232 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1233 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001234
Johannes Berg86e8cf92013-06-19 10:57:22 +02001235 state->split_start++;
1236 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001237 break;
1238 case 1:
1239 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1240 sizeof(u32) * dev->wiphy.n_cipher_suites,
1241 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001242 goto nla_put_failure;
1243
Johannes Berg3713b4e2013-02-14 16:19:38 +01001244 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1245 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001246 goto nla_put_failure;
1247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1249 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1250 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001251
Johannes Berg3713b4e2013-02-14 16:19:38 +01001252 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1253 dev->wiphy.available_antennas_tx) ||
1254 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1255 dev->wiphy.available_antennas_rx))
1256 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001257
Johannes Berg3713b4e2013-02-14 16:19:38 +01001258 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1259 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1260 dev->wiphy.probe_resp_offload))
1261 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001262
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 if ((dev->wiphy.available_antennas_tx ||
1264 dev->wiphy.available_antennas_rx) &&
1265 dev->ops->get_antenna) {
1266 u32 tx_ant = 0, rx_ant = 0;
1267 int res;
1268 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1269 if (!res) {
1270 if (nla_put_u32(msg,
1271 NL80211_ATTR_WIPHY_ANTENNA_TX,
1272 tx_ant) ||
1273 nla_put_u32(msg,
1274 NL80211_ATTR_WIPHY_ANTENNA_RX,
1275 rx_ant))
1276 goto nla_put_failure;
1277 }
Johannes Bergee688b002008-01-24 19:38:39 +01001278 }
1279
Johannes Berg86e8cf92013-06-19 10:57:22 +02001280 state->split_start++;
1281 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 break;
1283 case 2:
1284 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1285 dev->wiphy.interface_modes))
1286 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001287 state->split_start++;
1288 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 break;
1290 case 3:
1291 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1292 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001293 goto nla_put_failure;
1294
Johannes Berg86e8cf92013-06-19 10:57:22 +02001295 for (band = state->band_start;
1296 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 struct ieee80211_supported_band *sband;
1298
1299 sband = dev->wiphy.bands[band];
1300
1301 if (!sband)
1302 continue;
1303
1304 nl_band = nla_nest_start(msg, band);
1305 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001306 goto nla_put_failure;
1307
Johannes Berg86e8cf92013-06-19 10:57:22 +02001308 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 case 0:
1310 if (nl80211_send_band_rateinfo(msg, sband))
1311 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001312 state->chan_start++;
1313 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 break;
1315 default:
1316 /* add frequencies */
1317 nl_freqs = nla_nest_start(
1318 msg, NL80211_BAND_ATTR_FREQS);
1319 if (!nl_freqs)
1320 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001321
Johannes Berg86e8cf92013-06-19 10:57:22 +02001322 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 i < sband->n_channels;
1324 i++) {
1325 nl_freq = nla_nest_start(msg, i);
1326 if (!nl_freq)
1327 goto nla_put_failure;
1328
1329 chan = &sband->channels[i];
1330
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 if (nl80211_msg_put_channel(
1332 msg, chan,
1333 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 goto nla_put_failure;
1335
1336 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001337 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 break;
1339 }
1340 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001343 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_nest_end(msg, nl_freqs);
1345 }
1346
1347 nla_nest_end(msg, nl_band);
1348
Johannes Berg86e8cf92013-06-19 10:57:22 +02001349 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001351 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 band--;
1353 break;
1354 }
Johannes Bergee688b002008-01-24 19:38:39 +01001355 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001357
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001359 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001361 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001362
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001364 if (state->band_start == 0 && state->chan_start == 0)
1365 state->split_start++;
1366 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 break;
1368 case 4:
1369 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1370 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001371 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372
1373 i = 0;
1374#define CMD(op, n) \
1375 do { \
1376 if (dev->ops->op) { \
1377 i++; \
1378 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1379 goto nla_put_failure; \
1380 } \
1381 } while (0)
1382
1383 CMD(add_virtual_intf, NEW_INTERFACE);
1384 CMD(change_virtual_intf, SET_INTERFACE);
1385 CMD(add_key, NEW_KEY);
1386 CMD(start_ap, START_AP);
1387 CMD(add_station, NEW_STATION);
1388 CMD(add_mpath, NEW_MPATH);
1389 CMD(update_mesh_config, SET_MESH_CONFIG);
1390 CMD(change_bss, SET_BSS);
1391 CMD(auth, AUTHENTICATE);
1392 CMD(assoc, ASSOCIATE);
1393 CMD(deauth, DEAUTHENTICATE);
1394 CMD(disassoc, DISASSOCIATE);
1395 CMD(join_ibss, JOIN_IBSS);
1396 CMD(join_mesh, JOIN_MESH);
1397 CMD(set_pmksa, SET_PMKSA);
1398 CMD(del_pmksa, DEL_PMKSA);
1399 CMD(flush_pmksa, FLUSH_PMKSA);
1400 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1401 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1402 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1403 CMD(mgmt_tx, FRAME);
1404 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1405 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1406 i++;
1407 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1408 goto nla_put_failure;
1409 }
1410 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1411 dev->ops->join_mesh) {
1412 i++;
1413 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1414 goto nla_put_failure;
1415 }
1416 CMD(set_wds_peer, SET_WDS_PEER);
1417 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1418 CMD(tdls_mgmt, TDLS_MGMT);
1419 CMD(tdls_oper, TDLS_OPER);
1420 }
1421 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1422 CMD(sched_scan_start, START_SCHED_SCAN);
1423 CMD(probe_client, PROBE_CLIENT);
1424 CMD(set_noack_map, SET_NOACK_MAP);
1425 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1426 i++;
1427 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1428 goto nla_put_failure;
1429 }
1430 CMD(start_p2p_device, START_P2P_DEVICE);
1431 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001433 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1434 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001435 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1436 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001437 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001438
Kalle Valo4745fc02011-11-17 19:06:10 +02001439#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001441#endif
1442
Johannes Berg8fdc6212009-03-14 09:34:01 +01001443#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001444
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 if (dev->ops->connect || dev->ops->auth) {
1446 i++;
1447 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001448 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001449 }
1450
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 if (dev->ops->disconnect || dev->ops->deauth) {
1452 i++;
1453 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1454 goto nla_put_failure;
1455 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001456
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001458 state->split_start++;
1459 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001460 break;
1461 case 5:
1462 if (dev->ops->remain_on_channel &&
1463 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1464 nla_put_u32(msg,
1465 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1466 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001467 goto nla_put_failure;
1468
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1470 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1471 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001472
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1474 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001475 state->split_start++;
1476 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 break;
1478 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001479#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001480 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001482 state->split_start++;
1483 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 break;
1485#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001486 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487#endif
1488 case 7:
1489 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1490 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001491 goto nla_put_failure;
1492
Johannes Berg86e8cf92013-06-19 10:57:22 +02001493 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1494 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001496
Johannes Berg86e8cf92013-06-19 10:57:22 +02001497 state->split_start++;
1498 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 break;
1500 case 8:
1501 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1502 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1503 dev->wiphy.ap_sme_capa))
1504 goto nla_put_failure;
1505
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001506 features = dev->wiphy.features;
1507 /*
1508 * We can only add the per-channel limit information if the
1509 * dump is split, otherwise it makes it too big. Therefore
1510 * only advertise it in that case.
1511 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001512 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001513 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1514 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 goto nla_put_failure;
1516
1517 if (dev->wiphy.ht_capa_mod_mask &&
1518 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1519 sizeof(*dev->wiphy.ht_capa_mod_mask),
1520 dev->wiphy.ht_capa_mod_mask))
1521 goto nla_put_failure;
1522
1523 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1524 dev->wiphy.max_acl_mac_addrs &&
1525 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1526 dev->wiphy.max_acl_mac_addrs))
1527 goto nla_put_failure;
1528
1529 /*
1530 * Any information below this point is only available to
1531 * applications that can deal with it being split. This
1532 * helps ensure that newly added capabilities don't break
1533 * older tools by overrunning their buffers.
1534 *
1535 * We still increment split_start so that in the split
1536 * case we'll continue with more data in the next round,
1537 * but break unconditionally so unsplit data stops here.
1538 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001539 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 break;
1541 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001542 if (dev->wiphy.extended_capabilities &&
1543 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1544 dev->wiphy.extended_capabilities_len,
1545 dev->wiphy.extended_capabilities) ||
1546 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1547 dev->wiphy.extended_capabilities_len,
1548 dev->wiphy.extended_capabilities_mask)))
1549 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550
Johannes Bergee2aca32013-02-21 17:36:01 +01001551 if (dev->wiphy.vht_capa_mod_mask &&
1552 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1553 sizeof(*dev->wiphy.vht_capa_mod_mask),
1554 dev->wiphy.vht_capa_mod_mask))
1555 goto nla_put_failure;
1556
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001557 state->split_start++;
1558 break;
1559 case 10:
1560 if (nl80211_send_coalesce(msg, dev))
1561 goto nla_put_failure;
1562
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001564 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001566 }
Johannes Berg55682962007-09-20 13:09:35 -04001567 return genlmsg_end(msg, hdr);
1568
1569 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001570 genlmsg_cancel(msg, hdr);
1571 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001572}
1573
Johannes Berg86e8cf92013-06-19 10:57:22 +02001574static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1575 struct netlink_callback *cb,
1576 struct nl80211_dump_wiphy_state *state)
1577{
1578 struct nlattr **tb = nl80211_fam.attrbuf;
1579 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1580 tb, nl80211_fam.maxattr, nl80211_policy);
1581 /* ignore parse errors for backward compatibility */
1582 if (ret)
1583 return 0;
1584
1585 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1586 if (tb[NL80211_ATTR_WIPHY])
1587 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1588 if (tb[NL80211_ATTR_WDEV])
1589 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1590 if (tb[NL80211_ATTR_IFINDEX]) {
1591 struct net_device *netdev;
1592 struct cfg80211_registered_device *rdev;
1593 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1594
1595 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1596 if (!netdev)
1597 return -ENODEV;
1598 if (netdev->ieee80211_ptr) {
1599 rdev = wiphy_to_dev(
1600 netdev->ieee80211_ptr->wiphy);
1601 state->filter_wiphy = rdev->wiphy_idx;
1602 }
1603 dev_put(netdev);
1604 }
1605
1606 return 0;
1607}
1608
Johannes Berg55682962007-09-20 13:09:35 -04001609static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1610{
Johannes Berg645e77d2013-03-01 14:03:49 +01001611 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001612 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001613 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001614
Johannes Berg5fe231e2013-05-08 21:45:15 +02001615 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001616 if (!state) {
1617 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001618 if (!state) {
1619 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001620 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001621 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001622 state->filter_wiphy = -1;
1623 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1624 if (ret) {
1625 kfree(state);
1626 rtnl_unlock();
1627 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001628 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001629 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001630 }
1631
Johannes Berg79c97e92009-07-07 03:56:12 +02001632 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001633 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1634 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001635 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001636 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001637 if (state->filter_wiphy != -1 &&
1638 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001639 continue;
1640 /* attempt to fit multiple wiphy data chunks into the skb */
1641 do {
1642 ret = nl80211_send_wiphy(dev, skb,
1643 NETLINK_CB(cb->skb).portid,
1644 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001645 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646 if (ret < 0) {
1647 /*
1648 * If sending the wiphy data didn't fit (ENOBUFS
1649 * or EMSGSIZE returned), this SKB is still
1650 * empty (so it's not too big because another
1651 * wiphy dataset is already in the skb) and
1652 * we've not tried to adjust the dump allocation
1653 * yet ... then adjust the alloc size to be
1654 * bigger, and return 1 but with the empty skb.
1655 * This results in an empty message being RX'ed
1656 * in userspace, but that is ignored.
1657 *
1658 * We can then retry with the larger buffer.
1659 */
1660 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1661 !skb->len &&
1662 cb->min_dump_alloc < 4096) {
1663 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001664 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001665 return 1;
1666 }
1667 idx--;
1668 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001669 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001670 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001671 break;
Johannes Berg55682962007-09-20 13:09:35 -04001672 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001673 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001674
Johannes Berg86e8cf92013-06-19 10:57:22 +02001675 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001676
1677 return skb->len;
1678}
1679
Johannes Berg86e8cf92013-06-19 10:57:22 +02001680static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1681{
1682 kfree((void *)cb->args[0]);
1683 return 0;
1684}
1685
Johannes Berg55682962007-09-20 13:09:35 -04001686static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1687{
1688 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001689 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001690 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001691
Johannes Berg645e77d2013-03-01 14:03:49 +01001692 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001693 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001694 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001695
Johannes Berg3713b4e2013-02-14 16:19:38 +01001696 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001697 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001698 nlmsg_free(msg);
1699 return -ENOBUFS;
1700 }
Johannes Berg55682962007-09-20 13:09:35 -04001701
Johannes Berg134e6372009-07-10 09:51:34 +00001702 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001703}
1704
Jouni Malinen31888482008-10-30 16:59:24 +02001705static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1706 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1707 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1708 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1709 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1710 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1711};
1712
1713static int parse_txq_params(struct nlattr *tb[],
1714 struct ieee80211_txq_params *txq_params)
1715{
Johannes Berga3304b02012-03-28 11:04:24 +02001716 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001717 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1718 !tb[NL80211_TXQ_ATTR_AIFS])
1719 return -EINVAL;
1720
Johannes Berga3304b02012-03-28 11:04:24 +02001721 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001722 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1723 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1724 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1725 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1726
Johannes Berga3304b02012-03-28 11:04:24 +02001727 if (txq_params->ac >= NL80211_NUM_ACS)
1728 return -EINVAL;
1729
Jouni Malinen31888482008-10-30 16:59:24 +02001730 return 0;
1731}
1732
Johannes Bergf444de02010-05-05 15:25:02 +02001733static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1734{
1735 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001736 * You can only set the channel explicitly for WDS interfaces,
1737 * all others have their channel managed via their respective
1738 * "establish a connection" command (connect, join, ...)
1739 *
1740 * For AP/GO and mesh mode, the channel can be set with the
1741 * channel userspace API, but is only stored and passed to the
1742 * low-level driver when the AP starts or the mesh is joined.
1743 * This is for backward compatibility, userspace can also give
1744 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001745 *
1746 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001747 * whatever else is going on, so they have their own special
1748 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001749 */
1750 return !wdev ||
1751 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001752 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001753 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1754 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001755}
1756
Johannes Berg683b6d32012-11-08 21:25:48 +01001757static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1758 struct genl_info *info,
1759 struct cfg80211_chan_def *chandef)
1760{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301761 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001762
1763 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1764 return -EINVAL;
1765
1766 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1767
1768 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001769 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1770 chandef->center_freq1 = control_freq;
1771 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001772
1773 /* Primary channel not allowed */
1774 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1775 return -EINVAL;
1776
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001777 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1778 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001779
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001780 chantype = nla_get_u32(
1781 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1782
1783 switch (chantype) {
1784 case NL80211_CHAN_NO_HT:
1785 case NL80211_CHAN_HT20:
1786 case NL80211_CHAN_HT40PLUS:
1787 case NL80211_CHAN_HT40MINUS:
1788 cfg80211_chandef_create(chandef, chandef->chan,
1789 chantype);
1790 break;
1791 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001792 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001793 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001794 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1795 chandef->width =
1796 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1797 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1798 chandef->center_freq1 =
1799 nla_get_u32(
1800 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1801 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1802 chandef->center_freq2 =
1803 nla_get_u32(
1804 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1805 }
1806
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001807 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001808 return -EINVAL;
1809
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001810 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1811 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001812 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001813
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001814 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1815 chandef->width == NL80211_CHAN_WIDTH_10) &&
1816 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1817 return -EINVAL;
1818
Johannes Berg683b6d32012-11-08 21:25:48 +01001819 return 0;
1820}
1821
Johannes Bergf444de02010-05-05 15:25:02 +02001822static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1823 struct wireless_dev *wdev,
1824 struct genl_info *info)
1825{
Johannes Berg683b6d32012-11-08 21:25:48 +01001826 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001827 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001828 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1829
1830 if (wdev)
1831 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001832
Johannes Bergf444de02010-05-05 15:25:02 +02001833 if (!nl80211_can_set_dev_channel(wdev))
1834 return -EOPNOTSUPP;
1835
Johannes Berg683b6d32012-11-08 21:25:48 +01001836 result = nl80211_parse_chandef(rdev, info, &chandef);
1837 if (result)
1838 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001839
Johannes Berge8c9bd52012-06-06 08:18:22 +02001840 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001841 case NL80211_IFTYPE_AP:
1842 case NL80211_IFTYPE_P2P_GO:
1843 if (wdev->beacon_interval) {
1844 result = -EBUSY;
1845 break;
1846 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001847 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001848 result = -EINVAL;
1849 break;
1850 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001851 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001852 result = 0;
1853 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001854 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001855 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001856 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001857 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001858 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001859 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001860 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001861 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001862 }
Johannes Bergf444de02010-05-05 15:25:02 +02001863
1864 return result;
1865}
1866
1867static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1868{
Johannes Berg4c476992010-10-04 21:36:35 +02001869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1870 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001871
Johannes Berg4c476992010-10-04 21:36:35 +02001872 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001873}
1874
Bill Jordane8347eb2010-10-01 13:54:28 -04001875static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1876{
Johannes Berg43b19952010-10-07 13:10:30 +02001877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1878 struct net_device *dev = info->user_ptr[1];
1879 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001880 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001881
1882 if (!info->attrs[NL80211_ATTR_MAC])
1883 return -EINVAL;
1884
Johannes Berg43b19952010-10-07 13:10:30 +02001885 if (netif_running(dev))
1886 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001887
Johannes Berg43b19952010-10-07 13:10:30 +02001888 if (!rdev->ops->set_wds_peer)
1889 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001890
Johannes Berg43b19952010-10-07 13:10:30 +02001891 if (wdev->iftype != NL80211_IFTYPE_WDS)
1892 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001893
1894 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001895 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001896}
1897
1898
Johannes Berg55682962007-09-20 13:09:35 -04001899static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1900{
1901 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001902 struct net_device *netdev = NULL;
1903 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001904 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001905 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001906 u32 changed;
1907 u8 retry_short = 0, retry_long = 0;
1908 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001909 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001910
Johannes Berg5fe231e2013-05-08 21:45:15 +02001911 ASSERT_RTNL();
1912
Johannes Bergf444de02010-05-05 15:25:02 +02001913 /*
1914 * Try to find the wiphy and netdev. Normally this
1915 * function shouldn't need the netdev, but this is
1916 * done for backward compatibility -- previously
1917 * setting the channel was done per wiphy, but now
1918 * it is per netdev. Previous userland like hostapd
1919 * also passed a netdev to set_wiphy, so that it is
1920 * possible to let that go to the right netdev!
1921 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001922
Johannes Bergf444de02010-05-05 15:25:02 +02001923 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1924 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1925
1926 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001927 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001928 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001929 else
Johannes Bergf444de02010-05-05 15:25:02 +02001930 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001931 }
1932
Johannes Bergf444de02010-05-05 15:25:02 +02001933 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001934 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1935 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001936 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001937 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001938 wdev = NULL;
1939 netdev = NULL;
1940 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001941 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001942 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001943
1944 /*
1945 * end workaround code, by now the rdev is available
1946 * and locked, and wdev may or may not be NULL.
1947 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001948
1949 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001950 result = cfg80211_dev_rename(
1951 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001952
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001953 if (result)
1954 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001955
Jouni Malinen31888482008-10-30 16:59:24 +02001956 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1957 struct ieee80211_txq_params txq_params;
1958 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1959
1960 if (!rdev->ops->set_txq_params) {
1961 result = -EOPNOTSUPP;
1962 goto bad_res;
1963 }
1964
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001965 if (!netdev) {
1966 result = -EINVAL;
1967 goto bad_res;
1968 }
1969
Johannes Berg133a3ff2011-11-03 14:50:13 +01001970 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1971 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1972 result = -EINVAL;
1973 goto bad_res;
1974 }
1975
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001976 if (!netif_running(netdev)) {
1977 result = -ENETDOWN;
1978 goto bad_res;
1979 }
1980
Jouni Malinen31888482008-10-30 16:59:24 +02001981 nla_for_each_nested(nl_txq_params,
1982 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1983 rem_txq_params) {
1984 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1985 nla_data(nl_txq_params),
1986 nla_len(nl_txq_params),
1987 txq_params_policy);
1988 result = parse_txq_params(tb, &txq_params);
1989 if (result)
1990 goto bad_res;
1991
Hila Gonene35e4d22012-06-27 17:19:42 +03001992 result = rdev_set_txq_params(rdev, netdev,
1993 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001994 if (result)
1995 goto bad_res;
1996 }
1997 }
1998
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001999 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002000 result = __nl80211_set_channel(rdev,
2001 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2002 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002003 if (result)
2004 goto bad_res;
2005 }
2006
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002007 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002008 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002009 enum nl80211_tx_power_setting type;
2010 int idx, mbm = 0;
2011
Johannes Bergc8442112012-10-24 10:17:18 +02002012 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2013 txp_wdev = NULL;
2014
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002015 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002016 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002017 goto bad_res;
2018 }
2019
2020 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2021 type = nla_get_u32(info->attrs[idx]);
2022
2023 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2024 (type != NL80211_TX_POWER_AUTOMATIC)) {
2025 result = -EINVAL;
2026 goto bad_res;
2027 }
2028
2029 if (type != NL80211_TX_POWER_AUTOMATIC) {
2030 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2031 mbm = nla_get_u32(info->attrs[idx]);
2032 }
2033
Johannes Bergc8442112012-10-24 10:17:18 +02002034 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002035 if (result)
2036 goto bad_res;
2037 }
2038
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002039 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2040 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2041 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002042 if ((!rdev->wiphy.available_antennas_tx &&
2043 !rdev->wiphy.available_antennas_rx) ||
2044 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002045 result = -EOPNOTSUPP;
2046 goto bad_res;
2047 }
2048
2049 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2050 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2051
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002052 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002053 * available antenna masks, except for the "all" mask */
2054 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2055 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002056 result = -EINVAL;
2057 goto bad_res;
2058 }
2059
Bruno Randolf7f531e02010-12-16 11:30:22 +09002060 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2061 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002062
Hila Gonene35e4d22012-06-27 17:19:42 +03002063 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002064 if (result)
2065 goto bad_res;
2066 }
2067
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002068 changed = 0;
2069
2070 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2071 retry_short = nla_get_u8(
2072 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2073 if (retry_short == 0) {
2074 result = -EINVAL;
2075 goto bad_res;
2076 }
2077 changed |= WIPHY_PARAM_RETRY_SHORT;
2078 }
2079
2080 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2081 retry_long = nla_get_u8(
2082 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2083 if (retry_long == 0) {
2084 result = -EINVAL;
2085 goto bad_res;
2086 }
2087 changed |= WIPHY_PARAM_RETRY_LONG;
2088 }
2089
2090 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2091 frag_threshold = nla_get_u32(
2092 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2093 if (frag_threshold < 256) {
2094 result = -EINVAL;
2095 goto bad_res;
2096 }
2097 if (frag_threshold != (u32) -1) {
2098 /*
2099 * Fragments (apart from the last one) are required to
2100 * have even length. Make the fragmentation code
2101 * simpler by stripping LSB should someone try to use
2102 * odd threshold value.
2103 */
2104 frag_threshold &= ~0x1;
2105 }
2106 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2107 }
2108
2109 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2110 rts_threshold = nla_get_u32(
2111 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2112 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2113 }
2114
Lukáš Turek81077e82009-12-21 22:50:47 +01002115 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2116 coverage_class = nla_get_u8(
2117 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2118 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2119 }
2120
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002121 if (changed) {
2122 u8 old_retry_short, old_retry_long;
2123 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002124 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002125
2126 if (!rdev->ops->set_wiphy_params) {
2127 result = -EOPNOTSUPP;
2128 goto bad_res;
2129 }
2130
2131 old_retry_short = rdev->wiphy.retry_short;
2132 old_retry_long = rdev->wiphy.retry_long;
2133 old_frag_threshold = rdev->wiphy.frag_threshold;
2134 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002135 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002136
2137 if (changed & WIPHY_PARAM_RETRY_SHORT)
2138 rdev->wiphy.retry_short = retry_short;
2139 if (changed & WIPHY_PARAM_RETRY_LONG)
2140 rdev->wiphy.retry_long = retry_long;
2141 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2142 rdev->wiphy.frag_threshold = frag_threshold;
2143 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2144 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002145 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2146 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002147
Hila Gonene35e4d22012-06-27 17:19:42 +03002148 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002149 if (result) {
2150 rdev->wiphy.retry_short = old_retry_short;
2151 rdev->wiphy.retry_long = old_retry_long;
2152 rdev->wiphy.frag_threshold = old_frag_threshold;
2153 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002154 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002155 }
2156 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002157
Johannes Berg306d6112008-12-08 12:39:04 +01002158 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002159 if (netdev)
2160 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002161 return result;
2162}
2163
Johannes Berg71bbc992012-06-15 15:30:18 +02002164static inline u64 wdev_id(struct wireless_dev *wdev)
2165{
2166 return (u64)wdev->identifier |
2167 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2168}
Johannes Berg55682962007-09-20 13:09:35 -04002169
Johannes Berg683b6d32012-11-08 21:25:48 +01002170static int nl80211_send_chandef(struct sk_buff *msg,
2171 struct cfg80211_chan_def *chandef)
2172{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002173 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002174
Johannes Berg683b6d32012-11-08 21:25:48 +01002175 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2176 chandef->chan->center_freq))
2177 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002178 switch (chandef->width) {
2179 case NL80211_CHAN_WIDTH_20_NOHT:
2180 case NL80211_CHAN_WIDTH_20:
2181 case NL80211_CHAN_WIDTH_40:
2182 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2183 cfg80211_get_chandef_type(chandef)))
2184 return -ENOBUFS;
2185 break;
2186 default:
2187 break;
2188 }
2189 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2190 return -ENOBUFS;
2191 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2192 return -ENOBUFS;
2193 if (chandef->center_freq2 &&
2194 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002195 return -ENOBUFS;
2196 return 0;
2197}
2198
Eric W. Biederman15e47302012-09-07 20:12:54 +00002199static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002200 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002201 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002202{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002203 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002204 void *hdr;
2205
Eric W. Biederman15e47302012-09-07 20:12:54 +00002206 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002207 if (!hdr)
2208 return -1;
2209
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002210 if (dev &&
2211 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002212 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002213 goto nla_put_failure;
2214
2215 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2216 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002217 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002218 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002219 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2220 rdev->devlist_generation ^
2221 (cfg80211_rdev_list_generation << 2)))
2222 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002223
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002224 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002225 int ret;
2226 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002227
Johannes Berg683b6d32012-11-08 21:25:48 +01002228 ret = rdev_get_channel(rdev, wdev, &chandef);
2229 if (ret == 0) {
2230 if (nl80211_send_chandef(msg, &chandef))
2231 goto nla_put_failure;
2232 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002233 }
2234
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002235 if (wdev->ssid_len) {
2236 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2237 goto nla_put_failure;
2238 }
2239
Johannes Berg55682962007-09-20 13:09:35 -04002240 return genlmsg_end(msg, hdr);
2241
2242 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002243 genlmsg_cancel(msg, hdr);
2244 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002245}
2246
2247static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2248{
2249 int wp_idx = 0;
2250 int if_idx = 0;
2251 int wp_start = cb->args[0];
2252 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002253 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002254 struct wireless_dev *wdev;
2255
Johannes Berg5fe231e2013-05-08 21:45:15 +02002256 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002257 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2258 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002259 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002260 if (wp_idx < wp_start) {
2261 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002262 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002263 }
Johannes Berg55682962007-09-20 13:09:35 -04002264 if_idx = 0;
2265
Johannes Berg89a54e42012-06-15 14:33:17 +02002266 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002267 if (if_idx < if_start) {
2268 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002269 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002270 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002271 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002272 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002273 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002274 goto out;
2275 }
2276 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002277 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002278
2279 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002280 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002281 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002282 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002283
2284 cb->args[0] = wp_idx;
2285 cb->args[1] = if_idx;
2286
2287 return skb->len;
2288}
2289
2290static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2291{
2292 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002293 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002294 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002295
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002296 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002297 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002298 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002299
Eric W. Biederman15e47302012-09-07 20:12:54 +00002300 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002301 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002302 nlmsg_free(msg);
2303 return -ENOBUFS;
2304 }
Johannes Berg55682962007-09-20 13:09:35 -04002305
Johannes Berg134e6372009-07-10 09:51:34 +00002306 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002307}
2308
Michael Wu66f7ac52008-01-31 19:48:22 +01002309static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2310 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2311 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2312 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2313 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2314 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002315 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002316};
2317
2318static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2319{
2320 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2321 int flag;
2322
2323 *mntrflags = 0;
2324
2325 if (!nla)
2326 return -EINVAL;
2327
2328 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2329 nla, mntr_flags_policy))
2330 return -EINVAL;
2331
2332 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2333 if (flags[flag])
2334 *mntrflags |= (1<<flag);
2335
2336 return 0;
2337}
2338
Johannes Berg9bc383d2009-11-19 11:55:19 +01002339static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002340 struct net_device *netdev, u8 use_4addr,
2341 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002342{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002343 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002344 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002345 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002346 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002347 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002348
2349 switch (iftype) {
2350 case NL80211_IFTYPE_AP_VLAN:
2351 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2352 return 0;
2353 break;
2354 case NL80211_IFTYPE_STATION:
2355 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2356 return 0;
2357 break;
2358 default:
2359 break;
2360 }
2361
2362 return -EOPNOTSUPP;
2363}
2364
Johannes Berg55682962007-09-20 13:09:35 -04002365static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2366{
Johannes Berg4c476992010-10-04 21:36:35 +02002367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002368 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002369 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002370 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002371 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002372 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002373 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002374
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002375 memset(&params, 0, sizeof(params));
2376
Johannes Berg04a773a2009-04-19 21:24:32 +02002377 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002378
Johannes Berg723b0382008-09-16 20:22:09 +02002379 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002380 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002381 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002382 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002383 if (ntype > NL80211_IFTYPE_MAX)
2384 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002385 }
2386
Johannes Berg92ffe052008-09-16 20:39:36 +02002387 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002388 struct wireless_dev *wdev = dev->ieee80211_ptr;
2389
Johannes Berg4c476992010-10-04 21:36:35 +02002390 if (ntype != NL80211_IFTYPE_MESH_POINT)
2391 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002392 if (netif_running(dev))
2393 return -EBUSY;
2394
2395 wdev_lock(wdev);
2396 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2397 IEEE80211_MAX_MESH_ID_LEN);
2398 wdev->mesh_id_up_len =
2399 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2400 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2401 wdev->mesh_id_up_len);
2402 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002403 }
2404
Felix Fietkau8b787642009-11-10 18:53:10 +01002405 if (info->attrs[NL80211_ATTR_4ADDR]) {
2406 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2407 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002408 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002409 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002410 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002411 } else {
2412 params.use_4addr = -1;
2413 }
2414
Johannes Berg92ffe052008-09-16 20:39:36 +02002415 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002416 if (ntype != NL80211_IFTYPE_MONITOR)
2417 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002418 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2419 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002420 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002421 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002422
2423 flags = &_flags;
2424 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002425 }
Johannes Berg3b858752009-03-12 09:55:09 +01002426
Luciano Coelho18003292013-08-29 13:26:57 +03002427 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002428 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2429 return -EOPNOTSUPP;
2430
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002431 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002432 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002433 else
2434 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002435
Johannes Berg9bc383d2009-11-19 11:55:19 +01002436 if (!err && params.use_4addr != -1)
2437 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2438
Johannes Berg55682962007-09-20 13:09:35 -04002439 return err;
2440}
2441
2442static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2443{
Johannes Berg4c476992010-10-04 21:36:35 +02002444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002445 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002446 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002447 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002448 int err;
2449 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002450 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002451
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002452 memset(&params, 0, sizeof(params));
2453
Johannes Berg55682962007-09-20 13:09:35 -04002454 if (!info->attrs[NL80211_ATTR_IFNAME])
2455 return -EINVAL;
2456
2457 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2458 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2459 if (type > NL80211_IFTYPE_MAX)
2460 return -EINVAL;
2461 }
2462
Johannes Berg79c97e92009-07-07 03:56:12 +02002463 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002464 !(rdev->wiphy.interface_modes & (1 << type)))
2465 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002466
Arend van Spriel1c18f142013-01-08 10:17:27 +01002467 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2468 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2469 ETH_ALEN);
2470 if (!is_valid_ether_addr(params.macaddr))
2471 return -EADDRNOTAVAIL;
2472 }
2473
Johannes Berg9bc383d2009-11-19 11:55:19 +01002474 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002475 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002476 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002477 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002478 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002479 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002480
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2482 if (!msg)
2483 return -ENOMEM;
2484
Michael Wu66f7ac52008-01-31 19:48:22 +01002485 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2486 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2487 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002488
Luciano Coelho18003292013-08-29 13:26:57 +03002489 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002490 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2491 return -EOPNOTSUPP;
2492
Hila Gonene35e4d22012-06-27 17:19:42 +03002493 wdev = rdev_add_virtual_intf(rdev,
2494 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2495 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002496 if (IS_ERR(wdev)) {
2497 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002498 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002499 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002500
Johannes Berg98104fde2012-06-16 00:19:54 +02002501 switch (type) {
2502 case NL80211_IFTYPE_MESH_POINT:
2503 if (!info->attrs[NL80211_ATTR_MESH_ID])
2504 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002505 wdev_lock(wdev);
2506 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2507 IEEE80211_MAX_MESH_ID_LEN);
2508 wdev->mesh_id_up_len =
2509 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2510 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2511 wdev->mesh_id_up_len);
2512 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002513 break;
2514 case NL80211_IFTYPE_P2P_DEVICE:
2515 /*
2516 * P2P Device doesn't have a netdev, so doesn't go
2517 * through the netdev notifier and must be added here
2518 */
2519 mutex_init(&wdev->mtx);
2520 INIT_LIST_HEAD(&wdev->event_list);
2521 spin_lock_init(&wdev->event_lock);
2522 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2523 spin_lock_init(&wdev->mgmt_registrations_lock);
2524
Johannes Berg98104fde2012-06-16 00:19:54 +02002525 wdev->identifier = ++rdev->wdev_id;
2526 list_add_rcu(&wdev->list, &rdev->wdev_list);
2527 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002528 break;
2529 default:
2530 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002531 }
2532
Eric W. Biederman15e47302012-09-07 20:12:54 +00002533 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002534 rdev, wdev) < 0) {
2535 nlmsg_free(msg);
2536 return -ENOBUFS;
2537 }
2538
2539 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002540}
2541
2542static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2543{
Johannes Berg4c476992010-10-04 21:36:35 +02002544 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002545 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002546
Johannes Berg4c476992010-10-04 21:36:35 +02002547 if (!rdev->ops->del_virtual_intf)
2548 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002549
Johannes Berg84efbb82012-06-16 00:00:26 +02002550 /*
2551 * If we remove a wireless device without a netdev then clear
2552 * user_ptr[1] so that nl80211_post_doit won't dereference it
2553 * to check if it needs to do dev_put(). Otherwise it crashes
2554 * since the wdev has been freed, unlike with a netdev where
2555 * we need the dev_put() for the netdev to really be freed.
2556 */
2557 if (!wdev->netdev)
2558 info->user_ptr[1] = NULL;
2559
Hila Gonene35e4d22012-06-27 17:19:42 +03002560 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002561}
2562
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002563static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2564{
2565 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2566 struct net_device *dev = info->user_ptr[1];
2567 u16 noack_map;
2568
2569 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2570 return -EINVAL;
2571
2572 if (!rdev->ops->set_noack_map)
2573 return -EOPNOTSUPP;
2574
2575 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2576
Hila Gonene35e4d22012-06-27 17:19:42 +03002577 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002578}
2579
Johannes Berg41ade002007-12-19 02:03:29 +01002580struct get_key_cookie {
2581 struct sk_buff *msg;
2582 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002583 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002584};
2585
2586static void get_key_callback(void *c, struct key_params *params)
2587{
Johannes Bergb9454e82009-07-08 13:29:08 +02002588 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002589 struct get_key_cookie *cookie = c;
2590
David S. Miller9360ffd2012-03-29 04:41:26 -04002591 if ((params->key &&
2592 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2593 params->key_len, params->key)) ||
2594 (params->seq &&
2595 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2596 params->seq_len, params->seq)) ||
2597 (params->cipher &&
2598 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2599 params->cipher)))
2600 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002601
Johannes Bergb9454e82009-07-08 13:29:08 +02002602 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2603 if (!key)
2604 goto nla_put_failure;
2605
David S. Miller9360ffd2012-03-29 04:41:26 -04002606 if ((params->key &&
2607 nla_put(cookie->msg, NL80211_KEY_DATA,
2608 params->key_len, params->key)) ||
2609 (params->seq &&
2610 nla_put(cookie->msg, NL80211_KEY_SEQ,
2611 params->seq_len, params->seq)) ||
2612 (params->cipher &&
2613 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2614 params->cipher)))
2615 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002616
David S. Miller9360ffd2012-03-29 04:41:26 -04002617 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2618 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002619
2620 nla_nest_end(cookie->msg, key);
2621
Johannes Berg41ade002007-12-19 02:03:29 +01002622 return;
2623 nla_put_failure:
2624 cookie->error = 1;
2625}
2626
2627static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2628{
Johannes Berg4c476992010-10-04 21:36:35 +02002629 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002630 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002631 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002632 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002633 const u8 *mac_addr = NULL;
2634 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002635 struct get_key_cookie cookie = {
2636 .error = 0,
2637 };
2638 void *hdr;
2639 struct sk_buff *msg;
2640
2641 if (info->attrs[NL80211_ATTR_KEY_IDX])
2642 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2643
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002644 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002645 return -EINVAL;
2646
2647 if (info->attrs[NL80211_ATTR_MAC])
2648 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2649
Johannes Berge31b8212010-10-05 19:39:30 +02002650 pairwise = !!mac_addr;
2651 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2652 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2653 if (kt >= NUM_NL80211_KEYTYPES)
2654 return -EINVAL;
2655 if (kt != NL80211_KEYTYPE_GROUP &&
2656 kt != NL80211_KEYTYPE_PAIRWISE)
2657 return -EINVAL;
2658 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2659 }
2660
Johannes Berg4c476992010-10-04 21:36:35 +02002661 if (!rdev->ops->get_key)
2662 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002663
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002665 if (!msg)
2666 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002667
Eric W. Biederman15e47302012-09-07 20:12:54 +00002668 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002669 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002670 if (!hdr)
2671 return -ENOBUFS;
Johannes Berg41ade002007-12-19 02:03:29 +01002672
2673 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002674 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002675
David S. Miller9360ffd2012-03-29 04:41:26 -04002676 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2677 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2678 goto nla_put_failure;
2679 if (mac_addr &&
2680 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2681 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002682
Johannes Berge31b8212010-10-05 19:39:30 +02002683 if (pairwise && mac_addr &&
2684 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2685 return -ENOENT;
2686
Hila Gonene35e4d22012-06-27 17:19:42 +03002687 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2688 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002689
2690 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002691 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002692
2693 if (cookie.error)
2694 goto nla_put_failure;
2695
2696 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002697 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002698
2699 nla_put_failure:
2700 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002701 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002702 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002703 return err;
2704}
2705
2706static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2707{
Johannes Berg4c476992010-10-04 21:36:35 +02002708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002709 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002710 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002711 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002712
Johannes Bergb9454e82009-07-08 13:29:08 +02002713 err = nl80211_parse_key(info, &key);
2714 if (err)
2715 return err;
2716
2717 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002718 return -EINVAL;
2719
Johannes Bergb9454e82009-07-08 13:29:08 +02002720 /* only support setting default key */
2721 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002722 return -EINVAL;
2723
Johannes Bergfffd0932009-07-08 14:22:54 +02002724 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002725
2726 if (key.def) {
2727 if (!rdev->ops->set_default_key) {
2728 err = -EOPNOTSUPP;
2729 goto out;
2730 }
2731
2732 err = nl80211_key_allowed(dev->ieee80211_ptr);
2733 if (err)
2734 goto out;
2735
Hila Gonene35e4d22012-06-27 17:19:42 +03002736 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002737 key.def_uni, key.def_multi);
2738
2739 if (err)
2740 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002741
Johannes Berg3d23e342009-09-29 23:27:28 +02002742#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002743 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002744#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002745 } else {
2746 if (key.def_uni || !key.def_multi) {
2747 err = -EINVAL;
2748 goto out;
2749 }
2750
2751 if (!rdev->ops->set_default_mgmt_key) {
2752 err = -EOPNOTSUPP;
2753 goto out;
2754 }
2755
2756 err = nl80211_key_allowed(dev->ieee80211_ptr);
2757 if (err)
2758 goto out;
2759
Hila Gonene35e4d22012-06-27 17:19:42 +03002760 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002761 if (err)
2762 goto out;
2763
2764#ifdef CONFIG_CFG80211_WEXT
2765 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2766#endif
2767 }
2768
2769 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002770 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002771
Johannes Berg41ade002007-12-19 02:03:29 +01002772 return err;
2773}
2774
2775static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2776{
Johannes Berg4c476992010-10-04 21:36:35 +02002777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002778 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002779 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002781 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002782
Johannes Bergb9454e82009-07-08 13:29:08 +02002783 err = nl80211_parse_key(info, &key);
2784 if (err)
2785 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002786
Johannes Bergb9454e82009-07-08 13:29:08 +02002787 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002788 return -EINVAL;
2789
Johannes Berg41ade002007-12-19 02:03:29 +01002790 if (info->attrs[NL80211_ATTR_MAC])
2791 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2792
Johannes Berge31b8212010-10-05 19:39:30 +02002793 if (key.type == -1) {
2794 if (mac_addr)
2795 key.type = NL80211_KEYTYPE_PAIRWISE;
2796 else
2797 key.type = NL80211_KEYTYPE_GROUP;
2798 }
2799
2800 /* for now */
2801 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2802 key.type != NL80211_KEYTYPE_GROUP)
2803 return -EINVAL;
2804
Johannes Berg4c476992010-10-04 21:36:35 +02002805 if (!rdev->ops->add_key)
2806 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002807
Johannes Berge31b8212010-10-05 19:39:30 +02002808 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2809 key.type == NL80211_KEYTYPE_PAIRWISE,
2810 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002811 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002812
2813 wdev_lock(dev->ieee80211_ptr);
2814 err = nl80211_key_allowed(dev->ieee80211_ptr);
2815 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002816 err = rdev_add_key(rdev, dev, key.idx,
2817 key.type == NL80211_KEYTYPE_PAIRWISE,
2818 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002819 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002820
Johannes Berg41ade002007-12-19 02:03:29 +01002821 return err;
2822}
2823
2824static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2825{
Johannes Berg4c476992010-10-04 21:36:35 +02002826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002827 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002828 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002829 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002830 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002831
Johannes Bergb9454e82009-07-08 13:29:08 +02002832 err = nl80211_parse_key(info, &key);
2833 if (err)
2834 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002835
2836 if (info->attrs[NL80211_ATTR_MAC])
2837 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2838
Johannes Berge31b8212010-10-05 19:39:30 +02002839 if (key.type == -1) {
2840 if (mac_addr)
2841 key.type = NL80211_KEYTYPE_PAIRWISE;
2842 else
2843 key.type = NL80211_KEYTYPE_GROUP;
2844 }
2845
2846 /* for now */
2847 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2848 key.type != NL80211_KEYTYPE_GROUP)
2849 return -EINVAL;
2850
Johannes Berg4c476992010-10-04 21:36:35 +02002851 if (!rdev->ops->del_key)
2852 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002853
Johannes Bergfffd0932009-07-08 14:22:54 +02002854 wdev_lock(dev->ieee80211_ptr);
2855 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002856
2857 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2858 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2859 err = -ENOENT;
2860
Johannes Bergfffd0932009-07-08 14:22:54 +02002861 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002862 err = rdev_del_key(rdev, dev, key.idx,
2863 key.type == NL80211_KEYTYPE_PAIRWISE,
2864 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002865
Johannes Berg3d23e342009-09-29 23:27:28 +02002866#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002867 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002868 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002869 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002870 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002871 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2872 }
2873#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002874 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002875
Johannes Berg41ade002007-12-19 02:03:29 +01002876 return err;
2877}
2878
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302879/* This function returns an error or the number of nested attributes */
2880static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2881{
2882 struct nlattr *attr;
2883 int n_entries = 0, tmp;
2884
2885 nla_for_each_nested(attr, nl_attr, tmp) {
2886 if (nla_len(attr) != ETH_ALEN)
2887 return -EINVAL;
2888
2889 n_entries++;
2890 }
2891
2892 return n_entries;
2893}
2894
2895/*
2896 * This function parses ACL information and allocates memory for ACL data.
2897 * On successful return, the calling function is responsible to free the
2898 * ACL buffer returned by this function.
2899 */
2900static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2901 struct genl_info *info)
2902{
2903 enum nl80211_acl_policy acl_policy;
2904 struct nlattr *attr;
2905 struct cfg80211_acl_data *acl;
2906 int i = 0, n_entries, tmp;
2907
2908 if (!wiphy->max_acl_mac_addrs)
2909 return ERR_PTR(-EOPNOTSUPP);
2910
2911 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2912 return ERR_PTR(-EINVAL);
2913
2914 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2915 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2916 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2917 return ERR_PTR(-EINVAL);
2918
2919 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2920 return ERR_PTR(-EINVAL);
2921
2922 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2923 if (n_entries < 0)
2924 return ERR_PTR(n_entries);
2925
2926 if (n_entries > wiphy->max_acl_mac_addrs)
2927 return ERR_PTR(-ENOTSUPP);
2928
2929 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2930 GFP_KERNEL);
2931 if (!acl)
2932 return ERR_PTR(-ENOMEM);
2933
2934 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2935 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2936 i++;
2937 }
2938
2939 acl->n_acl_entries = n_entries;
2940 acl->acl_policy = acl_policy;
2941
2942 return acl;
2943}
2944
2945static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2946{
2947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2948 struct net_device *dev = info->user_ptr[1];
2949 struct cfg80211_acl_data *acl;
2950 int err;
2951
2952 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2953 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2954 return -EOPNOTSUPP;
2955
2956 if (!dev->ieee80211_ptr->beacon_interval)
2957 return -EINVAL;
2958
2959 acl = parse_acl_data(&rdev->wiphy, info);
2960 if (IS_ERR(acl))
2961 return PTR_ERR(acl);
2962
2963 err = rdev_set_mac_acl(rdev, dev, acl);
2964
2965 kfree(acl);
2966
2967 return err;
2968}
2969
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002970static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002971 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002972{
Johannes Berg88600202012-02-13 15:17:18 +01002973 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002974
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002975 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2976 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2977 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2978 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002979 return -EINVAL;
2980
Johannes Berg88600202012-02-13 15:17:18 +01002981 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002982
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002983 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2984 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2985 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002986 if (!bcn->head_len)
2987 return -EINVAL;
2988 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002989 }
2990
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002991 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2992 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2993 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002994 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002995 }
2996
Johannes Berg4c476992010-10-04 21:36:35 +02002997 if (!haveinfo)
2998 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002999
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003000 if (attrs[NL80211_ATTR_IE]) {
3001 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3002 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003003 }
3004
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003005 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003006 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003007 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003008 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003009 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003010 }
3011
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003012 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003013 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003014 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003015 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003016 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003017 }
3018
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003019 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3020 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3021 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003022 }
3023
Johannes Berg88600202012-02-13 15:17:18 +01003024 return 0;
3025}
3026
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003027static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3028 struct cfg80211_ap_settings *params)
3029{
3030 struct wireless_dev *wdev;
3031 bool ret = false;
3032
Johannes Berg89a54e42012-06-15 14:33:17 +02003033 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003034 if (wdev->iftype != NL80211_IFTYPE_AP &&
3035 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3036 continue;
3037
Johannes Berg683b6d32012-11-08 21:25:48 +01003038 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003039 continue;
3040
Johannes Berg683b6d32012-11-08 21:25:48 +01003041 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003042 ret = true;
3043 break;
3044 }
3045
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003046 return ret;
3047}
3048
Jouni Malinene39e5b52012-09-30 19:29:39 +03003049static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3050 enum nl80211_auth_type auth_type,
3051 enum nl80211_commands cmd)
3052{
3053 if (auth_type > NL80211_AUTHTYPE_MAX)
3054 return false;
3055
3056 switch (cmd) {
3057 case NL80211_CMD_AUTHENTICATE:
3058 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3059 auth_type == NL80211_AUTHTYPE_SAE)
3060 return false;
3061 return true;
3062 case NL80211_CMD_CONNECT:
3063 case NL80211_CMD_START_AP:
3064 /* SAE not supported yet */
3065 if (auth_type == NL80211_AUTHTYPE_SAE)
3066 return false;
3067 return true;
3068 default:
3069 return false;
3070 }
3071}
3072
Johannes Berg88600202012-02-13 15:17:18 +01003073static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3074{
3075 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3076 struct net_device *dev = info->user_ptr[1];
3077 struct wireless_dev *wdev = dev->ieee80211_ptr;
3078 struct cfg80211_ap_settings params;
3079 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003080 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003081
3082 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3083 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3084 return -EOPNOTSUPP;
3085
3086 if (!rdev->ops->start_ap)
3087 return -EOPNOTSUPP;
3088
3089 if (wdev->beacon_interval)
3090 return -EALREADY;
3091
3092 memset(&params, 0, sizeof(params));
3093
3094 /* these are required for START_AP */
3095 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3096 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3097 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3098 return -EINVAL;
3099
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003100 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003101 if (err)
3102 return err;
3103
3104 params.beacon_interval =
3105 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3106 params.dtim_period =
3107 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3108
3109 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3110 if (err)
3111 return err;
3112
3113 /*
3114 * In theory, some of these attributes should be required here
3115 * but since they were not used when the command was originally
3116 * added, keep them optional for old user space programs to let
3117 * them continue to work with drivers that do not need the
3118 * additional information -- drivers must check!
3119 */
3120 if (info->attrs[NL80211_ATTR_SSID]) {
3121 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3122 params.ssid_len =
3123 nla_len(info->attrs[NL80211_ATTR_SSID]);
3124 if (params.ssid_len == 0 ||
3125 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3126 return -EINVAL;
3127 }
3128
3129 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3130 params.hidden_ssid = nla_get_u32(
3131 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3132 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3133 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3134 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3135 return -EINVAL;
3136 }
3137
3138 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3139
3140 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3141 params.auth_type = nla_get_u32(
3142 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003143 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3144 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003145 return -EINVAL;
3146 } else
3147 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3148
3149 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3150 NL80211_MAX_NR_CIPHER_SUITES);
3151 if (err)
3152 return err;
3153
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303154 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3155 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3156 return -EOPNOTSUPP;
3157 params.inactivity_timeout = nla_get_u16(
3158 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3159 }
3160
Johannes Berg53cabad2012-11-14 15:17:28 +01003161 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3162 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3163 return -EINVAL;
3164 params.p2p_ctwindow =
3165 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3166 if (params.p2p_ctwindow > 127)
3167 return -EINVAL;
3168 if (params.p2p_ctwindow != 0 &&
3169 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3170 return -EINVAL;
3171 }
3172
3173 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3174 u8 tmp;
3175
3176 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3177 return -EINVAL;
3178 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3179 if (tmp > 1)
3180 return -EINVAL;
3181 params.p2p_opp_ps = tmp;
3182 if (params.p2p_opp_ps != 0 &&
3183 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3184 return -EINVAL;
3185 }
3186
Johannes Bergaa430da2012-05-16 23:50:18 +02003187 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003188 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3189 if (err)
3190 return err;
3191 } else if (wdev->preset_chandef.chan) {
3192 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003193 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003194 return -EINVAL;
3195
Johannes Berg683b6d32012-11-08 21:25:48 +01003196 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003197 return -EINVAL;
3198
Simon Wunderlich04f39042013-02-08 18:16:19 +01003199 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3200 if (err < 0)
3201 return err;
3202 if (err) {
3203 radar_detect_width = BIT(params.chandef.width);
3204 params.radar_required = true;
3205 }
3206
Simon Wunderlich04f39042013-02-08 18:16:19 +01003207 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3208 params.chandef.chan,
3209 CHAN_MODE_SHARED,
3210 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003211 if (err)
3212 return err;
3213
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303214 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3215 params.acl = parse_acl_data(&rdev->wiphy, info);
3216 if (IS_ERR(params.acl))
3217 return PTR_ERR(params.acl);
3218 }
3219
Hila Gonene35e4d22012-06-27 17:19:42 +03003220 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003221 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003222 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003223 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003224 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003225 wdev->ssid_len = params.ssid_len;
3226 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003227 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303228
3229 kfree(params.acl);
3230
Johannes Berg56d18932011-05-09 18:41:15 +02003231 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003232}
3233
Johannes Berg88600202012-02-13 15:17:18 +01003234static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3235{
3236 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3237 struct net_device *dev = info->user_ptr[1];
3238 struct wireless_dev *wdev = dev->ieee80211_ptr;
3239 struct cfg80211_beacon_data params;
3240 int err;
3241
3242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3243 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3244 return -EOPNOTSUPP;
3245
3246 if (!rdev->ops->change_beacon)
3247 return -EOPNOTSUPP;
3248
3249 if (!wdev->beacon_interval)
3250 return -EINVAL;
3251
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003252 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003253 if (err)
3254 return err;
3255
Hila Gonene35e4d22012-06-27 17:19:42 +03003256 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003257}
3258
3259static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003260{
Johannes Berg4c476992010-10-04 21:36:35 +02003261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3262 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003263
Michal Kazior60771782012-06-29 12:46:56 +02003264 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003265}
3266
Johannes Berg5727ef12007-12-19 02:03:34 +01003267static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3268 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3269 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3270 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003271 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003272 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003273 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003274};
3275
Johannes Bergeccb8e82009-05-11 21:57:56 +03003276static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003277 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003278 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003279{
3280 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003281 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003282 int flag;
3283
Johannes Bergeccb8e82009-05-11 21:57:56 +03003284 /*
3285 * Try parsing the new attribute first so userspace
3286 * can specify both for older kernels.
3287 */
3288 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3289 if (nla) {
3290 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003291
Johannes Bergeccb8e82009-05-11 21:57:56 +03003292 sta_flags = nla_data(nla);
3293 params->sta_flags_mask = sta_flags->mask;
3294 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003295 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003296 if ((params->sta_flags_mask |
3297 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3298 return -EINVAL;
3299 return 0;
3300 }
3301
3302 /* if present, parse the old attribute */
3303
3304 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003305 if (!nla)
3306 return 0;
3307
3308 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3309 nla, sta_flags_policy))
3310 return -EINVAL;
3311
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003312 /*
3313 * Only allow certain flags for interface types so that
3314 * other attributes are silently ignored. Remember that
3315 * this is backward compatibility code with old userspace
3316 * and shouldn't be hit in other cases anyway.
3317 */
3318 switch (iftype) {
3319 case NL80211_IFTYPE_AP:
3320 case NL80211_IFTYPE_AP_VLAN:
3321 case NL80211_IFTYPE_P2P_GO:
3322 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3323 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3324 BIT(NL80211_STA_FLAG_WME) |
3325 BIT(NL80211_STA_FLAG_MFP);
3326 break;
3327 case NL80211_IFTYPE_P2P_CLIENT:
3328 case NL80211_IFTYPE_STATION:
3329 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3330 BIT(NL80211_STA_FLAG_TDLS_PEER);
3331 break;
3332 case NL80211_IFTYPE_MESH_POINT:
3333 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3334 BIT(NL80211_STA_FLAG_MFP) |
3335 BIT(NL80211_STA_FLAG_AUTHORIZED);
3336 default:
3337 return -EINVAL;
3338 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003339
Johannes Berg3383b5a2012-05-10 20:14:43 +02003340 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3341 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003342 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003343
Johannes Berg3383b5a2012-05-10 20:14:43 +02003344 /* no longer support new API additions in old API */
3345 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3346 return -EINVAL;
3347 }
3348 }
3349
Johannes Berg5727ef12007-12-19 02:03:34 +01003350 return 0;
3351}
3352
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003353static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3354 int attr)
3355{
3356 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003357 u32 bitrate;
3358 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003359
3360 rate = nla_nest_start(msg, attr);
3361 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003362 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003363
3364 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3365 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003366 /* report 16-bit bitrate only if we can */
3367 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003368 if (bitrate > 0 &&
3369 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3370 return false;
3371 if (bitrate_compat > 0 &&
3372 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3373 return false;
3374
3375 if (info->flags & RATE_INFO_FLAGS_MCS) {
3376 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3377 return false;
3378 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3379 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3380 return false;
3381 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3382 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3383 return false;
3384 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3385 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3386 return false;
3387 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3388 return false;
3389 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3390 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3391 return false;
3392 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3393 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3394 return false;
3395 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3396 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3397 return false;
3398 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3399 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3400 return false;
3401 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3402 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3403 return false;
3404 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003405
3406 nla_nest_end(msg, rate);
3407 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003408}
3409
Felix Fietkau119363c2013-04-22 16:29:30 +02003410static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3411 int id)
3412{
3413 void *attr;
3414 int i = 0;
3415
3416 if (!mask)
3417 return true;
3418
3419 attr = nla_nest_start(msg, id);
3420 if (!attr)
3421 return false;
3422
3423 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3424 if (!(mask & BIT(i)))
3425 continue;
3426
3427 if (nla_put_u8(msg, i, signal[i]))
3428 return false;
3429 }
3430
3431 nla_nest_end(msg, attr);
3432
3433 return true;
3434}
3435
Eric W. Biederman15e47302012-09-07 20:12:54 +00003436static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003437 int flags,
3438 struct cfg80211_registered_device *rdev,
3439 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003440 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003441{
3442 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003443 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003444
Eric W. Biederman15e47302012-09-07 20:12:54 +00003445 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003446 if (!hdr)
3447 return -1;
3448
David S. Miller9360ffd2012-03-29 04:41:26 -04003449 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3450 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3451 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3452 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003453
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003454 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3455 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003456 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003457 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3458 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3459 sinfo->connected_time))
3460 goto nla_put_failure;
3461 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3462 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3463 sinfo->inactive_time))
3464 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003465 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3466 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003467 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003468 (u32)sinfo->rx_bytes))
3469 goto nla_put_failure;
3470 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003471 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003472 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3473 (u32)sinfo->tx_bytes))
3474 goto nla_put_failure;
3475 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3476 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003477 sinfo->rx_bytes))
3478 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003479 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3480 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003481 sinfo->tx_bytes))
3482 goto nla_put_failure;
3483 if ((sinfo->filled & STATION_INFO_LLID) &&
3484 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3485 goto nla_put_failure;
3486 if ((sinfo->filled & STATION_INFO_PLID) &&
3487 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3488 goto nla_put_failure;
3489 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3490 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3491 sinfo->plink_state))
3492 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003493 switch (rdev->wiphy.signal_type) {
3494 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003495 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3496 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3497 sinfo->signal))
3498 goto nla_put_failure;
3499 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3500 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3501 sinfo->signal_avg))
3502 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003503 break;
3504 default:
3505 break;
3506 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003507 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3508 if (!nl80211_put_signal(msg, sinfo->chains,
3509 sinfo->chain_signal,
3510 NL80211_STA_INFO_CHAIN_SIGNAL))
3511 goto nla_put_failure;
3512 }
3513 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3514 if (!nl80211_put_signal(msg, sinfo->chains,
3515 sinfo->chain_signal_avg,
3516 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3517 goto nla_put_failure;
3518 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003519 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003520 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3521 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003522 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003523 }
3524 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3525 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3526 NL80211_STA_INFO_RX_BITRATE))
3527 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003528 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003529 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3530 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3531 sinfo->rx_packets))
3532 goto nla_put_failure;
3533 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3534 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3535 sinfo->tx_packets))
3536 goto nla_put_failure;
3537 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3538 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3539 sinfo->tx_retries))
3540 goto nla_put_failure;
3541 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3542 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3543 sinfo->tx_failed))
3544 goto nla_put_failure;
3545 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3546 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3547 sinfo->beacon_loss_count))
3548 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003549 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3550 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3551 sinfo->local_pm))
3552 goto nla_put_failure;
3553 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3554 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3555 sinfo->peer_pm))
3556 goto nla_put_failure;
3557 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3558 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3559 sinfo->nonpeer_pm))
3560 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003561 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3562 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3563 if (!bss_param)
3564 goto nla_put_failure;
3565
David S. Miller9360ffd2012-03-29 04:41:26 -04003566 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3567 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3568 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3569 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3570 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3571 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3572 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3573 sinfo->bss_param.dtim_period) ||
3574 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3575 sinfo->bss_param.beacon_interval))
3576 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003577
3578 nla_nest_end(msg, bss_param);
3579 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003580 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3581 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3582 sizeof(struct nl80211_sta_flag_update),
3583 &sinfo->sta_flags))
3584 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003585 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3586 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3587 sinfo->t_offset))
3588 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003589 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003590
David S. Miller9360ffd2012-03-29 04:41:26 -04003591 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3592 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3593 sinfo->assoc_req_ies))
3594 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003595
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003596 return genlmsg_end(msg, hdr);
3597
3598 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003599 genlmsg_cancel(msg, hdr);
3600 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003601}
3602
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003603static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003604 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003605{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003606 struct station_info sinfo;
3607 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003608 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003609 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003610 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003611 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003612
Johannes Berg97990a02013-04-19 01:02:55 +02003613 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003614 if (err)
3615 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003616
Johannes Berg97990a02013-04-19 01:02:55 +02003617 if (!wdev->netdev) {
3618 err = -EINVAL;
3619 goto out_err;
3620 }
3621
Johannes Bergbba95fe2008-07-29 13:22:51 +02003622 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003623 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003624 goto out_err;
3625 }
3626
Johannes Bergbba95fe2008-07-29 13:22:51 +02003627 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003628 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003629 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003630 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003631 if (err == -ENOENT)
3632 break;
3633 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003634 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003635
3636 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003637 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003638 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003639 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003640 &sinfo) < 0)
3641 goto out;
3642
3643 sta_idx++;
3644 }
3645
3646
3647 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003648 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003649 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003650 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003651 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003652
3653 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003654}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003655
Johannes Berg5727ef12007-12-19 02:03:34 +01003656static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3657{
Johannes Berg4c476992010-10-04 21:36:35 +02003658 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3659 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003660 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003661 struct sk_buff *msg;
3662 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003663 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003664
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003665 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003666
3667 if (!info->attrs[NL80211_ATTR_MAC])
3668 return -EINVAL;
3669
3670 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3671
Johannes Berg4c476992010-10-04 21:36:35 +02003672 if (!rdev->ops->get_station)
3673 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003674
Hila Gonene35e4d22012-06-27 17:19:42 +03003675 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003676 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003677 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003678
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003680 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003681 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003682
Eric W. Biederman15e47302012-09-07 20:12:54 +00003683 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003684 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003685 nlmsg_free(msg);
3686 return -ENOBUFS;
3687 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003688
Johannes Berg4c476992010-10-04 21:36:35 +02003689 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003690}
3691
Johannes Berg77ee7c82013-02-15 00:48:33 +01003692int cfg80211_check_station_change(struct wiphy *wiphy,
3693 struct station_parameters *params,
3694 enum cfg80211_station_type statype)
3695{
3696 if (params->listen_interval != -1)
3697 return -EINVAL;
3698 if (params->aid)
3699 return -EINVAL;
3700
3701 /* When you run into this, adjust the code below for the new flag */
3702 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3703
3704 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003705 case CFG80211_STA_MESH_PEER_KERNEL:
3706 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003707 /*
3708 * No ignoring the TDLS flag here -- the userspace mesh
3709 * code doesn't have the bug of including TDLS in the
3710 * mask everywhere.
3711 */
3712 if (params->sta_flags_mask &
3713 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3714 BIT(NL80211_STA_FLAG_MFP) |
3715 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3716 return -EINVAL;
3717 break;
3718 case CFG80211_STA_TDLS_PEER_SETUP:
3719 case CFG80211_STA_TDLS_PEER_ACTIVE:
3720 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3721 return -EINVAL;
3722 /* ignore since it can't change */
3723 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3724 break;
3725 default:
3726 /* disallow mesh-specific things */
3727 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3728 return -EINVAL;
3729 if (params->local_pm)
3730 return -EINVAL;
3731 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3732 return -EINVAL;
3733 }
3734
3735 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3736 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3737 /* TDLS can't be set, ... */
3738 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3739 return -EINVAL;
3740 /*
3741 * ... but don't bother the driver with it. This works around
3742 * a hostapd/wpa_supplicant issue -- it always includes the
3743 * TLDS_PEER flag in the mask even for AP mode.
3744 */
3745 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3746 }
3747
3748 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3749 /* reject other things that can't change */
3750 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3751 return -EINVAL;
3752 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3753 return -EINVAL;
3754 if (params->supported_rates)
3755 return -EINVAL;
3756 if (params->ext_capab || params->ht_capa || params->vht_capa)
3757 return -EINVAL;
3758 }
3759
3760 if (statype != CFG80211_STA_AP_CLIENT) {
3761 if (params->vlan)
3762 return -EINVAL;
3763 }
3764
3765 switch (statype) {
3766 case CFG80211_STA_AP_MLME_CLIENT:
3767 /* Use this only for authorizing/unauthorizing a station */
3768 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3769 return -EOPNOTSUPP;
3770 break;
3771 case CFG80211_STA_AP_CLIENT:
3772 /* accept only the listed bits */
3773 if (params->sta_flags_mask &
3774 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3775 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3776 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3777 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3778 BIT(NL80211_STA_FLAG_WME) |
3779 BIT(NL80211_STA_FLAG_MFP)))
3780 return -EINVAL;
3781
3782 /* but authenticated/associated only if driver handles it */
3783 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3784 params->sta_flags_mask &
3785 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3786 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3787 return -EINVAL;
3788 break;
3789 case CFG80211_STA_IBSS:
3790 case CFG80211_STA_AP_STA:
3791 /* reject any changes other than AUTHORIZED */
3792 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3793 return -EINVAL;
3794 break;
3795 case CFG80211_STA_TDLS_PEER_SETUP:
3796 /* reject any changes other than AUTHORIZED or WME */
3797 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3798 BIT(NL80211_STA_FLAG_WME)))
3799 return -EINVAL;
3800 /* force (at least) rates when authorizing */
3801 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3802 !params->supported_rates)
3803 return -EINVAL;
3804 break;
3805 case CFG80211_STA_TDLS_PEER_ACTIVE:
3806 /* reject any changes */
3807 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003808 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003809 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3810 return -EINVAL;
3811 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003812 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003813 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3814 return -EINVAL;
3815 break;
3816 }
3817
3818 return 0;
3819}
3820EXPORT_SYMBOL(cfg80211_check_station_change);
3821
Johannes Berg5727ef12007-12-19 02:03:34 +01003822/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003823 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003824 */
Johannes Berg80b99892011-11-18 16:23:01 +01003825static struct net_device *get_vlan(struct genl_info *info,
3826 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003827{
Johannes Berg463d0182009-07-14 00:33:35 +02003828 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003829 struct net_device *v;
3830 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003831
Johannes Berg80b99892011-11-18 16:23:01 +01003832 if (!vlanattr)
3833 return NULL;
3834
3835 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3836 if (!v)
3837 return ERR_PTR(-ENODEV);
3838
3839 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3840 ret = -EINVAL;
3841 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003842 }
Johannes Berg80b99892011-11-18 16:23:01 +01003843
Johannes Berg77ee7c82013-02-15 00:48:33 +01003844 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3845 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3846 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3847 ret = -EINVAL;
3848 goto error;
3849 }
3850
Johannes Berg80b99892011-11-18 16:23:01 +01003851 if (!netif_running(v)) {
3852 ret = -ENETDOWN;
3853 goto error;
3854 }
3855
3856 return v;
3857 error:
3858 dev_put(v);
3859 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003860}
3861
Jouni Malinendf881292013-02-14 21:10:54 +02003862static struct nla_policy
3863nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3864 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3865 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3866};
3867
Johannes Bergff276692013-02-15 00:09:01 +01003868static int nl80211_parse_sta_wme(struct genl_info *info,
3869 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003870{
Jouni Malinendf881292013-02-14 21:10:54 +02003871 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3872 struct nlattr *nla;
3873 int err;
3874
Jouni Malinendf881292013-02-14 21:10:54 +02003875 /* parse WME attributes if present */
3876 if (!info->attrs[NL80211_ATTR_STA_WME])
3877 return 0;
3878
3879 nla = info->attrs[NL80211_ATTR_STA_WME];
3880 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3881 nl80211_sta_wme_policy);
3882 if (err)
3883 return err;
3884
3885 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3886 params->uapsd_queues = nla_get_u8(
3887 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3888 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3889 return -EINVAL;
3890
3891 if (tb[NL80211_STA_WME_MAX_SP])
3892 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3893
3894 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3895 return -EINVAL;
3896
3897 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3898
3899 return 0;
3900}
3901
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303902static int nl80211_parse_sta_channel_info(struct genl_info *info,
3903 struct station_parameters *params)
3904{
3905 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3906 params->supported_channels =
3907 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3908 params->supported_channels_len =
3909 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3910 /*
3911 * Need to include at least one (first channel, number of
3912 * channels) tuple for each subband, and must have proper
3913 * tuples for the rest of the data as well.
3914 */
3915 if (params->supported_channels_len < 2)
3916 return -EINVAL;
3917 if (params->supported_channels_len % 2)
3918 return -EINVAL;
3919 }
3920
3921 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3922 params->supported_oper_classes =
3923 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3924 params->supported_oper_classes_len =
3925 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3926 /*
3927 * The value of the Length field of the Supported Operating
3928 * Classes element is between 2 and 253.
3929 */
3930 if (params->supported_oper_classes_len < 2 ||
3931 params->supported_oper_classes_len > 253)
3932 return -EINVAL;
3933 }
3934 return 0;
3935}
3936
Johannes Bergff276692013-02-15 00:09:01 +01003937static int nl80211_set_station_tdls(struct genl_info *info,
3938 struct station_parameters *params)
3939{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303940 int err;
Johannes Bergff276692013-02-15 00:09:01 +01003941 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003942 if (info->attrs[NL80211_ATTR_PEER_AID])
3943 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003944 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3945 params->ht_capa =
3946 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3947 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3948 params->vht_capa =
3949 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3950
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303951 err = nl80211_parse_sta_channel_info(info, params);
3952 if (err)
3953 return err;
3954
Johannes Bergff276692013-02-15 00:09:01 +01003955 return nl80211_parse_sta_wme(info, params);
3956}
3957
Johannes Berg5727ef12007-12-19 02:03:34 +01003958static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3959{
Johannes Berg4c476992010-10-04 21:36:35 +02003960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003961 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003962 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003963 u8 *mac_addr;
3964 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003965
3966 memset(&params, 0, sizeof(params));
3967
3968 params.listen_interval = -1;
3969
Johannes Berg77ee7c82013-02-15 00:48:33 +01003970 if (!rdev->ops->change_station)
3971 return -EOPNOTSUPP;
3972
Johannes Berg5727ef12007-12-19 02:03:34 +01003973 if (info->attrs[NL80211_ATTR_STA_AID])
3974 return -EINVAL;
3975
3976 if (!info->attrs[NL80211_ATTR_MAC])
3977 return -EINVAL;
3978
3979 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3980
3981 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3982 params.supported_rates =
3983 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3984 params.supported_rates_len =
3985 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3986 }
3987
Jouni Malinen9d62a982013-02-14 21:10:13 +02003988 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3989 params.capability =
3990 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3991 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3992 }
3993
3994 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3995 params.ext_capab =
3996 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3997 params.ext_capab_len =
3998 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3999 }
4000
Jouni Malinendf881292013-02-14 21:10:54 +02004001 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004002 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004003
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004004 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004005 return -EINVAL;
4006
Johannes Bergf8bacc22013-02-14 23:27:01 +01004007 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004008 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004009 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4010 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4011 return -EINVAL;
4012 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004013
Johannes Bergf8bacc22013-02-14 23:27:01 +01004014 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004015 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004016 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4017 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4018 return -EINVAL;
4019 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4020 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004021
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004022 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4023 enum nl80211_mesh_power_mode pm = nla_get_u32(
4024 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4025
4026 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4027 pm > NL80211_MESH_POWER_MAX)
4028 return -EINVAL;
4029
4030 params.local_pm = pm;
4031 }
4032
Johannes Berg77ee7c82013-02-15 00:48:33 +01004033 /* Include parameters for TDLS peer (will check later) */
4034 err = nl80211_set_station_tdls(info, &params);
4035 if (err)
4036 return err;
4037
4038 params.vlan = get_vlan(info, rdev);
4039 if (IS_ERR(params.vlan))
4040 return PTR_ERR(params.vlan);
4041
Johannes Berga97f4422009-06-18 17:23:43 +02004042 switch (dev->ieee80211_ptr->iftype) {
4043 case NL80211_IFTYPE_AP:
4044 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004045 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004046 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004047 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004048 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004049 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004050 break;
4051 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004052 err = -EOPNOTSUPP;
4053 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004054 }
4055
Johannes Berg77ee7c82013-02-15 00:48:33 +01004056 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004057 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004058
Johannes Berg77ee7c82013-02-15 00:48:33 +01004059 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004060 if (params.vlan)
4061 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004062
Johannes Berg5727ef12007-12-19 02:03:34 +01004063 return err;
4064}
4065
4066static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4067{
Johannes Berg4c476992010-10-04 21:36:35 +02004068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004069 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004070 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004071 struct station_parameters params;
4072 u8 *mac_addr = NULL;
4073
4074 memset(&params, 0, sizeof(params));
4075
Johannes Berg984c3112013-02-14 23:43:25 +01004076 if (!rdev->ops->add_station)
4077 return -EOPNOTSUPP;
4078
Johannes Berg5727ef12007-12-19 02:03:34 +01004079 if (!info->attrs[NL80211_ATTR_MAC])
4080 return -EINVAL;
4081
Johannes Berg5727ef12007-12-19 02:03:34 +01004082 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4083 return -EINVAL;
4084
4085 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4086 return -EINVAL;
4087
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004088 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4089 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004090 return -EINVAL;
4091
Johannes Berg5727ef12007-12-19 02:03:34 +01004092 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4093 params.supported_rates =
4094 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4095 params.supported_rates_len =
4096 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4097 params.listen_interval =
4098 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004099
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004100 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004101 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004102 else
4103 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004104 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4105 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004106
Jouni Malinen9d62a982013-02-14 21:10:13 +02004107 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4108 params.capability =
4109 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4110 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4111 }
4112
4113 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4114 params.ext_capab =
4115 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4116 params.ext_capab_len =
4117 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4118 }
4119
Jouni Malinen36aedc902008-08-25 11:58:58 +03004120 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4121 params.ht_capa =
4122 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004123
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004124 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4125 params.vht_capa =
4126 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4127
Johannes Bergf8bacc22013-02-14 23:27:01 +01004128 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004129 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004130 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4131 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4132 return -EINVAL;
4133 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004134
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304135 err = nl80211_parse_sta_channel_info(info, &params);
4136 if (err)
4137 return err;
4138
Johannes Bergff276692013-02-15 00:09:01 +01004139 err = nl80211_parse_sta_wme(info, &params);
4140 if (err)
4141 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004142
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004143 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004144 return -EINVAL;
4145
Johannes Berg77ee7c82013-02-15 00:48:33 +01004146 /* When you run into this, adjust the code below for the new flag */
4147 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4148
Johannes Bergbdd90d52011-12-14 12:20:27 +01004149 switch (dev->ieee80211_ptr->iftype) {
4150 case NL80211_IFTYPE_AP:
4151 case NL80211_IFTYPE_AP_VLAN:
4152 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004153 /* ignore WME attributes if iface/sta is not capable */
4154 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4155 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4156 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004157
Johannes Bergbdd90d52011-12-14 12:20:27 +01004158 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004159 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4160 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004161 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004162 /* but don't bother the driver with it */
4163 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004164
Johannes Bergd582cff2012-10-26 17:53:44 +02004165 /* allow authenticated/associated only if driver handles it */
4166 if (!(rdev->wiphy.features &
4167 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4168 params.sta_flags_mask &
4169 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4170 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4171 return -EINVAL;
4172
Johannes Bergbdd90d52011-12-14 12:20:27 +01004173 /* must be last in here for error handling */
4174 params.vlan = get_vlan(info, rdev);
4175 if (IS_ERR(params.vlan))
4176 return PTR_ERR(params.vlan);
4177 break;
4178 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004179 /* ignore uAPSD data */
4180 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4181
Johannes Bergd582cff2012-10-26 17:53:44 +02004182 /* associated is disallowed */
4183 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4184 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004185 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004186 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4187 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004188 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004189 break;
4190 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004191 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004192 /* ignore uAPSD data */
4193 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4194
Johannes Berg77ee7c82013-02-15 00:48:33 +01004195 /* these are disallowed */
4196 if (params.sta_flags_mask &
4197 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4198 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004199 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004200 /* Only TDLS peers can be added */
4201 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4202 return -EINVAL;
4203 /* Can only add if TDLS ... */
4204 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4205 return -EOPNOTSUPP;
4206 /* ... with external setup is supported */
4207 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4208 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004209 /*
4210 * Older wpa_supplicant versions always mark the TDLS peer
4211 * as authorized, but it shouldn't yet be.
4212 */
4213 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004214 break;
4215 default:
4216 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004217 }
4218
Johannes Bergbdd90d52011-12-14 12:20:27 +01004219 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004220
Hila Gonene35e4d22012-06-27 17:19:42 +03004221 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004222
Johannes Berg5727ef12007-12-19 02:03:34 +01004223 if (params.vlan)
4224 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004225 return err;
4226}
4227
4228static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4229{
Johannes Berg4c476992010-10-04 21:36:35 +02004230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4231 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004232 u8 *mac_addr = NULL;
4233
4234 if (info->attrs[NL80211_ATTR_MAC])
4235 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4236
Johannes Berge80cf852009-05-11 14:43:13 +02004237 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004238 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004239 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004240 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4241 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004242
Johannes Berg4c476992010-10-04 21:36:35 +02004243 if (!rdev->ops->del_station)
4244 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004245
Hila Gonene35e4d22012-06-27 17:19:42 +03004246 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004247}
4248
Eric W. Biederman15e47302012-09-07 20:12:54 +00004249static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004250 int flags, struct net_device *dev,
4251 u8 *dst, u8 *next_hop,
4252 struct mpath_info *pinfo)
4253{
4254 void *hdr;
4255 struct nlattr *pinfoattr;
4256
Eric W. Biederman15e47302012-09-07 20:12:54 +00004257 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258 if (!hdr)
4259 return -1;
4260
David S. Miller9360ffd2012-03-29 04:41:26 -04004261 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4262 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4263 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4264 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4265 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004266
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004267 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4268 if (!pinfoattr)
4269 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004270 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4271 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4272 pinfo->frame_qlen))
4273 goto nla_put_failure;
4274 if (((pinfo->filled & MPATH_INFO_SN) &&
4275 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4276 ((pinfo->filled & MPATH_INFO_METRIC) &&
4277 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4278 pinfo->metric)) ||
4279 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4280 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4281 pinfo->exptime)) ||
4282 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4283 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4284 pinfo->flags)) ||
4285 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4286 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4287 pinfo->discovery_timeout)) ||
4288 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4289 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4290 pinfo->discovery_retries)))
4291 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004292
4293 nla_nest_end(msg, pinfoattr);
4294
4295 return genlmsg_end(msg, hdr);
4296
4297 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004298 genlmsg_cancel(msg, hdr);
4299 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300}
4301
4302static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004303 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004304{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004305 struct mpath_info pinfo;
4306 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004307 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004308 u8 dst[ETH_ALEN];
4309 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004310 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004311 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004312
Johannes Berg97990a02013-04-19 01:02:55 +02004313 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004314 if (err)
4315 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004316
4317 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004318 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004319 goto out_err;
4320 }
4321
Johannes Berg97990a02013-04-19 01:02:55 +02004322 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004323 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004324 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004325 }
4326
Johannes Bergbba95fe2008-07-29 13:22:51 +02004327 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004328 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4329 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004330 if (err == -ENOENT)
4331 break;
4332 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004333 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004334
Eric W. Biederman15e47302012-09-07 20:12:54 +00004335 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004336 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004337 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004338 &pinfo) < 0)
4339 goto out;
4340
4341 path_idx++;
4342 }
4343
4344
4345 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004346 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004347 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004348 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004349 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004350 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004351}
4352
4353static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4354{
Johannes Berg4c476992010-10-04 21:36:35 +02004355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004356 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004357 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358 struct mpath_info pinfo;
4359 struct sk_buff *msg;
4360 u8 *dst = NULL;
4361 u8 next_hop[ETH_ALEN];
4362
4363 memset(&pinfo, 0, sizeof(pinfo));
4364
4365 if (!info->attrs[NL80211_ATTR_MAC])
4366 return -EINVAL;
4367
4368 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4369
Johannes Berg4c476992010-10-04 21:36:35 +02004370 if (!rdev->ops->get_mpath)
4371 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004372
Johannes Berg4c476992010-10-04 21:36:35 +02004373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4374 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004375
Hila Gonene35e4d22012-06-27 17:19:42 +03004376 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004377 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004378 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004379
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004380 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004381 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004382 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383
Eric W. Biederman15e47302012-09-07 20:12:54 +00004384 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004385 dev, dst, next_hop, &pinfo) < 0) {
4386 nlmsg_free(msg);
4387 return -ENOBUFS;
4388 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004389
Johannes Berg4c476992010-10-04 21:36:35 +02004390 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391}
4392
4393static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4394{
Johannes Berg4c476992010-10-04 21:36:35 +02004395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4396 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004397 u8 *dst = NULL;
4398 u8 *next_hop = NULL;
4399
4400 if (!info->attrs[NL80211_ATTR_MAC])
4401 return -EINVAL;
4402
4403 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4404 return -EINVAL;
4405
4406 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4407 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4408
Johannes Berg4c476992010-10-04 21:36:35 +02004409 if (!rdev->ops->change_mpath)
4410 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004411
Johannes Berg4c476992010-10-04 21:36:35 +02004412 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4413 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004414
Hila Gonene35e4d22012-06-27 17:19:42 +03004415 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004416}
Johannes Berg4c476992010-10-04 21:36:35 +02004417
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004418static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4419{
Johannes Berg4c476992010-10-04 21:36:35 +02004420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4421 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004422 u8 *dst = NULL;
4423 u8 *next_hop = NULL;
4424
4425 if (!info->attrs[NL80211_ATTR_MAC])
4426 return -EINVAL;
4427
4428 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4429 return -EINVAL;
4430
4431 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4432 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4433
Johannes Berg4c476992010-10-04 21:36:35 +02004434 if (!rdev->ops->add_mpath)
4435 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004436
Johannes Berg4c476992010-10-04 21:36:35 +02004437 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4438 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439
Hila Gonene35e4d22012-06-27 17:19:42 +03004440 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004441}
4442
4443static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4444{
Johannes Berg4c476992010-10-04 21:36:35 +02004445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4446 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447 u8 *dst = NULL;
4448
4449 if (info->attrs[NL80211_ATTR_MAC])
4450 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4451
Johannes Berg4c476992010-10-04 21:36:35 +02004452 if (!rdev->ops->del_mpath)
4453 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004454
Hila Gonene35e4d22012-06-27 17:19:42 +03004455 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004456}
4457
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004458static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4459{
Johannes Berg4c476992010-10-04 21:36:35 +02004460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4461 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004462 struct bss_parameters params;
4463
4464 memset(&params, 0, sizeof(params));
4465 /* default to not changing parameters */
4466 params.use_cts_prot = -1;
4467 params.use_short_preamble = -1;
4468 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004469 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004470 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004471 params.p2p_ctwindow = -1;
4472 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004473
4474 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4475 params.use_cts_prot =
4476 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4477 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4478 params.use_short_preamble =
4479 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4480 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4481 params.use_short_slot_time =
4482 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004483 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4484 params.basic_rates =
4485 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4486 params.basic_rates_len =
4487 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4488 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004489 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4490 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004491 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4492 params.ht_opmode =
4493 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004494
Johannes Berg53cabad2012-11-14 15:17:28 +01004495 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4496 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4497 return -EINVAL;
4498 params.p2p_ctwindow =
4499 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4500 if (params.p2p_ctwindow < 0)
4501 return -EINVAL;
4502 if (params.p2p_ctwindow != 0 &&
4503 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4504 return -EINVAL;
4505 }
4506
4507 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4508 u8 tmp;
4509
4510 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4511 return -EINVAL;
4512 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4513 if (tmp > 1)
4514 return -EINVAL;
4515 params.p2p_opp_ps = tmp;
4516 if (params.p2p_opp_ps &&
4517 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4518 return -EINVAL;
4519 }
4520
Johannes Berg4c476992010-10-04 21:36:35 +02004521 if (!rdev->ops->change_bss)
4522 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004523
Johannes Berg074ac8d2010-09-16 14:58:22 +02004524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4526 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004527
Hila Gonene35e4d22012-06-27 17:19:42 +03004528 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004529}
4530
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004531static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004532 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4533 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4534 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4535 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4536 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4537 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4538};
4539
4540static int parse_reg_rule(struct nlattr *tb[],
4541 struct ieee80211_reg_rule *reg_rule)
4542{
4543 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4544 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4545
4546 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4547 return -EINVAL;
4548 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4549 return -EINVAL;
4550 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4551 return -EINVAL;
4552 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4553 return -EINVAL;
4554 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4555 return -EINVAL;
4556
4557 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4558
4559 freq_range->start_freq_khz =
4560 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4561 freq_range->end_freq_khz =
4562 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4563 freq_range->max_bandwidth_khz =
4564 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4565
4566 power_rule->max_eirp =
4567 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4568
4569 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4570 power_rule->max_antenna_gain =
4571 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4572
4573 return 0;
4574}
4575
4576static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4577{
4578 int r;
4579 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004580 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004581
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004582 /*
4583 * You should only get this when cfg80211 hasn't yet initialized
4584 * completely when built-in to the kernel right between the time
4585 * window between nl80211_init() and regulatory_init(), if that is
4586 * even possible.
4587 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004588 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004589 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004590
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004591 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4592 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004593
4594 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4595
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004596 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4597 user_reg_hint_type =
4598 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4599 else
4600 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4601
4602 switch (user_reg_hint_type) {
4603 case NL80211_USER_REG_HINT_USER:
4604 case NL80211_USER_REG_HINT_CELL_BASE:
4605 break;
4606 default:
4607 return -EINVAL;
4608 }
4609
4610 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004611
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004612 return r;
4613}
4614
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004615static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004616 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004617{
Johannes Berg4c476992010-10-04 21:36:35 +02004618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004619 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004620 struct wireless_dev *wdev = dev->ieee80211_ptr;
4621 struct mesh_config cur_params;
4622 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004623 void *hdr;
4624 struct nlattr *pinfoattr;
4625 struct sk_buff *msg;
4626
Johannes Berg29cbe682010-12-03 09:20:44 +01004627 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4628 return -EOPNOTSUPP;
4629
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004630 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004631 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004632
Johannes Berg29cbe682010-12-03 09:20:44 +01004633 wdev_lock(wdev);
4634 /* If not connected, get default parameters */
4635 if (!wdev->mesh_id_len)
4636 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4637 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004638 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004639 wdev_unlock(wdev);
4640
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004641 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004642 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004643
4644 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004646 if (!msg)
4647 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004648 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004649 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004650 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004651 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004652 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004653 if (!pinfoattr)
4654 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004655 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4656 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4657 cur_params.dot11MeshRetryTimeout) ||
4658 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4659 cur_params.dot11MeshConfirmTimeout) ||
4660 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4661 cur_params.dot11MeshHoldingTimeout) ||
4662 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4663 cur_params.dot11MeshMaxPeerLinks) ||
4664 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4665 cur_params.dot11MeshMaxRetries) ||
4666 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4667 cur_params.dot11MeshTTL) ||
4668 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4669 cur_params.element_ttl) ||
4670 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4671 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004672 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4673 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004674 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4675 cur_params.dot11MeshHWMPmaxPREQretries) ||
4676 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4677 cur_params.path_refresh_time) ||
4678 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4679 cur_params.min_discovery_timeout) ||
4680 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4681 cur_params.dot11MeshHWMPactivePathTimeout) ||
4682 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4683 cur_params.dot11MeshHWMPpreqMinInterval) ||
4684 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4685 cur_params.dot11MeshHWMPperrMinInterval) ||
4686 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4687 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4688 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4689 cur_params.dot11MeshHWMPRootMode) ||
4690 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4691 cur_params.dot11MeshHWMPRannInterval) ||
4692 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4693 cur_params.dot11MeshGateAnnouncementProtocol) ||
4694 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4695 cur_params.dot11MeshForwarding) ||
4696 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004697 cur_params.rssi_threshold) ||
4698 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004699 cur_params.ht_opmode) ||
4700 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4701 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4702 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004703 cur_params.dot11MeshHWMProotInterval) ||
4704 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004705 cur_params.dot11MeshHWMPconfirmationInterval) ||
4706 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4707 cur_params.power_mode) ||
4708 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004709 cur_params.dot11MeshAwakeWindowDuration) ||
4710 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4711 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004712 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004713 nla_nest_end(msg, pinfoattr);
4714 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004715 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004716
Johannes Berg3b858752009-03-12 09:55:09 +01004717 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004719 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004720 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004721 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004722}
4723
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004724static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004725 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4726 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4727 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4728 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4729 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4730 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004731 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004732 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004733 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004734 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4735 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4736 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4737 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4738 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004739 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004740 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004741 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004742 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004743 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004744 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004745 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4746 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004747 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4748 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004749 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004750 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4751 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004752 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004753};
4754
Javier Cardonac80d5452010-12-16 17:37:49 -08004755static const struct nla_policy
4756 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004757 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004758 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4759 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004760 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004761 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004762 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004763 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004764 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004765 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004766};
4767
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004768static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004769 struct mesh_config *cfg,
4770 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004771{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004772 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004773 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004774
Marco Porschea54fba2013-01-07 16:04:48 +01004775#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4776do { \
4777 if (tb[attr]) { \
4778 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4779 return -EINVAL; \
4780 cfg->param = fn(tb[attr]); \
4781 mask |= (1 << (attr - 1)); \
4782 } \
4783} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004784
4785
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004786 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004787 return -EINVAL;
4788 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004789 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004790 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004791 return -EINVAL;
4792
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004793 /* This makes sure that there aren't more than 32 mesh config
4794 * parameters (otherwise our bitfield scheme would not work.) */
4795 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4796
4797 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004798 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004799 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4800 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004801 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004802 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4803 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004804 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004805 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4806 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004807 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004808 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4809 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004810 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004811 mask, NL80211_MESHCONF_MAX_RETRIES,
4812 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004813 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004814 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004815 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004816 mask, NL80211_MESHCONF_ELEMENT_TTL,
4817 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004819 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4820 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4822 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004823 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4824 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004825 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004826 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4827 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004828 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004829 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4830 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004832 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4833 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4835 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004836 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4837 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004838 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004839 1, 65535, mask,
4840 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004841 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004842 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004843 1, 65535, mask,
4844 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004845 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004846 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004847 dot11MeshHWMPnetDiameterTraversalTime,
4848 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004849 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4850 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004851 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4852 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4853 nla_get_u8);
4854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4855 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004856 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004858 dot11MeshGateAnnouncementProtocol, 0, 1,
4859 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004860 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004861 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004862 mask, NL80211_MESHCONF_FORWARDING,
4863 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004864 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004865 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004866 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004867 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004868 mask, NL80211_MESHCONF_HT_OPMODE,
4869 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004870 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004871 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004872 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4873 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004874 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004875 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4876 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004877 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004878 dot11MeshHWMPconfirmationInterval,
4879 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004880 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4881 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004882 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4883 NL80211_MESH_POWER_ACTIVE,
4884 NL80211_MESH_POWER_MAX,
4885 mask, NL80211_MESHCONF_POWER_MODE,
4886 nla_get_u32);
4887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4888 0, 65535, mask,
4889 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4891 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4892 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004893 if (mask_out)
4894 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004895
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004896 return 0;
4897
4898#undef FILL_IN_MESH_PARAM_IF_SET
4899}
4900
Javier Cardonac80d5452010-12-16 17:37:49 -08004901static int nl80211_parse_mesh_setup(struct genl_info *info,
4902 struct mesh_setup *setup)
4903{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004904 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004905 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4906
4907 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4908 return -EINVAL;
4909 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4910 info->attrs[NL80211_ATTR_MESH_SETUP],
4911 nl80211_mesh_setup_params_policy))
4912 return -EINVAL;
4913
Javier Cardonad299a1f2012-03-31 11:31:33 -07004914 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4915 setup->sync_method =
4916 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4917 IEEE80211_SYNC_METHOD_VENDOR :
4918 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4919
Javier Cardonac80d5452010-12-16 17:37:49 -08004920 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4921 setup->path_sel_proto =
4922 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4923 IEEE80211_PATH_PROTOCOL_VENDOR :
4924 IEEE80211_PATH_PROTOCOL_HWMP;
4925
4926 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4927 setup->path_metric =
4928 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4929 IEEE80211_PATH_METRIC_VENDOR :
4930 IEEE80211_PATH_METRIC_AIRTIME;
4931
Javier Cardona581a8b02011-04-07 15:08:27 -07004932
4933 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004934 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004935 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004936 if (!is_valid_ie_attr(ieattr))
4937 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004938 setup->ie = nla_data(ieattr);
4939 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004940 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004941 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4942 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4943 return -EINVAL;
4944 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004945 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4946 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004947 if (setup->is_secure)
4948 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004949
Colleen Twitty6e16d902013-05-08 11:45:59 -07004950 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4951 if (!setup->user_mpm)
4952 return -EINVAL;
4953 setup->auth_id =
4954 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4955 }
4956
Javier Cardonac80d5452010-12-16 17:37:49 -08004957 return 0;
4958}
4959
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004960static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004961 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004962{
4963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4964 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004965 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004966 struct mesh_config cfg;
4967 u32 mask;
4968 int err;
4969
Johannes Berg29cbe682010-12-03 09:20:44 +01004970 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4971 return -EOPNOTSUPP;
4972
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004973 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004974 return -EOPNOTSUPP;
4975
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004976 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004977 if (err)
4978 return err;
4979
Johannes Berg29cbe682010-12-03 09:20:44 +01004980 wdev_lock(wdev);
4981 if (!wdev->mesh_id_len)
4982 err = -ENOLINK;
4983
4984 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004985 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004986
4987 wdev_unlock(wdev);
4988
4989 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004990}
4991
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004992static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4993{
Johannes Berg458f4f92012-12-06 15:47:38 +01004994 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004995 struct sk_buff *msg;
4996 void *hdr = NULL;
4997 struct nlattr *nl_reg_rules;
4998 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004999
5000 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005001 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005002
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005004 if (!msg)
5005 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005006
Eric W. Biederman15e47302012-09-07 20:12:54 +00005007 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005008 NL80211_CMD_GET_REG);
5009 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005010 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005011
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005012 if (reg_last_request_cell_base() &&
5013 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5014 NL80211_USER_REG_HINT_CELL_BASE))
5015 goto nla_put_failure;
5016
Johannes Berg458f4f92012-12-06 15:47:38 +01005017 rcu_read_lock();
5018 regdom = rcu_dereference(cfg80211_regdomain);
5019
5020 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5021 (regdom->dfs_region &&
5022 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5023 goto nla_put_failure_rcu;
5024
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005025 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5026 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005027 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005028
Johannes Berg458f4f92012-12-06 15:47:38 +01005029 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005030 struct nlattr *nl_reg_rule;
5031 const struct ieee80211_reg_rule *reg_rule;
5032 const struct ieee80211_freq_range *freq_range;
5033 const struct ieee80211_power_rule *power_rule;
5034
Johannes Berg458f4f92012-12-06 15:47:38 +01005035 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005036 freq_range = &reg_rule->freq_range;
5037 power_rule = &reg_rule->power_rule;
5038
5039 nl_reg_rule = nla_nest_start(msg, i);
5040 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005041 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005042
David S. Miller9360ffd2012-03-29 04:41:26 -04005043 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5044 reg_rule->flags) ||
5045 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5046 freq_range->start_freq_khz) ||
5047 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5048 freq_range->end_freq_khz) ||
5049 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5050 freq_range->max_bandwidth_khz) ||
5051 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5052 power_rule->max_antenna_gain) ||
5053 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5054 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005055 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005056
5057 nla_nest_end(msg, nl_reg_rule);
5058 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005059 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005060
5061 nla_nest_end(msg, nl_reg_rules);
5062
5063 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005064 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005065
Johannes Berg458f4f92012-12-06 15:47:38 +01005066nla_put_failure_rcu:
5067 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005068nla_put_failure:
5069 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005070put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005071 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005072 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005073}
5074
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005075static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5076{
5077 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5078 struct nlattr *nl_reg_rule;
5079 char *alpha2 = NULL;
5080 int rem_reg_rules = 0, r = 0;
5081 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005082 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005083 struct ieee80211_regdomain *rd = NULL;
5084
5085 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5086 return -EINVAL;
5087
5088 if (!info->attrs[NL80211_ATTR_REG_RULES])
5089 return -EINVAL;
5090
5091 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5092
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005093 if (info->attrs[NL80211_ATTR_DFS_REGION])
5094 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5095
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005096 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005097 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005098 num_rules++;
5099 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005100 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005101 }
5102
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005103 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005104 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005105
5106 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005107 if (!rd)
5108 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005109
5110 rd->n_reg_rules = num_rules;
5111 rd->alpha2[0] = alpha2[0];
5112 rd->alpha2[1] = alpha2[1];
5113
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005114 /*
5115 * Disable DFS master mode if the DFS region was
5116 * not supported or known on this kernel.
5117 */
5118 if (reg_supported_dfs_region(dfs_region))
5119 rd->dfs_region = dfs_region;
5120
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005121 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005122 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005123 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005124 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5125 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005126 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5127 if (r)
5128 goto bad_reg;
5129
5130 rule_idx++;
5131
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005132 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5133 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005134 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005135 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005136 }
5137
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005138 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005139 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005140 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005141
Johannes Bergd2372b32008-10-24 20:32:20 +02005142 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005143 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005144 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005145}
5146
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005147static int validate_scan_freqs(struct nlattr *freqs)
5148{
5149 struct nlattr *attr1, *attr2;
5150 int n_channels = 0, tmp1, tmp2;
5151
5152 nla_for_each_nested(attr1, freqs, tmp1) {
5153 n_channels++;
5154 /*
5155 * Some hardware has a limited channel list for
5156 * scanning, and it is pretty much nonsensical
5157 * to scan for a channel twice, so disallow that
5158 * and don't require drivers to check that the
5159 * channel list they get isn't longer than what
5160 * they can scan, as long as they can scan all
5161 * the channels they registered at once.
5162 */
5163 nla_for_each_nested(attr2, freqs, tmp2)
5164 if (attr1 != attr2 &&
5165 nla_get_u32(attr1) == nla_get_u32(attr2))
5166 return 0;
5167 }
5168
5169 return n_channels;
5170}
5171
Johannes Berg2a519312009-02-10 21:25:55 +01005172static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5173{
Johannes Berg4c476992010-10-04 21:36:35 +02005174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005175 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005176 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005177 struct nlattr *attr;
5178 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005179 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005180 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005181
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005182 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5183 return -EINVAL;
5184
Johannes Berg79c97e92009-07-07 03:56:12 +02005185 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005186
Johannes Berg4c476992010-10-04 21:36:35 +02005187 if (!rdev->ops->scan)
5188 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005189
Johannes Bergf9f47522013-03-19 15:04:07 +01005190 if (rdev->scan_req) {
5191 err = -EBUSY;
5192 goto unlock;
5193 }
Johannes Berg2a519312009-02-10 21:25:55 +01005194
5195 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005196 n_channels = validate_scan_freqs(
5197 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005198 if (!n_channels) {
5199 err = -EINVAL;
5200 goto unlock;
5201 }
Johannes Berg2a519312009-02-10 21:25:55 +01005202 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005203 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005204 n_channels = 0;
5205
Johannes Berg2a519312009-02-10 21:25:55 +01005206 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5207 if (wiphy->bands[band])
5208 n_channels += wiphy->bands[band]->n_channels;
5209 }
5210
5211 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5212 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5213 n_ssids++;
5214
Johannes Bergf9f47522013-03-19 15:04:07 +01005215 if (n_ssids > wiphy->max_scan_ssids) {
5216 err = -EINVAL;
5217 goto unlock;
5218 }
Johannes Berg2a519312009-02-10 21:25:55 +01005219
Jouni Malinen70692ad2009-02-16 19:39:13 +02005220 if (info->attrs[NL80211_ATTR_IE])
5221 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5222 else
5223 ie_len = 0;
5224
Johannes Bergf9f47522013-03-19 15:04:07 +01005225 if (ie_len > wiphy->max_scan_ie_len) {
5226 err = -EINVAL;
5227 goto unlock;
5228 }
Johannes Berg18a83652009-03-31 12:12:05 +02005229
Johannes Berg2a519312009-02-10 21:25:55 +01005230 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005231 + sizeof(*request->ssids) * n_ssids
5232 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005233 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005234 if (!request) {
5235 err = -ENOMEM;
5236 goto unlock;
5237 }
Johannes Berg2a519312009-02-10 21:25:55 +01005238
Johannes Berg2a519312009-02-10 21:25:55 +01005239 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005240 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005241 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005242 if (ie_len) {
5243 if (request->ssids)
5244 request->ie = (void *)(request->ssids + n_ssids);
5245 else
5246 request->ie = (void *)(request->channels + n_channels);
5247 }
Johannes Berg2a519312009-02-10 21:25:55 +01005248
Johannes Berg584991d2009-11-02 13:32:03 +01005249 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005250 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5251 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005252 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005253 struct ieee80211_channel *chan;
5254
5255 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5256
5257 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005258 err = -EINVAL;
5259 goto out_free;
5260 }
Johannes Berg584991d2009-11-02 13:32:03 +01005261
5262 /* ignore disabled channels */
5263 if (chan->flags & IEEE80211_CHAN_DISABLED)
5264 continue;
5265
5266 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005267 i++;
5268 }
5269 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005270 enum ieee80211_band band;
5271
Johannes Berg2a519312009-02-10 21:25:55 +01005272 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005273 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5274 int j;
5275 if (!wiphy->bands[band])
5276 continue;
5277 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005278 struct ieee80211_channel *chan;
5279
5280 chan = &wiphy->bands[band]->channels[j];
5281
5282 if (chan->flags & IEEE80211_CHAN_DISABLED)
5283 continue;
5284
5285 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005286 i++;
5287 }
5288 }
5289 }
5290
Johannes Berg584991d2009-11-02 13:32:03 +01005291 if (!i) {
5292 err = -EINVAL;
5293 goto out_free;
5294 }
5295
5296 request->n_channels = i;
5297
Johannes Berg2a519312009-02-10 21:25:55 +01005298 i = 0;
5299 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5300 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005301 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005302 err = -EINVAL;
5303 goto out_free;
5304 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005305 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005306 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005307 i++;
5308 }
5309 }
5310
Jouni Malinen70692ad2009-02-16 19:39:13 +02005311 if (info->attrs[NL80211_ATTR_IE]) {
5312 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005313 memcpy((void *)request->ie,
5314 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005315 request->ie_len);
5316 }
5317
Johannes Berg34850ab2011-07-18 18:08:35 +02005318 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005319 if (wiphy->bands[i])
5320 request->rates[i] =
5321 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005322
5323 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5324 nla_for_each_nested(attr,
5325 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5326 tmp) {
5327 enum ieee80211_band band = nla_type(attr);
5328
Dan Carpenter84404622011-07-29 11:52:18 +03005329 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005330 err = -EINVAL;
5331 goto out_free;
5332 }
5333 err = ieee80211_get_ratemask(wiphy->bands[band],
5334 nla_data(attr),
5335 nla_len(attr),
5336 &request->rates[band]);
5337 if (err)
5338 goto out_free;
5339 }
5340 }
5341
Sam Leffler46856bb2012-10-11 21:03:32 -07005342 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005343 request->flags = nla_get_u32(
5344 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005345 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5346 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005347 err = -EOPNOTSUPP;
5348 goto out_free;
5349 }
5350 }
Sam Lefflered4737712012-10-11 21:03:31 -07005351
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305352 request->no_cck =
5353 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5354
Johannes Bergfd014282012-06-18 19:17:03 +02005355 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005356 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005357 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005358
Johannes Berg79c97e92009-07-07 03:56:12 +02005359 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005360 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005361
Johannes Berg463d0182009-07-14 00:33:35 +02005362 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005363 nl80211_send_scan_start(rdev, wdev);
5364 if (wdev->netdev)
5365 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005366 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005367 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005368 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005369 kfree(request);
5370 }
Johannes Berg3b858752009-03-12 09:55:09 +01005371
Johannes Bergf9f47522013-03-19 15:04:07 +01005372 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005373 return err;
5374}
5375
Luciano Coelho807f8a82011-05-11 17:09:35 +03005376static int nl80211_start_sched_scan(struct sk_buff *skb,
5377 struct genl_info *info)
5378{
5379 struct cfg80211_sched_scan_request *request;
5380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5381 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005382 struct nlattr *attr;
5383 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005384 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005385 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005386 enum ieee80211_band band;
5387 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005388 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005389
5390 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5391 !rdev->ops->sched_scan_start)
5392 return -EOPNOTSUPP;
5393
5394 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5395 return -EINVAL;
5396
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005397 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5398 return -EINVAL;
5399
5400 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5401 if (interval == 0)
5402 return -EINVAL;
5403
Luciano Coelho807f8a82011-05-11 17:09:35 +03005404 wiphy = &rdev->wiphy;
5405
5406 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5407 n_channels = validate_scan_freqs(
5408 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5409 if (!n_channels)
5410 return -EINVAL;
5411 } else {
5412 n_channels = 0;
5413
5414 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5415 if (wiphy->bands[band])
5416 n_channels += wiphy->bands[band]->n_channels;
5417 }
5418
5419 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5420 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5421 tmp)
5422 n_ssids++;
5423
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005424 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005425 return -EINVAL;
5426
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005427 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5428 nla_for_each_nested(attr,
5429 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5430 tmp)
5431 n_match_sets++;
5432
5433 if (n_match_sets > wiphy->max_match_sets)
5434 return -EINVAL;
5435
Luciano Coelho807f8a82011-05-11 17:09:35 +03005436 if (info->attrs[NL80211_ATTR_IE])
5437 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5438 else
5439 ie_len = 0;
5440
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005441 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005442 return -EINVAL;
5443
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005444 if (rdev->sched_scan_req) {
5445 err = -EINPROGRESS;
5446 goto out;
5447 }
5448
Luciano Coelho807f8a82011-05-11 17:09:35 +03005449 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005450 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005451 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005452 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005453 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005454 if (!request) {
5455 err = -ENOMEM;
5456 goto out;
5457 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005458
5459 if (n_ssids)
5460 request->ssids = (void *)&request->channels[n_channels];
5461 request->n_ssids = n_ssids;
5462 if (ie_len) {
5463 if (request->ssids)
5464 request->ie = (void *)(request->ssids + n_ssids);
5465 else
5466 request->ie = (void *)(request->channels + n_channels);
5467 }
5468
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005469 if (n_match_sets) {
5470 if (request->ie)
5471 request->match_sets = (void *)(request->ie + ie_len);
5472 else if (request->ssids)
5473 request->match_sets =
5474 (void *)(request->ssids + n_ssids);
5475 else
5476 request->match_sets =
5477 (void *)(request->channels + n_channels);
5478 }
5479 request->n_match_sets = n_match_sets;
5480
Luciano Coelho807f8a82011-05-11 17:09:35 +03005481 i = 0;
5482 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5483 /* user specified, bail out if channel not found */
5484 nla_for_each_nested(attr,
5485 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5486 tmp) {
5487 struct ieee80211_channel *chan;
5488
5489 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5490
5491 if (!chan) {
5492 err = -EINVAL;
5493 goto out_free;
5494 }
5495
5496 /* ignore disabled channels */
5497 if (chan->flags & IEEE80211_CHAN_DISABLED)
5498 continue;
5499
5500 request->channels[i] = chan;
5501 i++;
5502 }
5503 } else {
5504 /* all channels */
5505 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5506 int j;
5507 if (!wiphy->bands[band])
5508 continue;
5509 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5510 struct ieee80211_channel *chan;
5511
5512 chan = &wiphy->bands[band]->channels[j];
5513
5514 if (chan->flags & IEEE80211_CHAN_DISABLED)
5515 continue;
5516
5517 request->channels[i] = chan;
5518 i++;
5519 }
5520 }
5521 }
5522
5523 if (!i) {
5524 err = -EINVAL;
5525 goto out_free;
5526 }
5527
5528 request->n_channels = i;
5529
5530 i = 0;
5531 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5532 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5533 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005534 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005535 err = -EINVAL;
5536 goto out_free;
5537 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005538 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005539 memcpy(request->ssids[i].ssid, nla_data(attr),
5540 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005541 i++;
5542 }
5543 }
5544
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005545 i = 0;
5546 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5547 nla_for_each_nested(attr,
5548 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5549 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005550 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005551
5552 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5553 nla_data(attr), nla_len(attr),
5554 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005555 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005556 if (ssid) {
5557 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5558 err = -EINVAL;
5559 goto out_free;
5560 }
5561 memcpy(request->match_sets[i].ssid.ssid,
5562 nla_data(ssid), nla_len(ssid));
5563 request->match_sets[i].ssid.ssid_len =
5564 nla_len(ssid);
5565 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005566 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5567 if (rssi)
5568 request->rssi_thold = nla_get_u32(rssi);
5569 else
5570 request->rssi_thold =
5571 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005572 i++;
5573 }
5574 }
5575
Luciano Coelho807f8a82011-05-11 17:09:35 +03005576 if (info->attrs[NL80211_ATTR_IE]) {
5577 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5578 memcpy((void *)request->ie,
5579 nla_data(info->attrs[NL80211_ATTR_IE]),
5580 request->ie_len);
5581 }
5582
Sam Leffler46856bb2012-10-11 21:03:32 -07005583 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005584 request->flags = nla_get_u32(
5585 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005586 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5587 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005588 err = -EOPNOTSUPP;
5589 goto out_free;
5590 }
5591 }
Sam Lefflered4737712012-10-11 21:03:31 -07005592
Luciano Coelho807f8a82011-05-11 17:09:35 +03005593 request->dev = dev;
5594 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005595 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005596 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005597
Hila Gonene35e4d22012-06-27 17:19:42 +03005598 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005599 if (!err) {
5600 rdev->sched_scan_req = request;
5601 nl80211_send_sched_scan(rdev, dev,
5602 NL80211_CMD_START_SCHED_SCAN);
5603 goto out;
5604 }
5605
5606out_free:
5607 kfree(request);
5608out:
5609 return err;
5610}
5611
5612static int nl80211_stop_sched_scan(struct sk_buff *skb,
5613 struct genl_info *info)
5614{
5615 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5616
5617 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5618 !rdev->ops->sched_scan_stop)
5619 return -EOPNOTSUPP;
5620
Johannes Berg5fe231e2013-05-08 21:45:15 +02005621 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005622}
5623
Simon Wunderlich04f39042013-02-08 18:16:19 +01005624static int nl80211_start_radar_detection(struct sk_buff *skb,
5625 struct genl_info *info)
5626{
5627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5628 struct net_device *dev = info->user_ptr[1];
5629 struct wireless_dev *wdev = dev->ieee80211_ptr;
5630 struct cfg80211_chan_def chandef;
5631 int err;
5632
5633 err = nl80211_parse_chandef(rdev, info, &chandef);
5634 if (err)
5635 return err;
5636
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005637 if (netif_carrier_ok(dev))
5638 return -EBUSY;
5639
Simon Wunderlich04f39042013-02-08 18:16:19 +01005640 if (wdev->cac_started)
5641 return -EBUSY;
5642
5643 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5644 if (err < 0)
5645 return err;
5646
5647 if (err == 0)
5648 return -EINVAL;
5649
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005650 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005651 return -EINVAL;
5652
5653 if (!rdev->ops->start_radar_detection)
5654 return -EOPNOTSUPP;
5655
Simon Wunderlich04f39042013-02-08 18:16:19 +01005656 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5657 chandef.chan, CHAN_MODE_SHARED,
5658 BIT(chandef.width));
5659 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005660 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005661
5662 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5663 if (!err) {
5664 wdev->channel = chandef.chan;
5665 wdev->cac_started = true;
5666 wdev->cac_start_time = jiffies;
5667 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005668 return err;
5669}
5670
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005671static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5672{
5673 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5674 struct net_device *dev = info->user_ptr[1];
5675 struct wireless_dev *wdev = dev->ieee80211_ptr;
5676 struct cfg80211_csa_settings params;
5677 /* csa_attrs is defined static to avoid waste of stack size - this
5678 * function is called under RTNL lock, so this should not be a problem.
5679 */
5680 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5681 u8 radar_detect_width = 0;
5682 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005683 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005684
5685 if (!rdev->ops->channel_switch ||
5686 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5687 return -EOPNOTSUPP;
5688
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005689 switch (dev->ieee80211_ptr->iftype) {
5690 case NL80211_IFTYPE_AP:
5691 case NL80211_IFTYPE_P2P_GO:
5692 need_new_beacon = true;
5693
5694 /* useless if AP is not running */
5695 if (!wdev->beacon_interval)
5696 return -EINVAL;
5697 break;
5698 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005699 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005700 break;
5701 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005702 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005703 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005704
5705 memset(&params, 0, sizeof(params));
5706
5707 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5708 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5709 return -EINVAL;
5710
5711 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005712 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005713 return -EINVAL;
5714
5715 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5716
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005717 if (!need_new_beacon)
5718 goto skip_beacons;
5719
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005720 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5721 if (err)
5722 return err;
5723
5724 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5725 info->attrs[NL80211_ATTR_CSA_IES],
5726 nl80211_policy);
5727 if (err)
5728 return err;
5729
5730 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5731 if (err)
5732 return err;
5733
5734 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5735 return -EINVAL;
5736
5737 params.counter_offset_beacon =
5738 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5739 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5740 return -EINVAL;
5741
5742 /* sanity check - counters should be the same */
5743 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5744 params.count)
5745 return -EINVAL;
5746
5747 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5748 params.counter_offset_presp =
5749 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5750 if (params.counter_offset_presp >=
5751 params.beacon_csa.probe_resp_len)
5752 return -EINVAL;
5753
5754 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5755 params.count)
5756 return -EINVAL;
5757 }
5758
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005759skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005760 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5761 if (err)
5762 return err;
5763
5764 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5765 return -EINVAL;
5766
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005767 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005768 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5769 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005770 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5771 &params.chandef);
5772 if (err < 0) {
5773 return err;
5774 } else if (err) {
5775 radar_detect_width = BIT(params.chandef.width);
5776 params.radar_required = true;
5777 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005778 }
5779
5780 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5781 params.chandef.chan,
5782 CHAN_MODE_SHARED,
5783 radar_detect_width);
5784 if (err)
5785 return err;
5786
5787 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5788 params.block_tx = true;
5789
5790 return rdev_channel_switch(rdev, dev, &params);
5791}
5792
Johannes Berg9720bb32011-06-21 09:45:33 +02005793static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5794 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005795 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005796 struct wireless_dev *wdev,
5797 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005798{
Johannes Berg48ab9052009-07-10 18:42:31 +02005799 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005800 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005801 void *hdr;
5802 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005803 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005804
5805 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005806
Eric W. Biederman15e47302012-09-07 20:12:54 +00005807 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005808 NL80211_CMD_NEW_SCAN_RESULTS);
5809 if (!hdr)
5810 return -1;
5811
Johannes Berg9720bb32011-06-21 09:45:33 +02005812 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5813
Johannes Berg97990a02013-04-19 01:02:55 +02005814 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5815 goto nla_put_failure;
5816 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005817 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5818 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005819 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5820 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005821
5822 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5823 if (!bss)
5824 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005825 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005826 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005827 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005828
5829 rcu_read_lock();
5830 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005831 if (ies) {
5832 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5833 goto fail_unlock_rcu;
5834 tsf = true;
5835 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5836 ies->len, ies->data))
5837 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005838 }
5839 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005840 if (ies) {
5841 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5842 goto fail_unlock_rcu;
5843 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5844 ies->len, ies->data))
5845 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005846 }
5847 rcu_read_unlock();
5848
David S. Miller9360ffd2012-03-29 04:41:26 -04005849 if (res->beacon_interval &&
5850 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5851 goto nla_put_failure;
5852 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5853 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005854 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005855 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5856 jiffies_to_msecs(jiffies - intbss->ts)))
5857 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005858
Johannes Berg77965c92009-02-18 18:45:06 +01005859 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005860 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005861 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5862 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005863 break;
5864 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005865 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5866 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005867 break;
5868 default:
5869 break;
5870 }
5871
Johannes Berg48ab9052009-07-10 18:42:31 +02005872 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005873 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005874 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005875 if (intbss == wdev->current_bss &&
5876 nla_put_u32(msg, NL80211_BSS_STATUS,
5877 NL80211_BSS_STATUS_ASSOCIATED))
5878 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005879 break;
5880 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005881 if (intbss == wdev->current_bss &&
5882 nla_put_u32(msg, NL80211_BSS_STATUS,
5883 NL80211_BSS_STATUS_IBSS_JOINED))
5884 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005885 break;
5886 default:
5887 break;
5888 }
5889
Johannes Berg2a519312009-02-10 21:25:55 +01005890 nla_nest_end(msg, bss);
5891
5892 return genlmsg_end(msg, hdr);
5893
Johannes Berg8cef2c92013-02-05 16:54:31 +01005894 fail_unlock_rcu:
5895 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005896 nla_put_failure:
5897 genlmsg_cancel(msg, hdr);
5898 return -EMSGSIZE;
5899}
5900
Johannes Berg97990a02013-04-19 01:02:55 +02005901static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005902{
Johannes Berg48ab9052009-07-10 18:42:31 +02005903 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005904 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005905 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005906 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005907 int err;
5908
Johannes Berg97990a02013-04-19 01:02:55 +02005909 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005910 if (err)
5911 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005912
Johannes Berg48ab9052009-07-10 18:42:31 +02005913 wdev_lock(wdev);
5914 spin_lock_bh(&rdev->bss_lock);
5915 cfg80211_bss_expire(rdev);
5916
Johannes Berg9720bb32011-06-21 09:45:33 +02005917 cb->seq = rdev->bss_generation;
5918
Johannes Berg48ab9052009-07-10 18:42:31 +02005919 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005920 if (++idx <= start)
5921 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005922 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005923 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005924 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005925 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005926 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005927 }
5928 }
5929
Johannes Berg48ab9052009-07-10 18:42:31 +02005930 spin_unlock_bh(&rdev->bss_lock);
5931 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005932
Johannes Berg97990a02013-04-19 01:02:55 +02005933 cb->args[2] = idx;
5934 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005935
Johannes Berg67748892010-10-04 21:14:06 +02005936 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005937}
5938
Eric W. Biederman15e47302012-09-07 20:12:54 +00005939static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005940 int flags, struct net_device *dev,
5941 struct survey_info *survey)
5942{
5943 void *hdr;
5944 struct nlattr *infoattr;
5945
Eric W. Biederman15e47302012-09-07 20:12:54 +00005946 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005947 NL80211_CMD_NEW_SURVEY_RESULTS);
5948 if (!hdr)
5949 return -ENOMEM;
5950
David S. Miller9360ffd2012-03-29 04:41:26 -04005951 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5952 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005953
5954 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5955 if (!infoattr)
5956 goto nla_put_failure;
5957
David S. Miller9360ffd2012-03-29 04:41:26 -04005958 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5959 survey->channel->center_freq))
5960 goto nla_put_failure;
5961
5962 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5963 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5964 goto nla_put_failure;
5965 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5966 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5967 goto nla_put_failure;
5968 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5969 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5970 survey->channel_time))
5971 goto nla_put_failure;
5972 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5973 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5974 survey->channel_time_busy))
5975 goto nla_put_failure;
5976 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5977 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5978 survey->channel_time_ext_busy))
5979 goto nla_put_failure;
5980 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5981 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5982 survey->channel_time_rx))
5983 goto nla_put_failure;
5984 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5985 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5986 survey->channel_time_tx))
5987 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005988
5989 nla_nest_end(msg, infoattr);
5990
5991 return genlmsg_end(msg, hdr);
5992
5993 nla_put_failure:
5994 genlmsg_cancel(msg, hdr);
5995 return -EMSGSIZE;
5996}
5997
5998static int nl80211_dump_survey(struct sk_buff *skb,
5999 struct netlink_callback *cb)
6000{
6001 struct survey_info survey;
6002 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006003 struct wireless_dev *wdev;
6004 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006005 int res;
6006
Johannes Berg97990a02013-04-19 01:02:55 +02006007 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006008 if (res)
6009 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006010
Johannes Berg97990a02013-04-19 01:02:55 +02006011 if (!wdev->netdev) {
6012 res = -EINVAL;
6013 goto out_err;
6014 }
6015
Holger Schurig61fa7132009-11-11 12:25:40 +01006016 if (!dev->ops->dump_survey) {
6017 res = -EOPNOTSUPP;
6018 goto out_err;
6019 }
6020
6021 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006022 struct ieee80211_channel *chan;
6023
Johannes Berg97990a02013-04-19 01:02:55 +02006024 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006025 if (res == -ENOENT)
6026 break;
6027 if (res)
6028 goto out_err;
6029
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006030 /* Survey without a channel doesn't make sense */
6031 if (!survey.channel) {
6032 res = -EINVAL;
6033 goto out;
6034 }
6035
6036 chan = ieee80211_get_channel(&dev->wiphy,
6037 survey.channel->center_freq);
6038 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6039 survey_idx++;
6040 continue;
6041 }
6042
Holger Schurig61fa7132009-11-11 12:25:40 +01006043 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006044 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006045 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006046 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006047 goto out;
6048 survey_idx++;
6049 }
6050
6051 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006052 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006053 res = skb->len;
6054 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006055 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006056 return res;
6057}
6058
Samuel Ortizb23aa672009-07-01 21:26:54 +02006059static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6060{
6061 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6062 NL80211_WPA_VERSION_2));
6063}
6064
Jouni Malinen636a5d32009-03-19 13:39:22 +02006065static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6066{
Johannes Berg4c476992010-10-04 21:36:35 +02006067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6068 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006069 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006070 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6071 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006072 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006073 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006074 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006075
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006076 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6077 return -EINVAL;
6078
6079 if (!info->attrs[NL80211_ATTR_MAC])
6080 return -EINVAL;
6081
Jouni Malinen17780922009-03-27 20:52:47 +02006082 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6083 return -EINVAL;
6084
Johannes Berg19957bb2009-07-02 17:20:43 +02006085 if (!info->attrs[NL80211_ATTR_SSID])
6086 return -EINVAL;
6087
6088 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6089 return -EINVAL;
6090
Johannes Bergfffd0932009-07-08 14:22:54 +02006091 err = nl80211_parse_key(info, &key);
6092 if (err)
6093 return err;
6094
6095 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006096 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6097 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006098 if (!key.p.key || !key.p.key_len)
6099 return -EINVAL;
6100 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6101 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6102 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6103 key.p.key_len != WLAN_KEY_LEN_WEP104))
6104 return -EINVAL;
6105 if (key.idx > 4)
6106 return -EINVAL;
6107 } else {
6108 key.p.key_len = 0;
6109 key.p.key = NULL;
6110 }
6111
Johannes Bergafea0b72010-08-10 09:46:42 +02006112 if (key.idx >= 0) {
6113 int i;
6114 bool ok = false;
6115 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6116 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6117 ok = true;
6118 break;
6119 }
6120 }
Johannes Berg4c476992010-10-04 21:36:35 +02006121 if (!ok)
6122 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006123 }
6124
Johannes Berg4c476992010-10-04 21:36:35 +02006125 if (!rdev->ops->auth)
6126 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006127
Johannes Berg074ac8d2010-09-16 14:58:22 +02006128 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006129 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6130 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006131
Johannes Berg19957bb2009-07-02 17:20:43 +02006132 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006133 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006134 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006135 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6136 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006137
Johannes Berg19957bb2009-07-02 17:20:43 +02006138 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6139 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6140
6141 if (info->attrs[NL80211_ATTR_IE]) {
6142 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6143 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6144 }
6145
6146 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006147 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006148 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006149
Jouni Malinene39e5b52012-09-30 19:29:39 +03006150 if (auth_type == NL80211_AUTHTYPE_SAE &&
6151 !info->attrs[NL80211_ATTR_SAE_DATA])
6152 return -EINVAL;
6153
6154 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6155 if (auth_type != NL80211_AUTHTYPE_SAE)
6156 return -EINVAL;
6157 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6158 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6159 /* need to include at least Auth Transaction and Status Code */
6160 if (sae_data_len < 4)
6161 return -EINVAL;
6162 }
6163
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006164 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6165
Johannes Berg95de8172012-01-20 13:55:25 +01006166 /*
6167 * Since we no longer track auth state, ignore
6168 * requests to only change local state.
6169 */
6170 if (local_state_change)
6171 return 0;
6172
Johannes Berg91bf9b22013-05-15 17:44:01 +02006173 wdev_lock(dev->ieee80211_ptr);
6174 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6175 ssid, ssid_len, ie, ie_len,
6176 key.p.key, key.p.key_len, key.idx,
6177 sae_data, sae_data_len);
6178 wdev_unlock(dev->ieee80211_ptr);
6179 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006180}
6181
Johannes Bergc0692b82010-08-27 14:26:53 +03006182static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6183 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006184 struct cfg80211_crypto_settings *settings,
6185 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006186{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006187 memset(settings, 0, sizeof(*settings));
6188
Samuel Ortizb23aa672009-07-01 21:26:54 +02006189 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6190
Johannes Bergc0692b82010-08-27 14:26:53 +03006191 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6192 u16 proto;
6193 proto = nla_get_u16(
6194 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6195 settings->control_port_ethertype = cpu_to_be16(proto);
6196 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6197 proto != ETH_P_PAE)
6198 return -EINVAL;
6199 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6200 settings->control_port_no_encrypt = true;
6201 } else
6202 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6203
Samuel Ortizb23aa672009-07-01 21:26:54 +02006204 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6205 void *data;
6206 int len, i;
6207
6208 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6209 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6210 settings->n_ciphers_pairwise = len / sizeof(u32);
6211
6212 if (len % sizeof(u32))
6213 return -EINVAL;
6214
Johannes Berg3dc27d22009-07-02 21:36:37 +02006215 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006216 return -EINVAL;
6217
6218 memcpy(settings->ciphers_pairwise, data, len);
6219
6220 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006221 if (!cfg80211_supported_cipher_suite(
6222 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006223 settings->ciphers_pairwise[i]))
6224 return -EINVAL;
6225 }
6226
6227 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6228 settings->cipher_group =
6229 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006230 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6231 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006232 return -EINVAL;
6233 }
6234
6235 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6236 settings->wpa_versions =
6237 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6238 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6239 return -EINVAL;
6240 }
6241
6242 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6243 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006244 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006245
6246 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6247 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6248 settings->n_akm_suites = len / sizeof(u32);
6249
6250 if (len % sizeof(u32))
6251 return -EINVAL;
6252
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006253 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6254 return -EINVAL;
6255
Samuel Ortizb23aa672009-07-01 21:26:54 +02006256 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006257 }
6258
6259 return 0;
6260}
6261
Jouni Malinen636a5d32009-03-19 13:39:22 +02006262static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6263{
Johannes Berg4c476992010-10-04 21:36:35 +02006264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6265 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006266 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006267 struct cfg80211_assoc_request req = {};
6268 const u8 *bssid, *ssid;
6269 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006270
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006271 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6272 return -EINVAL;
6273
6274 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006275 !info->attrs[NL80211_ATTR_SSID] ||
6276 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006277 return -EINVAL;
6278
Johannes Berg4c476992010-10-04 21:36:35 +02006279 if (!rdev->ops->assoc)
6280 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006281
Johannes Berg074ac8d2010-09-16 14:58:22 +02006282 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006283 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6284 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006285
Johannes Berg19957bb2009-07-02 17:20:43 +02006286 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006287
Johannes Berg19957bb2009-07-02 17:20:43 +02006288 chan = ieee80211_get_channel(&rdev->wiphy,
6289 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006290 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6291 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006292
Johannes Berg19957bb2009-07-02 17:20:43 +02006293 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6294 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006295
6296 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006297 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6298 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006299 }
6300
Jouni Malinendc6382c2009-05-06 22:09:37 +03006301 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006302 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006303 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006304 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006305 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006306 else if (mfp != NL80211_MFP_NO)
6307 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006308 }
6309
Johannes Berg3e5d7642009-07-07 14:37:26 +02006310 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006311 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006312
Ben Greear7e7c8922011-11-18 11:31:59 -08006313 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006314 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006315
6316 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006317 memcpy(&req.ht_capa_mask,
6318 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6319 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006320
6321 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006322 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006323 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006324 memcpy(&req.ht_capa,
6325 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6326 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006327 }
6328
Johannes Bergee2aca32013-02-21 17:36:01 +01006329 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006330 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006331
6332 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006333 memcpy(&req.vht_capa_mask,
6334 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6335 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006336
6337 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006338 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006339 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006340 memcpy(&req.vht_capa,
6341 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6342 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006343 }
6344
Johannes Bergf62fab72013-02-21 20:09:09 +01006345 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006346 if (!err) {
6347 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006348 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6349 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006350 wdev_unlock(dev->ieee80211_ptr);
6351 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006352
Jouni Malinen636a5d32009-03-19 13:39:22 +02006353 return err;
6354}
6355
6356static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6357{
Johannes Berg4c476992010-10-04 21:36:35 +02006358 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6359 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006360 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006361 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006362 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006363 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006364
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006365 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6366 return -EINVAL;
6367
6368 if (!info->attrs[NL80211_ATTR_MAC])
6369 return -EINVAL;
6370
6371 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6372 return -EINVAL;
6373
Johannes Berg4c476992010-10-04 21:36:35 +02006374 if (!rdev->ops->deauth)
6375 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006376
Johannes Berg074ac8d2010-09-16 14:58:22 +02006377 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006378 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6379 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006380
Johannes Berg19957bb2009-07-02 17:20:43 +02006381 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006382
Johannes Berg19957bb2009-07-02 17:20:43 +02006383 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6384 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006385 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006386 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006387 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006388
6389 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006390 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6391 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006392 }
6393
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006394 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6395
Johannes Berg91bf9b22013-05-15 17:44:01 +02006396 wdev_lock(dev->ieee80211_ptr);
6397 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6398 local_state_change);
6399 wdev_unlock(dev->ieee80211_ptr);
6400 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006401}
6402
6403static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6404{
Johannes Berg4c476992010-10-04 21:36:35 +02006405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6406 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006407 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006408 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006409 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006410 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006411
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006412 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6413 return -EINVAL;
6414
6415 if (!info->attrs[NL80211_ATTR_MAC])
6416 return -EINVAL;
6417
6418 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6419 return -EINVAL;
6420
Johannes Berg4c476992010-10-04 21:36:35 +02006421 if (!rdev->ops->disassoc)
6422 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006423
Johannes Berg074ac8d2010-09-16 14:58:22 +02006424 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006425 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6426 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006427
Johannes Berg19957bb2009-07-02 17:20:43 +02006428 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006429
Johannes Berg19957bb2009-07-02 17:20:43 +02006430 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6431 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006432 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006433 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006434 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006435
6436 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006437 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6438 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006439 }
6440
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006441 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6442
Johannes Berg91bf9b22013-05-15 17:44:01 +02006443 wdev_lock(dev->ieee80211_ptr);
6444 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6445 local_state_change);
6446 wdev_unlock(dev->ieee80211_ptr);
6447 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006448}
6449
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006450static bool
6451nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6452 int mcast_rate[IEEE80211_NUM_BANDS],
6453 int rateval)
6454{
6455 struct wiphy *wiphy = &rdev->wiphy;
6456 bool found = false;
6457 int band, i;
6458
6459 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6460 struct ieee80211_supported_band *sband;
6461
6462 sband = wiphy->bands[band];
6463 if (!sband)
6464 continue;
6465
6466 for (i = 0; i < sband->n_bitrates; i++) {
6467 if (sband->bitrates[i].bitrate == rateval) {
6468 mcast_rate[band] = i + 1;
6469 found = true;
6470 break;
6471 }
6472 }
6473 }
6474
6475 return found;
6476}
6477
Johannes Berg04a773a2009-04-19 21:24:32 +02006478static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6479{
Johannes Berg4c476992010-10-04 21:36:35 +02006480 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6481 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006482 struct cfg80211_ibss_params ibss;
6483 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006484 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006485 int err;
6486
Johannes Berg8e30bc52009-04-22 17:45:38 +02006487 memset(&ibss, 0, sizeof(ibss));
6488
Johannes Berg04a773a2009-04-19 21:24:32 +02006489 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6490 return -EINVAL;
6491
Johannes Berg683b6d32012-11-08 21:25:48 +01006492 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006493 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6494 return -EINVAL;
6495
Johannes Berg8e30bc52009-04-22 17:45:38 +02006496 ibss.beacon_interval = 100;
6497
6498 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6499 ibss.beacon_interval =
6500 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6501 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6502 return -EINVAL;
6503 }
6504
Johannes Berg4c476992010-10-04 21:36:35 +02006505 if (!rdev->ops->join_ibss)
6506 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006507
Johannes Berg4c476992010-10-04 21:36:35 +02006508 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6509 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006510
Johannes Berg79c97e92009-07-07 03:56:12 +02006511 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006512
Johannes Berg39193492011-09-16 13:45:25 +02006513 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006514 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006515
6516 if (!is_valid_ether_addr(ibss.bssid))
6517 return -EINVAL;
6518 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006519 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6520 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6521
6522 if (info->attrs[NL80211_ATTR_IE]) {
6523 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6524 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6525 }
6526
Johannes Berg683b6d32012-11-08 21:25:48 +01006527 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6528 if (err)
6529 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006530
Johannes Berg683b6d32012-11-08 21:25:48 +01006531 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006532 return -EINVAL;
6533
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006534 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006535 case NL80211_CHAN_WIDTH_5:
6536 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006537 case NL80211_CHAN_WIDTH_20_NOHT:
6538 break;
6539 case NL80211_CHAN_WIDTH_20:
6540 case NL80211_CHAN_WIDTH_40:
6541 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6542 break;
6543 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006544 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006545 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006546
Johannes Berg04a773a2009-04-19 21:24:32 +02006547 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006548 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006549
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006550 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6551 u8 *rates =
6552 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6553 int n_rates =
6554 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6555 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006556 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006557
Johannes Berg34850ab2011-07-18 18:08:35 +02006558 err = ieee80211_get_ratemask(sband, rates, n_rates,
6559 &ibss.basic_rates);
6560 if (err)
6561 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006562 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006563
Simon Wunderlich803768f2013-06-28 10:39:58 +02006564 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6565 memcpy(&ibss.ht_capa_mask,
6566 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6567 sizeof(ibss.ht_capa_mask));
6568
6569 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6570 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6571 return -EINVAL;
6572 memcpy(&ibss.ht_capa,
6573 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6574 sizeof(ibss.ht_capa));
6575 }
6576
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006577 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6578 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6579 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6580 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006581
Johannes Berg4c476992010-10-04 21:36:35 +02006582 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306583 bool no_ht = false;
6584
Johannes Berg4c476992010-10-04 21:36:35 +02006585 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306586 info->attrs[NL80211_ATTR_KEYS],
6587 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006588 if (IS_ERR(connkeys))
6589 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306590
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006591 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6592 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306593 kfree(connkeys);
6594 return -EINVAL;
6595 }
Johannes Berg4c476992010-10-04 21:36:35 +02006596 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006597
Antonio Quartulli267335d2012-01-31 20:25:47 +01006598 ibss.control_port =
6599 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6600
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006601 ibss.userspace_handles_dfs =
6602 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6603
Johannes Berg4c476992010-10-04 21:36:35 +02006604 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006605 if (err)
6606 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006607 return err;
6608}
6609
6610static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6611{
Johannes Berg4c476992010-10-04 21:36:35 +02006612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6613 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006614
Johannes Berg4c476992010-10-04 21:36:35 +02006615 if (!rdev->ops->leave_ibss)
6616 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006617
Johannes Berg4c476992010-10-04 21:36:35 +02006618 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6619 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006620
Johannes Berg4c476992010-10-04 21:36:35 +02006621 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006622}
6623
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006624static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6625{
6626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6627 struct net_device *dev = info->user_ptr[1];
6628 int mcast_rate[IEEE80211_NUM_BANDS];
6629 u32 nla_rate;
6630 int err;
6631
6632 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6633 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6634 return -EOPNOTSUPP;
6635
6636 if (!rdev->ops->set_mcast_rate)
6637 return -EOPNOTSUPP;
6638
6639 memset(mcast_rate, 0, sizeof(mcast_rate));
6640
6641 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6642 return -EINVAL;
6643
6644 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6645 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6646 return -EINVAL;
6647
6648 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6649
6650 return err;
6651}
6652
6653
Johannes Bergaff89a92009-07-01 21:26:51 +02006654#ifdef CONFIG_NL80211_TESTMODE
6655static struct genl_multicast_group nl80211_testmode_mcgrp = {
6656 .name = "testmode",
6657};
6658
6659static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6660{
Johannes Berg4c476992010-10-04 21:36:35 +02006661 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006662 struct wireless_dev *wdev =
6663 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006664 int err;
6665
David Spinadelfc73f112013-07-31 18:04:15 +03006666 if (!rdev->ops->testmode_cmd)
6667 return -EOPNOTSUPP;
6668
6669 if (IS_ERR(wdev)) {
6670 err = PTR_ERR(wdev);
6671 if (err != -EINVAL)
6672 return err;
6673 wdev = NULL;
6674 } else if (wdev->wiphy != &rdev->wiphy) {
6675 return -EINVAL;
6676 }
6677
Johannes Bergaff89a92009-07-01 21:26:51 +02006678 if (!info->attrs[NL80211_ATTR_TESTDATA])
6679 return -EINVAL;
6680
David Spinadelfc73f112013-07-31 18:04:15 +03006681 rdev->testmode_info = info;
6682 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006683 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6684 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
David Spinadelfc73f112013-07-31 18:04:15 +03006685 rdev->testmode_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006686
Johannes Bergaff89a92009-07-01 21:26:51 +02006687 return err;
6688}
6689
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006690static int nl80211_testmode_dump(struct sk_buff *skb,
6691 struct netlink_callback *cb)
6692{
Johannes Berg00918d32011-12-13 17:22:05 +01006693 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006694 int err;
6695 long phy_idx;
6696 void *data = NULL;
6697 int data_len = 0;
6698
Johannes Berg5fe231e2013-05-08 21:45:15 +02006699 rtnl_lock();
6700
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006701 if (cb->args[0]) {
6702 /*
6703 * 0 is a valid index, but not valid for args[0],
6704 * so we need to offset by 1.
6705 */
6706 phy_idx = cb->args[0] - 1;
6707 } else {
6708 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6709 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6710 nl80211_policy);
6711 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006712 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006713
Johannes Berg2bd7e352012-06-15 14:23:16 +02006714 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6715 nl80211_fam.attrbuf);
6716 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006717 err = PTR_ERR(rdev);
6718 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006719 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006720 phy_idx = rdev->wiphy_idx;
6721 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006722
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006723 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6724 cb->args[1] =
6725 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6726 }
6727
6728 if (cb->args[1]) {
6729 data = nla_data((void *)cb->args[1]);
6730 data_len = nla_len((void *)cb->args[1]);
6731 }
6732
Johannes Berg00918d32011-12-13 17:22:05 +01006733 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6734 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006735 err = -ENOENT;
6736 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006737 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006738
Johannes Berg00918d32011-12-13 17:22:05 +01006739 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006740 err = -EOPNOTSUPP;
6741 goto out_err;
6742 }
6743
6744 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006745 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006746 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6747 NL80211_CMD_TESTMODE);
6748 struct nlattr *tmdata;
6749
Dan Carpentercb35fba2013-08-14 14:50:01 +03006750 if (!hdr)
6751 break;
6752
David S. Miller9360ffd2012-03-29 04:41:26 -04006753 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006754 genlmsg_cancel(skb, hdr);
6755 break;
6756 }
6757
6758 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6759 if (!tmdata) {
6760 genlmsg_cancel(skb, hdr);
6761 break;
6762 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006763 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006764 nla_nest_end(skb, tmdata);
6765
6766 if (err == -ENOBUFS || err == -ENOENT) {
6767 genlmsg_cancel(skb, hdr);
6768 break;
6769 } else if (err) {
6770 genlmsg_cancel(skb, hdr);
6771 goto out_err;
6772 }
6773
6774 genlmsg_end(skb, hdr);
6775 }
6776
6777 err = skb->len;
6778 /* see above */
6779 cb->args[0] = phy_idx + 1;
6780 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006781 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006782 return err;
6783}
6784
Johannes Bergaff89a92009-07-01 21:26:51 +02006785static struct sk_buff *
6786__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006787 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006788{
6789 struct sk_buff *skb;
6790 void *hdr;
6791 struct nlattr *data;
6792
6793 skb = nlmsg_new(approxlen + 100, gfp);
6794 if (!skb)
6795 return NULL;
6796
Eric W. Biederman15e47302012-09-07 20:12:54 +00006797 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006798 if (!hdr) {
6799 kfree_skb(skb);
6800 return NULL;
6801 }
6802
David S. Miller9360ffd2012-03-29 04:41:26 -04006803 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6804 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006805 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6806
6807 ((void **)skb->cb)[0] = rdev;
6808 ((void **)skb->cb)[1] = hdr;
6809 ((void **)skb->cb)[2] = data;
6810
6811 return skb;
6812
6813 nla_put_failure:
6814 kfree_skb(skb);
6815 return NULL;
6816}
6817
6818struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6819 int approxlen)
6820{
6821 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6822
6823 if (WARN_ON(!rdev->testmode_info))
6824 return NULL;
6825
6826 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006827 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006828 rdev->testmode_info->snd_seq,
6829 GFP_KERNEL);
6830}
6831EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6832
6833int cfg80211_testmode_reply(struct sk_buff *skb)
6834{
6835 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6836 void *hdr = ((void **)skb->cb)[1];
6837 struct nlattr *data = ((void **)skb->cb)[2];
6838
6839 if (WARN_ON(!rdev->testmode_info)) {
6840 kfree_skb(skb);
6841 return -EINVAL;
6842 }
6843
6844 nla_nest_end(skb, data);
6845 genlmsg_end(skb, hdr);
6846 return genlmsg_reply(skb, rdev->testmode_info);
6847}
6848EXPORT_SYMBOL(cfg80211_testmode_reply);
6849
6850struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6851 int approxlen, gfp_t gfp)
6852{
6853 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6854
6855 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6856}
6857EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6858
6859void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6860{
Michal Kaziora0ec5702013-06-25 09:17:17 +02006861 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006862 void *hdr = ((void **)skb->cb)[1];
6863 struct nlattr *data = ((void **)skb->cb)[2];
6864
6865 nla_nest_end(skb, data);
6866 genlmsg_end(skb, hdr);
Michal Kaziora0ec5702013-06-25 09:17:17 +02006867 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
6868 nl80211_testmode_mcgrp.id, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006869}
6870EXPORT_SYMBOL(cfg80211_testmode_event);
6871#endif
6872
Samuel Ortizb23aa672009-07-01 21:26:54 +02006873static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6874{
Johannes Berg4c476992010-10-04 21:36:35 +02006875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6876 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006877 struct cfg80211_connect_params connect;
6878 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006879 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006880 int err;
6881
6882 memset(&connect, 0, sizeof(connect));
6883
6884 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6885 return -EINVAL;
6886
6887 if (!info->attrs[NL80211_ATTR_SSID] ||
6888 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6889 return -EINVAL;
6890
6891 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6892 connect.auth_type =
6893 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006894 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6895 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006896 return -EINVAL;
6897 } else
6898 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6899
6900 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6901
Johannes Bergc0692b82010-08-27 14:26:53 +03006902 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006903 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006904 if (err)
6905 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006906
Johannes Berg074ac8d2010-09-16 14:58:22 +02006907 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006908 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6909 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006910
Johannes Berg79c97e92009-07-07 03:56:12 +02006911 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006912
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306913 connect.bg_scan_period = -1;
6914 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6915 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6916 connect.bg_scan_period =
6917 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6918 }
6919
Samuel Ortizb23aa672009-07-01 21:26:54 +02006920 if (info->attrs[NL80211_ATTR_MAC])
6921 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6922 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6923 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6924
6925 if (info->attrs[NL80211_ATTR_IE]) {
6926 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6927 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6928 }
6929
Jouni Malinencee00a92013-01-15 17:15:57 +02006930 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6931 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6932 if (connect.mfp != NL80211_MFP_REQUIRED &&
6933 connect.mfp != NL80211_MFP_NO)
6934 return -EINVAL;
6935 } else {
6936 connect.mfp = NL80211_MFP_NO;
6937 }
6938
Samuel Ortizb23aa672009-07-01 21:26:54 +02006939 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6940 connect.channel =
6941 ieee80211_get_channel(wiphy,
6942 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6943 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006944 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6945 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006946 }
6947
Johannes Bergfffd0932009-07-08 14:22:54 +02006948 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6949 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306950 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006951 if (IS_ERR(connkeys))
6952 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006953 }
6954
Ben Greear7e7c8922011-11-18 11:31:59 -08006955 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6956 connect.flags |= ASSOC_REQ_DISABLE_HT;
6957
6958 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6959 memcpy(&connect.ht_capa_mask,
6960 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6961 sizeof(connect.ht_capa_mask));
6962
6963 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006964 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6965 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006966 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006967 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006968 memcpy(&connect.ht_capa,
6969 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6970 sizeof(connect.ht_capa));
6971 }
6972
Johannes Bergee2aca32013-02-21 17:36:01 +01006973 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6974 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6975
6976 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6977 memcpy(&connect.vht_capa_mask,
6978 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6979 sizeof(connect.vht_capa_mask));
6980
6981 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6982 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6983 kfree(connkeys);
6984 return -EINVAL;
6985 }
6986 memcpy(&connect.vht_capa,
6987 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6988 sizeof(connect.vht_capa));
6989 }
6990
Johannes Berg83739b02013-05-15 17:44:01 +02006991 wdev_lock(dev->ieee80211_ptr);
6992 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6993 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006994 if (err)
6995 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006996 return err;
6997}
6998
6999static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7000{
Johannes Berg4c476992010-10-04 21:36:35 +02007001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7002 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007003 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007004 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007005
7006 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7007 reason = WLAN_REASON_DEAUTH_LEAVING;
7008 else
7009 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7010
7011 if (reason == 0)
7012 return -EINVAL;
7013
Johannes Berg074ac8d2010-09-16 14:58:22 +02007014 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007015 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7016 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007017
Johannes Berg83739b02013-05-15 17:44:01 +02007018 wdev_lock(dev->ieee80211_ptr);
7019 ret = cfg80211_disconnect(rdev, dev, reason, true);
7020 wdev_unlock(dev->ieee80211_ptr);
7021 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007022}
7023
Johannes Berg463d0182009-07-14 00:33:35 +02007024static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7025{
Johannes Berg4c476992010-10-04 21:36:35 +02007026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007027 struct net *net;
7028 int err;
7029 u32 pid;
7030
7031 if (!info->attrs[NL80211_ATTR_PID])
7032 return -EINVAL;
7033
7034 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7035
Johannes Berg463d0182009-07-14 00:33:35 +02007036 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007037 if (IS_ERR(net))
7038 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007039
7040 err = 0;
7041
7042 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007043 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7044 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007045
Johannes Berg463d0182009-07-14 00:33:35 +02007046 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007047 return err;
7048}
7049
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007050static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7051{
Johannes Berg4c476992010-10-04 21:36:35 +02007052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007053 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7054 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007055 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007056 struct cfg80211_pmksa pmksa;
7057
7058 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7059
7060 if (!info->attrs[NL80211_ATTR_MAC])
7061 return -EINVAL;
7062
7063 if (!info->attrs[NL80211_ATTR_PMKID])
7064 return -EINVAL;
7065
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007066 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7067 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7068
Johannes Berg074ac8d2010-09-16 14:58:22 +02007069 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007070 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7071 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007072
7073 switch (info->genlhdr->cmd) {
7074 case NL80211_CMD_SET_PMKSA:
7075 rdev_ops = rdev->ops->set_pmksa;
7076 break;
7077 case NL80211_CMD_DEL_PMKSA:
7078 rdev_ops = rdev->ops->del_pmksa;
7079 break;
7080 default:
7081 WARN_ON(1);
7082 break;
7083 }
7084
Johannes Berg4c476992010-10-04 21:36:35 +02007085 if (!rdev_ops)
7086 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007087
Johannes Berg4c476992010-10-04 21:36:35 +02007088 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007089}
7090
7091static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7092{
Johannes Berg4c476992010-10-04 21:36:35 +02007093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7094 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007095
Johannes Berg074ac8d2010-09-16 14:58:22 +02007096 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007097 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7098 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007099
Johannes Berg4c476992010-10-04 21:36:35 +02007100 if (!rdev->ops->flush_pmksa)
7101 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007102
Hila Gonene35e4d22012-06-27 17:19:42 +03007103 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007104}
7105
Arik Nemtsov109086c2011-09-28 14:12:50 +03007106static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7107{
7108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7109 struct net_device *dev = info->user_ptr[1];
7110 u8 action_code, dialog_token;
7111 u16 status_code;
7112 u8 *peer;
7113
7114 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7115 !rdev->ops->tdls_mgmt)
7116 return -EOPNOTSUPP;
7117
7118 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7119 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7120 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7121 !info->attrs[NL80211_ATTR_IE] ||
7122 !info->attrs[NL80211_ATTR_MAC])
7123 return -EINVAL;
7124
7125 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7126 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7127 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7128 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7129
Hila Gonene35e4d22012-06-27 17:19:42 +03007130 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7131 dialog_token, status_code,
7132 nla_data(info->attrs[NL80211_ATTR_IE]),
7133 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007134}
7135
7136static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7137{
7138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7139 struct net_device *dev = info->user_ptr[1];
7140 enum nl80211_tdls_operation operation;
7141 u8 *peer;
7142
7143 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7144 !rdev->ops->tdls_oper)
7145 return -EOPNOTSUPP;
7146
7147 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7148 !info->attrs[NL80211_ATTR_MAC])
7149 return -EINVAL;
7150
7151 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7152 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7153
Hila Gonene35e4d22012-06-27 17:19:42 +03007154 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007155}
7156
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007157static int nl80211_remain_on_channel(struct sk_buff *skb,
7158 struct genl_info *info)
7159{
Johannes Berg4c476992010-10-04 21:36:35 +02007160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007161 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007162 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007163 struct sk_buff *msg;
7164 void *hdr;
7165 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007166 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007167 int err;
7168
7169 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7170 !info->attrs[NL80211_ATTR_DURATION])
7171 return -EINVAL;
7172
7173 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7174
Johannes Berg7c4ef712011-11-18 15:33:48 +01007175 if (!rdev->ops->remain_on_channel ||
7176 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007177 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007178
Johannes Bergebf348f2012-06-01 12:50:54 +02007179 /*
7180 * We should be on that channel for at least a minimum amount of
7181 * time (10ms) but no longer than the driver supports.
7182 */
7183 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7184 duration > rdev->wiphy.max_remain_on_channel_duration)
7185 return -EINVAL;
7186
Johannes Berg683b6d32012-11-08 21:25:48 +01007187 err = nl80211_parse_chandef(rdev, info, &chandef);
7188 if (err)
7189 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007190
7191 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007192 if (!msg)
7193 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007194
Eric W. Biederman15e47302012-09-07 20:12:54 +00007195 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007196 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007197 if (!hdr) {
7198 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007199 goto free_msg;
7200 }
7201
Johannes Berg683b6d32012-11-08 21:25:48 +01007202 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7203 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007204
7205 if (err)
7206 goto free_msg;
7207
David S. Miller9360ffd2012-03-29 04:41:26 -04007208 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7209 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007210
7211 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007212
7213 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007214
7215 nla_put_failure:
7216 err = -ENOBUFS;
7217 free_msg:
7218 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007219 return err;
7220}
7221
7222static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7223 struct genl_info *info)
7224{
Johannes Berg4c476992010-10-04 21:36:35 +02007225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007226 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007227 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007228
7229 if (!info->attrs[NL80211_ATTR_COOKIE])
7230 return -EINVAL;
7231
Johannes Berg4c476992010-10-04 21:36:35 +02007232 if (!rdev->ops->cancel_remain_on_channel)
7233 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007234
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007235 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7236
Hila Gonene35e4d22012-06-27 17:19:42 +03007237 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007238}
7239
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007240static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7241 u8 *rates, u8 rates_len)
7242{
7243 u8 i;
7244 u32 mask = 0;
7245
7246 for (i = 0; i < rates_len; i++) {
7247 int rate = (rates[i] & 0x7f) * 5;
7248 int ridx;
7249 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7250 struct ieee80211_rate *srate =
7251 &sband->bitrates[ridx];
7252 if (rate == srate->bitrate) {
7253 mask |= 1 << ridx;
7254 break;
7255 }
7256 }
7257 if (ridx == sband->n_bitrates)
7258 return 0; /* rate not found */
7259 }
7260
7261 return mask;
7262}
7263
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007264static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7265 u8 *rates, u8 rates_len,
7266 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7267{
7268 u8 i;
7269
7270 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7271
7272 for (i = 0; i < rates_len; i++) {
7273 int ridx, rbit;
7274
7275 ridx = rates[i] / 8;
7276 rbit = BIT(rates[i] % 8);
7277
7278 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007279 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007280 return false;
7281
7282 /* check availability */
7283 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7284 mcs[ridx] |= rbit;
7285 else
7286 return false;
7287 }
7288
7289 return true;
7290}
7291
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007292static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007293 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7294 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007295 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7296 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007297};
7298
7299static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7300 struct genl_info *info)
7301{
7302 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007304 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007305 int rem, i;
7306 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007307 struct nlattr *tx_rates;
7308 struct ieee80211_supported_band *sband;
7309
7310 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7311 return -EINVAL;
7312
Johannes Berg4c476992010-10-04 21:36:35 +02007313 if (!rdev->ops->set_bitrate_mask)
7314 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007315
7316 memset(&mask, 0, sizeof(mask));
7317 /* Default to all rates enabled */
7318 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7319 sband = rdev->wiphy.bands[i];
7320 mask.control[i].legacy =
7321 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007322 if (sband)
7323 memcpy(mask.control[i].mcs,
7324 sband->ht_cap.mcs.rx_mask,
7325 sizeof(mask.control[i].mcs));
7326 else
7327 memset(mask.control[i].mcs, 0,
7328 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007329 }
7330
7331 /*
7332 * The nested attribute uses enum nl80211_band as the index. This maps
7333 * directly to the enum ieee80211_band values used in cfg80211.
7334 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007335 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007336 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7337 {
7338 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007339 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7340 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007341 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007342 if (sband == NULL)
7343 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007344 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7345 nla_len(tx_rates), nl80211_txattr_policy);
7346 if (tb[NL80211_TXRATE_LEGACY]) {
7347 mask.control[band].legacy = rateset_to_mask(
7348 sband,
7349 nla_data(tb[NL80211_TXRATE_LEGACY]),
7350 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307351 if ((mask.control[band].legacy == 0) &&
7352 nla_len(tb[NL80211_TXRATE_LEGACY]))
7353 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007354 }
7355 if (tb[NL80211_TXRATE_MCS]) {
7356 if (!ht_rateset_to_mask(
7357 sband,
7358 nla_data(tb[NL80211_TXRATE_MCS]),
7359 nla_len(tb[NL80211_TXRATE_MCS]),
7360 mask.control[band].mcs))
7361 return -EINVAL;
7362 }
7363
7364 if (mask.control[band].legacy == 0) {
7365 /* don't allow empty legacy rates if HT
7366 * is not even supported. */
7367 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7368 return -EINVAL;
7369
7370 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7371 if (mask.control[band].mcs[i])
7372 break;
7373
7374 /* legacy and mcs rates may not be both empty */
7375 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007376 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007377 }
7378 }
7379
Hila Gonene35e4d22012-06-27 17:19:42 +03007380 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007381}
7382
Johannes Berg2e161f72010-08-12 15:38:38 +02007383static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007384{
Johannes Berg4c476992010-10-04 21:36:35 +02007385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007386 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007387 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007388
7389 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7390 return -EINVAL;
7391
Johannes Berg2e161f72010-08-12 15:38:38 +02007392 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7393 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007394
Johannes Berg71bbc992012-06-15 15:30:18 +02007395 switch (wdev->iftype) {
7396 case NL80211_IFTYPE_STATION:
7397 case NL80211_IFTYPE_ADHOC:
7398 case NL80211_IFTYPE_P2P_CLIENT:
7399 case NL80211_IFTYPE_AP:
7400 case NL80211_IFTYPE_AP_VLAN:
7401 case NL80211_IFTYPE_MESH_POINT:
7402 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007403 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007404 break;
7405 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007406 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007407 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007408
7409 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007410 if (!rdev->ops->mgmt_tx)
7411 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007412
Eric W. Biederman15e47302012-09-07 20:12:54 +00007413 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007414 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7415 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007416}
7417
Johannes Berg2e161f72010-08-12 15:38:38 +02007418static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007419{
Johannes Berg4c476992010-10-04 21:36:35 +02007420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007421 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007422 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007423 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007424 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007425 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007426 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007427 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007428 bool offchan, no_cck, dont_wait_for_ack;
7429
7430 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007431
Johannes Berg683b6d32012-11-08 21:25:48 +01007432 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007433 return -EINVAL;
7434
Johannes Berg4c476992010-10-04 21:36:35 +02007435 if (!rdev->ops->mgmt_tx)
7436 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007437
Johannes Berg71bbc992012-06-15 15:30:18 +02007438 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007439 case NL80211_IFTYPE_P2P_DEVICE:
7440 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7441 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007442 case NL80211_IFTYPE_STATION:
7443 case NL80211_IFTYPE_ADHOC:
7444 case NL80211_IFTYPE_P2P_CLIENT:
7445 case NL80211_IFTYPE_AP:
7446 case NL80211_IFTYPE_AP_VLAN:
7447 case NL80211_IFTYPE_MESH_POINT:
7448 case NL80211_IFTYPE_P2P_GO:
7449 break;
7450 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007451 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007452 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007453
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007454 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007455 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007456 return -EINVAL;
7457 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007458
7459 /*
7460 * We should wait on the channel for at least a minimum amount
7461 * of time (10ms) but no longer than the driver supports.
7462 */
7463 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7464 wait > rdev->wiphy.max_remain_on_channel_duration)
7465 return -EINVAL;
7466
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007467 }
7468
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007469 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7470
Johannes Berg7c4ef712011-11-18 15:33:48 +01007471 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7472 return -EINVAL;
7473
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307474 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7475
Antonio Quartulliea141b752013-06-11 14:20:03 +02007476 /* get the channel if any has been specified, otherwise pass NULL to
7477 * the driver. The latter will use the current one
7478 */
7479 chandef.chan = NULL;
7480 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7481 err = nl80211_parse_chandef(rdev, info, &chandef);
7482 if (err)
7483 return err;
7484 }
7485
7486 if (!chandef.chan && offchan)
7487 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007488
Johannes Berge247bd902011-11-04 11:18:21 +01007489 if (!dont_wait_for_ack) {
7490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7491 if (!msg)
7492 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007493
Eric W. Biederman15e47302012-09-07 20:12:54 +00007494 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007495 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007496 if (!hdr) {
7497 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007498 goto free_msg;
7499 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007500 }
Johannes Berge247bd902011-11-04 11:18:21 +01007501
Johannes Berg683b6d32012-11-08 21:25:48 +01007502 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007503 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7504 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007505 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007506 if (err)
7507 goto free_msg;
7508
Johannes Berge247bd902011-11-04 11:18:21 +01007509 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007510 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7511 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007512
Johannes Berge247bd902011-11-04 11:18:21 +01007513 genlmsg_end(msg, hdr);
7514 return genlmsg_reply(msg, info);
7515 }
7516
7517 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007518
7519 nla_put_failure:
7520 err = -ENOBUFS;
7521 free_msg:
7522 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007523 return err;
7524}
7525
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007526static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7527{
7528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007529 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007530 u64 cookie;
7531
7532 if (!info->attrs[NL80211_ATTR_COOKIE])
7533 return -EINVAL;
7534
7535 if (!rdev->ops->mgmt_tx_cancel_wait)
7536 return -EOPNOTSUPP;
7537
Johannes Berg71bbc992012-06-15 15:30:18 +02007538 switch (wdev->iftype) {
7539 case NL80211_IFTYPE_STATION:
7540 case NL80211_IFTYPE_ADHOC:
7541 case NL80211_IFTYPE_P2P_CLIENT:
7542 case NL80211_IFTYPE_AP:
7543 case NL80211_IFTYPE_AP_VLAN:
7544 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007545 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007546 break;
7547 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007548 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007549 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007550
7551 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7552
Hila Gonene35e4d22012-06-27 17:19:42 +03007553 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007554}
7555
Kalle Valoffb9eb32010-02-17 17:58:10 +02007556static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7557{
Johannes Berg4c476992010-10-04 21:36:35 +02007558 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007559 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007560 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007561 u8 ps_state;
7562 bool state;
7563 int err;
7564
Johannes Berg4c476992010-10-04 21:36:35 +02007565 if (!info->attrs[NL80211_ATTR_PS_STATE])
7566 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007567
7568 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7569
Johannes Berg4c476992010-10-04 21:36:35 +02007570 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7571 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007572
7573 wdev = dev->ieee80211_ptr;
7574
Johannes Berg4c476992010-10-04 21:36:35 +02007575 if (!rdev->ops->set_power_mgmt)
7576 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007577
7578 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7579
7580 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007581 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007582
Hila Gonene35e4d22012-06-27 17:19:42 +03007583 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007584 if (!err)
7585 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007586 return err;
7587}
7588
7589static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7590{
Johannes Berg4c476992010-10-04 21:36:35 +02007591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007592 enum nl80211_ps_state ps_state;
7593 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007594 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007595 struct sk_buff *msg;
7596 void *hdr;
7597 int err;
7598
Kalle Valoffb9eb32010-02-17 17:58:10 +02007599 wdev = dev->ieee80211_ptr;
7600
Johannes Berg4c476992010-10-04 21:36:35 +02007601 if (!rdev->ops->set_power_mgmt)
7602 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007603
7604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007605 if (!msg)
7606 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007607
Eric W. Biederman15e47302012-09-07 20:12:54 +00007608 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007609 NL80211_CMD_GET_POWER_SAVE);
7610 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007611 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007612 goto free_msg;
7613 }
7614
7615 if (wdev->ps)
7616 ps_state = NL80211_PS_ENABLED;
7617 else
7618 ps_state = NL80211_PS_DISABLED;
7619
David S. Miller9360ffd2012-03-29 04:41:26 -04007620 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7621 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007622
7623 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007624 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007625
Johannes Berg4c476992010-10-04 21:36:35 +02007626 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007627 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007628 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007629 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007630 return err;
7631}
7632
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007633static struct nla_policy
7634nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7635 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7636 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7637 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007638 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7639 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7640 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007641};
7642
Thomas Pedersen84f10702012-07-12 16:17:33 -07007643static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007644 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007645{
7646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007647 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007648 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007649
Johannes Bergd9d8b012012-11-26 12:51:52 +01007650 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007651 return -EINVAL;
7652
Thomas Pedersen84f10702012-07-12 16:17:33 -07007653 if (!rdev->ops->set_cqm_txe_config)
7654 return -EOPNOTSUPP;
7655
7656 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7657 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7658 return -EOPNOTSUPP;
7659
Hila Gonene35e4d22012-06-27 17:19:42 +03007660 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007661}
7662
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007663static int nl80211_set_cqm_rssi(struct genl_info *info,
7664 s32 threshold, u32 hysteresis)
7665{
Johannes Berg4c476992010-10-04 21:36:35 +02007666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007667 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007668 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007669
7670 if (threshold > 0)
7671 return -EINVAL;
7672
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007673 /* disabling - hysteresis should also be zero then */
7674 if (threshold == 0)
7675 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007676
Johannes Berg4c476992010-10-04 21:36:35 +02007677 if (!rdev->ops->set_cqm_rssi_config)
7678 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007679
Johannes Berg074ac8d2010-09-16 14:58:22 +02007680 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007681 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7682 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007683
Hila Gonene35e4d22012-06-27 17:19:42 +03007684 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007685}
7686
7687static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7688{
7689 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7690 struct nlattr *cqm;
7691 int err;
7692
7693 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007694 if (!cqm)
7695 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007696
7697 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7698 nl80211_attr_cqm_policy);
7699 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007700 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007701
7702 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7703 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007704 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7705 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007706
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007707 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7708 }
7709
7710 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7711 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7712 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7713 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7714 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7715 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7716
7717 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7718 }
7719
7720 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007721}
7722
Johannes Berg29cbe682010-12-03 09:20:44 +01007723static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7724{
7725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7726 struct net_device *dev = info->user_ptr[1];
7727 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007728 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007729 int err;
7730
7731 /* start with default */
7732 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007733 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007734
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007735 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007736 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007737 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007738 if (err)
7739 return err;
7740 }
7741
7742 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7743 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7744 return -EINVAL;
7745
Javier Cardonac80d5452010-12-16 17:37:49 -08007746 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7747 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7748
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007749 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7750 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7751 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7752 return -EINVAL;
7753
Marco Porsch9bdbf042013-01-07 16:04:51 +01007754 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7755 setup.beacon_interval =
7756 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7757 if (setup.beacon_interval < 10 ||
7758 setup.beacon_interval > 10000)
7759 return -EINVAL;
7760 }
7761
7762 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7763 setup.dtim_period =
7764 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7765 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7766 return -EINVAL;
7767 }
7768
Javier Cardonac80d5452010-12-16 17:37:49 -08007769 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7770 /* parse additional setup parameters if given */
7771 err = nl80211_parse_mesh_setup(info, &setup);
7772 if (err)
7773 return err;
7774 }
7775
Thomas Pedersend37bb182013-03-04 13:06:13 -08007776 if (setup.user_mpm)
7777 cfg.auto_open_plinks = false;
7778
Johannes Bergcc1d2802012-05-16 23:50:20 +02007779 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007780 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7781 if (err)
7782 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007783 } else {
7784 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007785 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007786 }
7787
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007788 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7789 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7790 int n_rates =
7791 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7792 struct ieee80211_supported_band *sband;
7793
7794 if (!setup.chandef.chan)
7795 return -EINVAL;
7796
7797 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7798
7799 err = ieee80211_get_ratemask(sband, rates, n_rates,
7800 &setup.basic_rates);
7801 if (err)
7802 return err;
7803 }
7804
Javier Cardonac80d5452010-12-16 17:37:49 -08007805 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007806}
7807
7808static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7809{
7810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7811 struct net_device *dev = info->user_ptr[1];
7812
7813 return cfg80211_leave_mesh(rdev, dev);
7814}
7815
Johannes Bergdfb89c52012-06-27 09:23:48 +02007816#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007817static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7818 struct cfg80211_registered_device *rdev)
7819{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007820 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007821 struct nlattr *nl_pats, *nl_pat;
7822 int i, pat_len;
7823
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007824 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007825 return 0;
7826
7827 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7828 if (!nl_pats)
7829 return -ENOBUFS;
7830
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007831 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007832 nl_pat = nla_nest_start(msg, i + 1);
7833 if (!nl_pat)
7834 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007835 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007836 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007837 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007838 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7839 wowlan->patterns[i].pattern) ||
7840 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007841 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007842 return -ENOBUFS;
7843 nla_nest_end(msg, nl_pat);
7844 }
7845 nla_nest_end(msg, nl_pats);
7846
7847 return 0;
7848}
7849
Johannes Berg2a0e0472013-01-23 22:57:40 +01007850static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7851 struct cfg80211_wowlan_tcp *tcp)
7852{
7853 struct nlattr *nl_tcp;
7854
7855 if (!tcp)
7856 return 0;
7857
7858 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7859 if (!nl_tcp)
7860 return -ENOBUFS;
7861
7862 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7863 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7864 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7865 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7866 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7867 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7868 tcp->payload_len, tcp->payload) ||
7869 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7870 tcp->data_interval) ||
7871 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7872 tcp->wake_len, tcp->wake_data) ||
7873 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7874 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7875 return -ENOBUFS;
7876
7877 if (tcp->payload_seq.len &&
7878 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7879 sizeof(tcp->payload_seq), &tcp->payload_seq))
7880 return -ENOBUFS;
7881
7882 if (tcp->payload_tok.len &&
7883 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7884 sizeof(tcp->payload_tok) + tcp->tokens_size,
7885 &tcp->payload_tok))
7886 return -ENOBUFS;
7887
Johannes Berge248ad32013-05-16 10:24:28 +02007888 nla_nest_end(msg, nl_tcp);
7889
Johannes Berg2a0e0472013-01-23 22:57:40 +01007890 return 0;
7891}
7892
Johannes Bergff1b6e62011-05-04 15:37:28 +02007893static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7894{
7895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7896 struct sk_buff *msg;
7897 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007898 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007899
Johannes Berg964dc9e2013-06-03 17:25:34 +02007900 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007901 return -EOPNOTSUPP;
7902
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007903 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007904 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007905 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7906 rdev->wiphy.wowlan_config->tcp->payload_len +
7907 rdev->wiphy.wowlan_config->tcp->wake_len +
7908 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007909 }
7910
7911 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007912 if (!msg)
7913 return -ENOMEM;
7914
Eric W. Biederman15e47302012-09-07 20:12:54 +00007915 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007916 NL80211_CMD_GET_WOWLAN);
7917 if (!hdr)
7918 goto nla_put_failure;
7919
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007920 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007921 struct nlattr *nl_wowlan;
7922
7923 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7924 if (!nl_wowlan)
7925 goto nla_put_failure;
7926
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007927 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007928 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007929 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007930 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007931 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007932 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007933 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007934 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007935 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007936 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007937 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007938 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007939 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007940 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7941 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007942
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007943 if (nl80211_send_wowlan_patterns(msg, rdev))
7944 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007945
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007946 if (nl80211_send_wowlan_tcp(msg,
7947 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007948 goto nla_put_failure;
7949
Johannes Bergff1b6e62011-05-04 15:37:28 +02007950 nla_nest_end(msg, nl_wowlan);
7951 }
7952
7953 genlmsg_end(msg, hdr);
7954 return genlmsg_reply(msg, info);
7955
7956nla_put_failure:
7957 nlmsg_free(msg);
7958 return -ENOBUFS;
7959}
7960
Johannes Berg2a0e0472013-01-23 22:57:40 +01007961static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7962 struct nlattr *attr,
7963 struct cfg80211_wowlan *trig)
7964{
7965 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7966 struct cfg80211_wowlan_tcp *cfg;
7967 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7968 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7969 u32 size;
7970 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7971 int err, port;
7972
Johannes Berg964dc9e2013-06-03 17:25:34 +02007973 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007974 return -EINVAL;
7975
7976 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7977 nla_data(attr), nla_len(attr),
7978 nl80211_wowlan_tcp_policy);
7979 if (err)
7980 return err;
7981
7982 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7983 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7984 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7985 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7986 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7987 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7988 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7989 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7990 return -EINVAL;
7991
7992 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007993 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007994 return -EINVAL;
7995
7996 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007997 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007998 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007999 return -EINVAL;
8000
8001 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008002 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008003 return -EINVAL;
8004
8005 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8006 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8007 return -EINVAL;
8008
8009 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8010 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8011
8012 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8013 tokens_size = tokln - sizeof(*tok);
8014
8015 if (!tok->len || tokens_size % tok->len)
8016 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008017 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008018 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008019 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008020 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008021 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008022 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008023 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008024 return -EINVAL;
8025 if (tok->offset + tok->len > data_size)
8026 return -EINVAL;
8027 }
8028
8029 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8030 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008031 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008032 return -EINVAL;
8033 if (seq->len == 0 || seq->len > 4)
8034 return -EINVAL;
8035 if (seq->len + seq->offset > data_size)
8036 return -EINVAL;
8037 }
8038
8039 size = sizeof(*cfg);
8040 size += data_size;
8041 size += wake_size + wake_mask_size;
8042 size += tokens_size;
8043
8044 cfg = kzalloc(size, GFP_KERNEL);
8045 if (!cfg)
8046 return -ENOMEM;
8047 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8048 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8049 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8050 ETH_ALEN);
8051 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8052 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8053 else
8054 port = 0;
8055#ifdef CONFIG_INET
8056 /* allocate a socket and port for it and use it */
8057 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8058 IPPROTO_TCP, &cfg->sock, 1);
8059 if (err) {
8060 kfree(cfg);
8061 return err;
8062 }
8063 if (inet_csk_get_port(cfg->sock->sk, port)) {
8064 sock_release(cfg->sock);
8065 kfree(cfg);
8066 return -EADDRINUSE;
8067 }
8068 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8069#else
8070 if (!port) {
8071 kfree(cfg);
8072 return -EINVAL;
8073 }
8074 cfg->src_port = port;
8075#endif
8076
8077 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8078 cfg->payload_len = data_size;
8079 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8080 memcpy((void *)cfg->payload,
8081 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8082 data_size);
8083 if (seq)
8084 cfg->payload_seq = *seq;
8085 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8086 cfg->wake_len = wake_size;
8087 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8088 memcpy((void *)cfg->wake_data,
8089 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8090 wake_size);
8091 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8092 data_size + wake_size;
8093 memcpy((void *)cfg->wake_mask,
8094 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8095 wake_mask_size);
8096 if (tok) {
8097 cfg->tokens_size = tokens_size;
8098 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8099 }
8100
8101 trig->tcp = cfg;
8102
8103 return 0;
8104}
8105
Johannes Bergff1b6e62011-05-04 15:37:28 +02008106static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8107{
8108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8109 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008110 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008111 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008112 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008113 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008114 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008115
Johannes Berg964dc9e2013-06-03 17:25:34 +02008116 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008117 return -EOPNOTSUPP;
8118
Johannes Bergae33bd82012-07-12 16:25:02 +02008119 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8120 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008121 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008122 goto set_wakeup;
8123 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008124
8125 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8126 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8127 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8128 nl80211_wowlan_policy);
8129 if (err)
8130 return err;
8131
8132 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8133 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8134 return -EINVAL;
8135 new_triggers.any = true;
8136 }
8137
8138 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8139 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8140 return -EINVAL;
8141 new_triggers.disconnect = true;
8142 }
8143
8144 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8145 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8146 return -EINVAL;
8147 new_triggers.magic_pkt = true;
8148 }
8149
Johannes Berg77dbbb12011-07-13 10:48:55 +02008150 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8151 return -EINVAL;
8152
8153 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8154 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8155 return -EINVAL;
8156 new_triggers.gtk_rekey_failure = true;
8157 }
8158
8159 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8160 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8161 return -EINVAL;
8162 new_triggers.eap_identity_req = true;
8163 }
8164
8165 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8166 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8167 return -EINVAL;
8168 new_triggers.four_way_handshake = true;
8169 }
8170
8171 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8172 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8173 return -EINVAL;
8174 new_triggers.rfkill_release = true;
8175 }
8176
Johannes Bergff1b6e62011-05-04 15:37:28 +02008177 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8178 struct nlattr *pat;
8179 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008180 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008181 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008182
8183 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8184 rem)
8185 n_patterns++;
8186 if (n_patterns > wowlan->n_patterns)
8187 return -EINVAL;
8188
8189 new_triggers.patterns = kcalloc(n_patterns,
8190 sizeof(new_triggers.patterns[0]),
8191 GFP_KERNEL);
8192 if (!new_triggers.patterns)
8193 return -ENOMEM;
8194
8195 new_triggers.n_patterns = n_patterns;
8196 i = 0;
8197
8198 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8199 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008200 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8201 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008202 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008203 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8204 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008205 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008206 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008207 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008208 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008209 goto error;
8210 if (pat_len > wowlan->pattern_max_len ||
8211 pat_len < wowlan->pattern_min_len)
8212 goto error;
8213
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008214 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008215 pkt_offset = 0;
8216 else
8217 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008218 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008219 if (pkt_offset > wowlan->max_pkt_offset)
8220 goto error;
8221 new_triggers.patterns[i].pkt_offset = pkt_offset;
8222
Johannes Bergff1b6e62011-05-04 15:37:28 +02008223 new_triggers.patterns[i].mask =
8224 kmalloc(mask_len + pat_len, GFP_KERNEL);
8225 if (!new_triggers.patterns[i].mask) {
8226 err = -ENOMEM;
8227 goto error;
8228 }
8229 new_triggers.patterns[i].pattern =
8230 new_triggers.patterns[i].mask + mask_len;
8231 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008232 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008233 mask_len);
8234 new_triggers.patterns[i].pattern_len = pat_len;
8235 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008236 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008237 pat_len);
8238 i++;
8239 }
8240 }
8241
Johannes Berg2a0e0472013-01-23 22:57:40 +01008242 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8243 err = nl80211_parse_wowlan_tcp(
8244 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8245 &new_triggers);
8246 if (err)
8247 goto error;
8248 }
8249
Johannes Bergae33bd82012-07-12 16:25:02 +02008250 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8251 if (!ntrig) {
8252 err = -ENOMEM;
8253 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008254 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008255 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008256 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008257
Johannes Bergae33bd82012-07-12 16:25:02 +02008258 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008259 if (rdev->ops->set_wakeup &&
8260 prev_enabled != !!rdev->wiphy.wowlan_config)
8261 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008262
Johannes Bergff1b6e62011-05-04 15:37:28 +02008263 return 0;
8264 error:
8265 for (i = 0; i < new_triggers.n_patterns; i++)
8266 kfree(new_triggers.patterns[i].mask);
8267 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008268 if (new_triggers.tcp && new_triggers.tcp->sock)
8269 sock_release(new_triggers.tcp->sock);
8270 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008271 return err;
8272}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008273#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008274
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008275static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8276 struct cfg80211_registered_device *rdev)
8277{
8278 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8279 int i, j, pat_len;
8280 struct cfg80211_coalesce_rules *rule;
8281
8282 if (!rdev->coalesce->n_rules)
8283 return 0;
8284
8285 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8286 if (!nl_rules)
8287 return -ENOBUFS;
8288
8289 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8290 nl_rule = nla_nest_start(msg, i + 1);
8291 if (!nl_rule)
8292 return -ENOBUFS;
8293
8294 rule = &rdev->coalesce->rules[i];
8295 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8296 rule->delay))
8297 return -ENOBUFS;
8298
8299 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8300 rule->condition))
8301 return -ENOBUFS;
8302
8303 nl_pats = nla_nest_start(msg,
8304 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8305 if (!nl_pats)
8306 return -ENOBUFS;
8307
8308 for (j = 0; j < rule->n_patterns; j++) {
8309 nl_pat = nla_nest_start(msg, j + 1);
8310 if (!nl_pat)
8311 return -ENOBUFS;
8312 pat_len = rule->patterns[j].pattern_len;
8313 if (nla_put(msg, NL80211_PKTPAT_MASK,
8314 DIV_ROUND_UP(pat_len, 8),
8315 rule->patterns[j].mask) ||
8316 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8317 rule->patterns[j].pattern) ||
8318 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8319 rule->patterns[j].pkt_offset))
8320 return -ENOBUFS;
8321 nla_nest_end(msg, nl_pat);
8322 }
8323 nla_nest_end(msg, nl_pats);
8324 nla_nest_end(msg, nl_rule);
8325 }
8326 nla_nest_end(msg, nl_rules);
8327
8328 return 0;
8329}
8330
8331static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8332{
8333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8334 struct sk_buff *msg;
8335 void *hdr;
8336
8337 if (!rdev->wiphy.coalesce)
8338 return -EOPNOTSUPP;
8339
8340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8341 if (!msg)
8342 return -ENOMEM;
8343
8344 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8345 NL80211_CMD_GET_COALESCE);
8346 if (!hdr)
8347 goto nla_put_failure;
8348
8349 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8350 goto nla_put_failure;
8351
8352 genlmsg_end(msg, hdr);
8353 return genlmsg_reply(msg, info);
8354
8355nla_put_failure:
8356 nlmsg_free(msg);
8357 return -ENOBUFS;
8358}
8359
8360void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8361{
8362 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8363 int i, j;
8364 struct cfg80211_coalesce_rules *rule;
8365
8366 if (!coalesce)
8367 return;
8368
8369 for (i = 0; i < coalesce->n_rules; i++) {
8370 rule = &coalesce->rules[i];
8371 for (j = 0; j < rule->n_patterns; j++)
8372 kfree(rule->patterns[j].mask);
8373 kfree(rule->patterns);
8374 }
8375 kfree(coalesce->rules);
8376 kfree(coalesce);
8377 rdev->coalesce = NULL;
8378}
8379
8380static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8381 struct nlattr *rule,
8382 struct cfg80211_coalesce_rules *new_rule)
8383{
8384 int err, i;
8385 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8386 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8387 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8388 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8389
8390 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8391 nla_len(rule), nl80211_coalesce_policy);
8392 if (err)
8393 return err;
8394
8395 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8396 new_rule->delay =
8397 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8398 if (new_rule->delay > coalesce->max_delay)
8399 return -EINVAL;
8400
8401 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8402 new_rule->condition =
8403 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8404 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8405 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8406 return -EINVAL;
8407
8408 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8409 return -EINVAL;
8410
8411 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8412 rem)
8413 n_patterns++;
8414 if (n_patterns > coalesce->n_patterns)
8415 return -EINVAL;
8416
8417 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8418 GFP_KERNEL);
8419 if (!new_rule->patterns)
8420 return -ENOMEM;
8421
8422 new_rule->n_patterns = n_patterns;
8423 i = 0;
8424
8425 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8426 rem) {
8427 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8428 nla_len(pat), NULL);
8429 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8430 !pat_tb[NL80211_PKTPAT_PATTERN])
8431 return -EINVAL;
8432 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8433 mask_len = DIV_ROUND_UP(pat_len, 8);
8434 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8435 return -EINVAL;
8436 if (pat_len > coalesce->pattern_max_len ||
8437 pat_len < coalesce->pattern_min_len)
8438 return -EINVAL;
8439
8440 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8441 pkt_offset = 0;
8442 else
8443 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8444 if (pkt_offset > coalesce->max_pkt_offset)
8445 return -EINVAL;
8446 new_rule->patterns[i].pkt_offset = pkt_offset;
8447
8448 new_rule->patterns[i].mask =
8449 kmalloc(mask_len + pat_len, GFP_KERNEL);
8450 if (!new_rule->patterns[i].mask)
8451 return -ENOMEM;
8452 new_rule->patterns[i].pattern =
8453 new_rule->patterns[i].mask + mask_len;
8454 memcpy(new_rule->patterns[i].mask,
8455 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8456 new_rule->patterns[i].pattern_len = pat_len;
8457 memcpy(new_rule->patterns[i].pattern,
8458 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8459 i++;
8460 }
8461
8462 return 0;
8463}
8464
8465static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8466{
8467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8468 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8469 struct cfg80211_coalesce new_coalesce = {};
8470 struct cfg80211_coalesce *n_coalesce;
8471 int err, rem_rule, n_rules = 0, i, j;
8472 struct nlattr *rule;
8473 struct cfg80211_coalesce_rules *tmp_rule;
8474
8475 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8476 return -EOPNOTSUPP;
8477
8478 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8479 cfg80211_rdev_free_coalesce(rdev);
8480 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8481 return 0;
8482 }
8483
8484 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8485 rem_rule)
8486 n_rules++;
8487 if (n_rules > coalesce->n_rules)
8488 return -EINVAL;
8489
8490 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8491 GFP_KERNEL);
8492 if (!new_coalesce.rules)
8493 return -ENOMEM;
8494
8495 new_coalesce.n_rules = n_rules;
8496 i = 0;
8497
8498 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8499 rem_rule) {
8500 err = nl80211_parse_coalesce_rule(rdev, rule,
8501 &new_coalesce.rules[i]);
8502 if (err)
8503 goto error;
8504
8505 i++;
8506 }
8507
8508 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8509 if (err)
8510 goto error;
8511
8512 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8513 if (!n_coalesce) {
8514 err = -ENOMEM;
8515 goto error;
8516 }
8517 cfg80211_rdev_free_coalesce(rdev);
8518 rdev->coalesce = n_coalesce;
8519
8520 return 0;
8521error:
8522 for (i = 0; i < new_coalesce.n_rules; i++) {
8523 tmp_rule = &new_coalesce.rules[i];
8524 for (j = 0; j < tmp_rule->n_patterns; j++)
8525 kfree(tmp_rule->patterns[j].mask);
8526 kfree(tmp_rule->patterns);
8527 }
8528 kfree(new_coalesce.rules);
8529
8530 return err;
8531}
8532
Johannes Berge5497d72011-07-05 16:35:40 +02008533static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8534{
8535 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8536 struct net_device *dev = info->user_ptr[1];
8537 struct wireless_dev *wdev = dev->ieee80211_ptr;
8538 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8539 struct cfg80211_gtk_rekey_data rekey_data;
8540 int err;
8541
8542 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8543 return -EINVAL;
8544
8545 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8546 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8547 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8548 nl80211_rekey_policy);
8549 if (err)
8550 return err;
8551
8552 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8553 return -ERANGE;
8554 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8555 return -ERANGE;
8556 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8557 return -ERANGE;
8558
8559 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8560 NL80211_KEK_LEN);
8561 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8562 NL80211_KCK_LEN);
8563 memcpy(rekey_data.replay_ctr,
8564 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8565 NL80211_REPLAY_CTR_LEN);
8566
8567 wdev_lock(wdev);
8568 if (!wdev->current_bss) {
8569 err = -ENOTCONN;
8570 goto out;
8571 }
8572
8573 if (!rdev->ops->set_rekey_data) {
8574 err = -EOPNOTSUPP;
8575 goto out;
8576 }
8577
Hila Gonene35e4d22012-06-27 17:19:42 +03008578 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008579 out:
8580 wdev_unlock(wdev);
8581 return err;
8582}
8583
Johannes Berg28946da2011-11-04 11:18:12 +01008584static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8585 struct genl_info *info)
8586{
8587 struct net_device *dev = info->user_ptr[1];
8588 struct wireless_dev *wdev = dev->ieee80211_ptr;
8589
8590 if (wdev->iftype != NL80211_IFTYPE_AP &&
8591 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8592 return -EINVAL;
8593
Eric W. Biederman15e47302012-09-07 20:12:54 +00008594 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008595 return -EBUSY;
8596
Eric W. Biederman15e47302012-09-07 20:12:54 +00008597 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008598 return 0;
8599}
8600
Johannes Berg7f6cf312011-11-04 11:18:15 +01008601static int nl80211_probe_client(struct sk_buff *skb,
8602 struct genl_info *info)
8603{
8604 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8605 struct net_device *dev = info->user_ptr[1];
8606 struct wireless_dev *wdev = dev->ieee80211_ptr;
8607 struct sk_buff *msg;
8608 void *hdr;
8609 const u8 *addr;
8610 u64 cookie;
8611 int err;
8612
8613 if (wdev->iftype != NL80211_IFTYPE_AP &&
8614 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8615 return -EOPNOTSUPP;
8616
8617 if (!info->attrs[NL80211_ATTR_MAC])
8618 return -EINVAL;
8619
8620 if (!rdev->ops->probe_client)
8621 return -EOPNOTSUPP;
8622
8623 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8624 if (!msg)
8625 return -ENOMEM;
8626
Eric W. Biederman15e47302012-09-07 20:12:54 +00008627 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008628 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008629 if (!hdr) {
8630 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008631 goto free_msg;
8632 }
8633
8634 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8635
Hila Gonene35e4d22012-06-27 17:19:42 +03008636 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008637 if (err)
8638 goto free_msg;
8639
David S. Miller9360ffd2012-03-29 04:41:26 -04008640 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8641 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008642
8643 genlmsg_end(msg, hdr);
8644
8645 return genlmsg_reply(msg, info);
8646
8647 nla_put_failure:
8648 err = -ENOBUFS;
8649 free_msg:
8650 nlmsg_free(msg);
8651 return err;
8652}
8653
Johannes Berg5e7602302011-11-04 11:18:17 +01008654static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8655{
8656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008657 struct cfg80211_beacon_registration *reg, *nreg;
8658 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008659
8660 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8661 return -EOPNOTSUPP;
8662
Ben Greear37c73b52012-10-26 14:49:25 -07008663 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8664 if (!nreg)
8665 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008666
Ben Greear37c73b52012-10-26 14:49:25 -07008667 /* First, check if already registered. */
8668 spin_lock_bh(&rdev->beacon_registrations_lock);
8669 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8670 if (reg->nlportid == info->snd_portid) {
8671 rv = -EALREADY;
8672 goto out_err;
8673 }
8674 }
8675 /* Add it to the list */
8676 nreg->nlportid = info->snd_portid;
8677 list_add(&nreg->list, &rdev->beacon_registrations);
8678
8679 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008680
8681 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008682out_err:
8683 spin_unlock_bh(&rdev->beacon_registrations_lock);
8684 kfree(nreg);
8685 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008686}
8687
Johannes Berg98104fde2012-06-16 00:19:54 +02008688static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8689{
8690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8691 struct wireless_dev *wdev = info->user_ptr[1];
8692 int err;
8693
8694 if (!rdev->ops->start_p2p_device)
8695 return -EOPNOTSUPP;
8696
8697 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8698 return -EOPNOTSUPP;
8699
8700 if (wdev->p2p_started)
8701 return 0;
8702
Johannes Berg98104fde2012-06-16 00:19:54 +02008703 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008704 if (err)
8705 return err;
8706
Johannes Bergeeb126e2012-10-23 15:16:50 +02008707 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008708 if (err)
8709 return err;
8710
8711 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008712 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008713
8714 return 0;
8715}
8716
8717static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8718{
8719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8720 struct wireless_dev *wdev = info->user_ptr[1];
8721
8722 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8723 return -EOPNOTSUPP;
8724
8725 if (!rdev->ops->stop_p2p_device)
8726 return -EOPNOTSUPP;
8727
Johannes Bergf9f47522013-03-19 15:04:07 +01008728 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008729
8730 return 0;
8731}
8732
Johannes Berg3713b4e2013-02-14 16:19:38 +01008733static int nl80211_get_protocol_features(struct sk_buff *skb,
8734 struct genl_info *info)
8735{
8736 void *hdr;
8737 struct sk_buff *msg;
8738
8739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8740 if (!msg)
8741 return -ENOMEM;
8742
8743 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8744 NL80211_CMD_GET_PROTOCOL_FEATURES);
8745 if (!hdr)
8746 goto nla_put_failure;
8747
8748 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8749 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8750 goto nla_put_failure;
8751
8752 genlmsg_end(msg, hdr);
8753 return genlmsg_reply(msg, info);
8754
8755 nla_put_failure:
8756 kfree_skb(msg);
8757 return -ENOBUFS;
8758}
8759
Jouni Malinen355199e2013-02-27 17:14:27 +02008760static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8761{
8762 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8763 struct cfg80211_update_ft_ies_params ft_params;
8764 struct net_device *dev = info->user_ptr[1];
8765
8766 if (!rdev->ops->update_ft_ies)
8767 return -EOPNOTSUPP;
8768
8769 if (!info->attrs[NL80211_ATTR_MDID] ||
8770 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8771 return -EINVAL;
8772
8773 memset(&ft_params, 0, sizeof(ft_params));
8774 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8775 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8776 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8777
8778 return rdev_update_ft_ies(rdev, dev, &ft_params);
8779}
8780
Arend van Spriel5de17982013-04-18 15:49:00 +02008781static int nl80211_crit_protocol_start(struct sk_buff *skb,
8782 struct genl_info *info)
8783{
8784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8785 struct wireless_dev *wdev = info->user_ptr[1];
8786 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8787 u16 duration;
8788 int ret;
8789
8790 if (!rdev->ops->crit_proto_start)
8791 return -EOPNOTSUPP;
8792
8793 if (WARN_ON(!rdev->ops->crit_proto_stop))
8794 return -EINVAL;
8795
8796 if (rdev->crit_proto_nlportid)
8797 return -EBUSY;
8798
8799 /* determine protocol if provided */
8800 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8801 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8802
8803 if (proto >= NUM_NL80211_CRIT_PROTO)
8804 return -EINVAL;
8805
8806 /* timeout must be provided */
8807 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8808 return -EINVAL;
8809
8810 duration =
8811 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8812
8813 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8814 return -ERANGE;
8815
8816 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8817 if (!ret)
8818 rdev->crit_proto_nlportid = info->snd_portid;
8819
8820 return ret;
8821}
8822
8823static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8824 struct genl_info *info)
8825{
8826 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8827 struct wireless_dev *wdev = info->user_ptr[1];
8828
8829 if (!rdev->ops->crit_proto_stop)
8830 return -EOPNOTSUPP;
8831
8832 if (rdev->crit_proto_nlportid) {
8833 rdev->crit_proto_nlportid = 0;
8834 rdev_crit_proto_stop(rdev, wdev);
8835 }
8836 return 0;
8837}
8838
Johannes Berg4c476992010-10-04 21:36:35 +02008839#define NL80211_FLAG_NEED_WIPHY 0x01
8840#define NL80211_FLAG_NEED_NETDEV 0x02
8841#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008842#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8843#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8844 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008845#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008846/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008847#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8848 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008849
8850static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8851 struct genl_info *info)
8852{
8853 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008854 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008855 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008856 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8857
8858 if (rtnl)
8859 rtnl_lock();
8860
8861 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008862 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008863 if (IS_ERR(rdev)) {
8864 if (rtnl)
8865 rtnl_unlock();
8866 return PTR_ERR(rdev);
8867 }
8868 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008869 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8870 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008871 ASSERT_RTNL();
8872
Johannes Berg89a54e42012-06-15 14:33:17 +02008873 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8874 info->attrs);
8875 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008876 if (rtnl)
8877 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008878 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008879 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008880
Johannes Berg89a54e42012-06-15 14:33:17 +02008881 dev = wdev->netdev;
8882 rdev = wiphy_to_dev(wdev->wiphy);
8883
Johannes Berg1bf614e2012-06-15 15:23:36 +02008884 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8885 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008886 if (rtnl)
8887 rtnl_unlock();
8888 return -EINVAL;
8889 }
8890
8891 info->user_ptr[1] = dev;
8892 } else {
8893 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008894 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008895
Johannes Berg1bf614e2012-06-15 15:23:36 +02008896 if (dev) {
8897 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8898 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008899 if (rtnl)
8900 rtnl_unlock();
8901 return -ENETDOWN;
8902 }
8903
8904 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008905 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8906 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008907 if (rtnl)
8908 rtnl_unlock();
8909 return -ENETDOWN;
8910 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008911 }
8912
Johannes Berg4c476992010-10-04 21:36:35 +02008913 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008914 }
8915
8916 return 0;
8917}
8918
8919static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8920 struct genl_info *info)
8921{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008922 if (info->user_ptr[1]) {
8923 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8924 struct wireless_dev *wdev = info->user_ptr[1];
8925
8926 if (wdev->netdev)
8927 dev_put(wdev->netdev);
8928 } else {
8929 dev_put(info->user_ptr[1]);
8930 }
8931 }
Johannes Berg4c476992010-10-04 21:36:35 +02008932 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8933 rtnl_unlock();
8934}
8935
Johannes Berg55682962007-09-20 13:09:35 -04008936static struct genl_ops nl80211_ops[] = {
8937 {
8938 .cmd = NL80211_CMD_GET_WIPHY,
8939 .doit = nl80211_get_wiphy,
8940 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008941 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008942 .policy = nl80211_policy,
8943 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008944 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8945 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008946 },
8947 {
8948 .cmd = NL80211_CMD_SET_WIPHY,
8949 .doit = nl80211_set_wiphy,
8950 .policy = nl80211_policy,
8951 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008952 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008953 },
8954 {
8955 .cmd = NL80211_CMD_GET_INTERFACE,
8956 .doit = nl80211_get_interface,
8957 .dumpit = nl80211_dump_interface,
8958 .policy = nl80211_policy,
8959 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008960 .internal_flags = NL80211_FLAG_NEED_WDEV |
8961 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008962 },
8963 {
8964 .cmd = NL80211_CMD_SET_INTERFACE,
8965 .doit = nl80211_set_interface,
8966 .policy = nl80211_policy,
8967 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008968 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8969 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008970 },
8971 {
8972 .cmd = NL80211_CMD_NEW_INTERFACE,
8973 .doit = nl80211_new_interface,
8974 .policy = nl80211_policy,
8975 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008976 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8977 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008978 },
8979 {
8980 .cmd = NL80211_CMD_DEL_INTERFACE,
8981 .doit = nl80211_del_interface,
8982 .policy = nl80211_policy,
8983 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008984 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008985 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008986 },
Johannes Berg41ade002007-12-19 02:03:29 +01008987 {
8988 .cmd = NL80211_CMD_GET_KEY,
8989 .doit = nl80211_get_key,
8990 .policy = nl80211_policy,
8991 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008993 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008994 },
8995 {
8996 .cmd = NL80211_CMD_SET_KEY,
8997 .doit = nl80211_set_key,
8998 .policy = nl80211_policy,
8999 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009000 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009001 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009002 },
9003 {
9004 .cmd = NL80211_CMD_NEW_KEY,
9005 .doit = nl80211_new_key,
9006 .policy = nl80211_policy,
9007 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009009 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009010 },
9011 {
9012 .cmd = NL80211_CMD_DEL_KEY,
9013 .doit = nl80211_del_key,
9014 .policy = nl80211_policy,
9015 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009017 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009018 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009019 {
9020 .cmd = NL80211_CMD_SET_BEACON,
9021 .policy = nl80211_policy,
9022 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009023 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009025 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009026 },
9027 {
Johannes Berg88600202012-02-13 15:17:18 +01009028 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009029 .policy = nl80211_policy,
9030 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009031 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009033 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009034 },
9035 {
Johannes Berg88600202012-02-13 15:17:18 +01009036 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009037 .policy = nl80211_policy,
9038 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009039 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009041 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009042 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009043 {
9044 .cmd = NL80211_CMD_GET_STATION,
9045 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009046 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009047 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009048 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9049 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009050 },
9051 {
9052 .cmd = NL80211_CMD_SET_STATION,
9053 .doit = nl80211_set_station,
9054 .policy = nl80211_policy,
9055 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009057 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009058 },
9059 {
9060 .cmd = NL80211_CMD_NEW_STATION,
9061 .doit = nl80211_new_station,
9062 .policy = nl80211_policy,
9063 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009065 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009066 },
9067 {
9068 .cmd = NL80211_CMD_DEL_STATION,
9069 .doit = nl80211_del_station,
9070 .policy = nl80211_policy,
9071 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009073 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009074 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009075 {
9076 .cmd = NL80211_CMD_GET_MPATH,
9077 .doit = nl80211_get_mpath,
9078 .dumpit = nl80211_dump_mpath,
9079 .policy = nl80211_policy,
9080 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009081 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009082 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009083 },
9084 {
9085 .cmd = NL80211_CMD_SET_MPATH,
9086 .doit = nl80211_set_mpath,
9087 .policy = nl80211_policy,
9088 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009089 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009090 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009091 },
9092 {
9093 .cmd = NL80211_CMD_NEW_MPATH,
9094 .doit = nl80211_new_mpath,
9095 .policy = nl80211_policy,
9096 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009098 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009099 },
9100 {
9101 .cmd = NL80211_CMD_DEL_MPATH,
9102 .doit = nl80211_del_mpath,
9103 .policy = nl80211_policy,
9104 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009105 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009106 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009107 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009108 {
9109 .cmd = NL80211_CMD_SET_BSS,
9110 .doit = nl80211_set_bss,
9111 .policy = nl80211_policy,
9112 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009113 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009114 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009115 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009116 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009117 .cmd = NL80211_CMD_GET_REG,
9118 .doit = nl80211_get_reg,
9119 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009120 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009121 /* can be retrieved by unprivileged users */
9122 },
9123 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009124 .cmd = NL80211_CMD_SET_REG,
9125 .doit = nl80211_set_reg,
9126 .policy = nl80211_policy,
9127 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009128 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009129 },
9130 {
9131 .cmd = NL80211_CMD_REQ_SET_REG,
9132 .doit = nl80211_req_set_reg,
9133 .policy = nl80211_policy,
9134 .flags = GENL_ADMIN_PERM,
9135 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009136 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009137 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9138 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009139 .policy = nl80211_policy,
9140 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009141 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009142 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009143 },
9144 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009145 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9146 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009147 .policy = nl80211_policy,
9148 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009149 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009150 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009151 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009152 {
Johannes Berg2a519312009-02-10 21:25:55 +01009153 .cmd = NL80211_CMD_TRIGGER_SCAN,
9154 .doit = nl80211_trigger_scan,
9155 .policy = nl80211_policy,
9156 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009157 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009158 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009159 },
9160 {
9161 .cmd = NL80211_CMD_GET_SCAN,
9162 .policy = nl80211_policy,
9163 .dumpit = nl80211_dump_scan,
9164 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009165 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009166 .cmd = NL80211_CMD_START_SCHED_SCAN,
9167 .doit = nl80211_start_sched_scan,
9168 .policy = nl80211_policy,
9169 .flags = GENL_ADMIN_PERM,
9170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9171 NL80211_FLAG_NEED_RTNL,
9172 },
9173 {
9174 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9175 .doit = nl80211_stop_sched_scan,
9176 .policy = nl80211_policy,
9177 .flags = GENL_ADMIN_PERM,
9178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9179 NL80211_FLAG_NEED_RTNL,
9180 },
9181 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009182 .cmd = NL80211_CMD_AUTHENTICATE,
9183 .doit = nl80211_authenticate,
9184 .policy = nl80211_policy,
9185 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009186 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009187 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009188 },
9189 {
9190 .cmd = NL80211_CMD_ASSOCIATE,
9191 .doit = nl80211_associate,
9192 .policy = nl80211_policy,
9193 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009194 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009195 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009196 },
9197 {
9198 .cmd = NL80211_CMD_DEAUTHENTICATE,
9199 .doit = nl80211_deauthenticate,
9200 .policy = nl80211_policy,
9201 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009202 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009203 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009204 },
9205 {
9206 .cmd = NL80211_CMD_DISASSOCIATE,
9207 .doit = nl80211_disassociate,
9208 .policy = nl80211_policy,
9209 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009210 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009211 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009212 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009213 {
9214 .cmd = NL80211_CMD_JOIN_IBSS,
9215 .doit = nl80211_join_ibss,
9216 .policy = nl80211_policy,
9217 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009218 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009219 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009220 },
9221 {
9222 .cmd = NL80211_CMD_LEAVE_IBSS,
9223 .doit = nl80211_leave_ibss,
9224 .policy = nl80211_policy,
9225 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009226 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009227 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009228 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009229#ifdef CONFIG_NL80211_TESTMODE
9230 {
9231 .cmd = NL80211_CMD_TESTMODE,
9232 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009233 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009234 .policy = nl80211_policy,
9235 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009236 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9237 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009238 },
9239#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009240 {
9241 .cmd = NL80211_CMD_CONNECT,
9242 .doit = nl80211_connect,
9243 .policy = nl80211_policy,
9244 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009246 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009247 },
9248 {
9249 .cmd = NL80211_CMD_DISCONNECT,
9250 .doit = nl80211_disconnect,
9251 .policy = nl80211_policy,
9252 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009253 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009254 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009255 },
Johannes Berg463d0182009-07-14 00:33:35 +02009256 {
9257 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9258 .doit = nl80211_wiphy_netns,
9259 .policy = nl80211_policy,
9260 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009261 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9262 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009263 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009264 {
9265 .cmd = NL80211_CMD_GET_SURVEY,
9266 .policy = nl80211_policy,
9267 .dumpit = nl80211_dump_survey,
9268 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009269 {
9270 .cmd = NL80211_CMD_SET_PMKSA,
9271 .doit = nl80211_setdel_pmksa,
9272 .policy = nl80211_policy,
9273 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009275 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009276 },
9277 {
9278 .cmd = NL80211_CMD_DEL_PMKSA,
9279 .doit = nl80211_setdel_pmksa,
9280 .policy = nl80211_policy,
9281 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009283 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009284 },
9285 {
9286 .cmd = NL80211_CMD_FLUSH_PMKSA,
9287 .doit = nl80211_flush_pmksa,
9288 .policy = nl80211_policy,
9289 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009290 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009291 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009292 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009293 {
9294 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9295 .doit = nl80211_remain_on_channel,
9296 .policy = nl80211_policy,
9297 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009298 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009299 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009300 },
9301 {
9302 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9303 .doit = nl80211_cancel_remain_on_channel,
9304 .policy = nl80211_policy,
9305 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009306 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009307 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009308 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009309 {
9310 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9311 .doit = nl80211_set_tx_bitrate_mask,
9312 .policy = nl80211_policy,
9313 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009314 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9315 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009316 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009317 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009318 .cmd = NL80211_CMD_REGISTER_FRAME,
9319 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009320 .policy = nl80211_policy,
9321 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009322 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009323 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009324 },
9325 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009326 .cmd = NL80211_CMD_FRAME,
9327 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009328 .policy = nl80211_policy,
9329 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009330 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009331 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009332 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009333 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009334 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9335 .doit = nl80211_tx_mgmt_cancel_wait,
9336 .policy = nl80211_policy,
9337 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009338 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009339 NL80211_FLAG_NEED_RTNL,
9340 },
9341 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009342 .cmd = NL80211_CMD_SET_POWER_SAVE,
9343 .doit = nl80211_set_power_save,
9344 .policy = nl80211_policy,
9345 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009346 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9347 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009348 },
9349 {
9350 .cmd = NL80211_CMD_GET_POWER_SAVE,
9351 .doit = nl80211_get_power_save,
9352 .policy = nl80211_policy,
9353 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009354 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9355 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009356 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009357 {
9358 .cmd = NL80211_CMD_SET_CQM,
9359 .doit = nl80211_set_cqm,
9360 .policy = nl80211_policy,
9361 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009362 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9363 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009364 },
Johannes Bergf444de02010-05-05 15:25:02 +02009365 {
9366 .cmd = NL80211_CMD_SET_CHANNEL,
9367 .doit = nl80211_set_channel,
9368 .policy = nl80211_policy,
9369 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009370 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9371 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009372 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009373 {
9374 .cmd = NL80211_CMD_SET_WDS_PEER,
9375 .doit = nl80211_set_wds_peer,
9376 .policy = nl80211_policy,
9377 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009378 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9379 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009380 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009381 {
9382 .cmd = NL80211_CMD_JOIN_MESH,
9383 .doit = nl80211_join_mesh,
9384 .policy = nl80211_policy,
9385 .flags = GENL_ADMIN_PERM,
9386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9387 NL80211_FLAG_NEED_RTNL,
9388 },
9389 {
9390 .cmd = NL80211_CMD_LEAVE_MESH,
9391 .doit = nl80211_leave_mesh,
9392 .policy = nl80211_policy,
9393 .flags = GENL_ADMIN_PERM,
9394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9395 NL80211_FLAG_NEED_RTNL,
9396 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009397#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009398 {
9399 .cmd = NL80211_CMD_GET_WOWLAN,
9400 .doit = nl80211_get_wowlan,
9401 .policy = nl80211_policy,
9402 /* can be retrieved by unprivileged users */
9403 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9404 NL80211_FLAG_NEED_RTNL,
9405 },
9406 {
9407 .cmd = NL80211_CMD_SET_WOWLAN,
9408 .doit = nl80211_set_wowlan,
9409 .policy = nl80211_policy,
9410 .flags = GENL_ADMIN_PERM,
9411 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9412 NL80211_FLAG_NEED_RTNL,
9413 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009414#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009415 {
9416 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9417 .doit = nl80211_set_rekey_data,
9418 .policy = nl80211_policy,
9419 .flags = GENL_ADMIN_PERM,
9420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9421 NL80211_FLAG_NEED_RTNL,
9422 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009423 {
9424 .cmd = NL80211_CMD_TDLS_MGMT,
9425 .doit = nl80211_tdls_mgmt,
9426 .policy = nl80211_policy,
9427 .flags = GENL_ADMIN_PERM,
9428 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9429 NL80211_FLAG_NEED_RTNL,
9430 },
9431 {
9432 .cmd = NL80211_CMD_TDLS_OPER,
9433 .doit = nl80211_tdls_oper,
9434 .policy = nl80211_policy,
9435 .flags = GENL_ADMIN_PERM,
9436 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9437 NL80211_FLAG_NEED_RTNL,
9438 },
Johannes Berg28946da2011-11-04 11:18:12 +01009439 {
9440 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9441 .doit = nl80211_register_unexpected_frame,
9442 .policy = nl80211_policy,
9443 .flags = GENL_ADMIN_PERM,
9444 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9445 NL80211_FLAG_NEED_RTNL,
9446 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009447 {
9448 .cmd = NL80211_CMD_PROBE_CLIENT,
9449 .doit = nl80211_probe_client,
9450 .policy = nl80211_policy,
9451 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009452 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009453 NL80211_FLAG_NEED_RTNL,
9454 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009455 {
9456 .cmd = NL80211_CMD_REGISTER_BEACONS,
9457 .doit = nl80211_register_beacons,
9458 .policy = nl80211_policy,
9459 .flags = GENL_ADMIN_PERM,
9460 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9461 NL80211_FLAG_NEED_RTNL,
9462 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009463 {
9464 .cmd = NL80211_CMD_SET_NOACK_MAP,
9465 .doit = nl80211_set_noack_map,
9466 .policy = nl80211_policy,
9467 .flags = GENL_ADMIN_PERM,
9468 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9469 NL80211_FLAG_NEED_RTNL,
9470 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009471 {
9472 .cmd = NL80211_CMD_START_P2P_DEVICE,
9473 .doit = nl80211_start_p2p_device,
9474 .policy = nl80211_policy,
9475 .flags = GENL_ADMIN_PERM,
9476 .internal_flags = NL80211_FLAG_NEED_WDEV |
9477 NL80211_FLAG_NEED_RTNL,
9478 },
9479 {
9480 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9481 .doit = nl80211_stop_p2p_device,
9482 .policy = nl80211_policy,
9483 .flags = GENL_ADMIN_PERM,
9484 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9485 NL80211_FLAG_NEED_RTNL,
9486 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009487 {
9488 .cmd = NL80211_CMD_SET_MCAST_RATE,
9489 .doit = nl80211_set_mcast_rate,
9490 .policy = nl80211_policy,
9491 .flags = GENL_ADMIN_PERM,
9492 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9493 NL80211_FLAG_NEED_RTNL,
9494 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309495 {
9496 .cmd = NL80211_CMD_SET_MAC_ACL,
9497 .doit = nl80211_set_mac_acl,
9498 .policy = nl80211_policy,
9499 .flags = GENL_ADMIN_PERM,
9500 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9501 NL80211_FLAG_NEED_RTNL,
9502 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009503 {
9504 .cmd = NL80211_CMD_RADAR_DETECT,
9505 .doit = nl80211_start_radar_detection,
9506 .policy = nl80211_policy,
9507 .flags = GENL_ADMIN_PERM,
9508 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9509 NL80211_FLAG_NEED_RTNL,
9510 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009511 {
9512 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9513 .doit = nl80211_get_protocol_features,
9514 .policy = nl80211_policy,
9515 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009516 {
9517 .cmd = NL80211_CMD_UPDATE_FT_IES,
9518 .doit = nl80211_update_ft_ies,
9519 .policy = nl80211_policy,
9520 .flags = GENL_ADMIN_PERM,
9521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9522 NL80211_FLAG_NEED_RTNL,
9523 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009524 {
9525 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9526 .doit = nl80211_crit_protocol_start,
9527 .policy = nl80211_policy,
9528 .flags = GENL_ADMIN_PERM,
9529 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9530 NL80211_FLAG_NEED_RTNL,
9531 },
9532 {
9533 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9534 .doit = nl80211_crit_protocol_stop,
9535 .policy = nl80211_policy,
9536 .flags = GENL_ADMIN_PERM,
9537 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9538 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009539 },
9540 {
9541 .cmd = NL80211_CMD_GET_COALESCE,
9542 .doit = nl80211_get_coalesce,
9543 .policy = nl80211_policy,
9544 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9545 NL80211_FLAG_NEED_RTNL,
9546 },
9547 {
9548 .cmd = NL80211_CMD_SET_COALESCE,
9549 .doit = nl80211_set_coalesce,
9550 .policy = nl80211_policy,
9551 .flags = GENL_ADMIN_PERM,
9552 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9553 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009554 },
9555 {
9556 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9557 .doit = nl80211_channel_switch,
9558 .policy = nl80211_policy,
9559 .flags = GENL_ADMIN_PERM,
9560 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9561 NL80211_FLAG_NEED_RTNL,
9562 },
Johannes Berg55682962007-09-20 13:09:35 -04009563};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009564
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009565static struct genl_multicast_group nl80211_mlme_mcgrp = {
9566 .name = "mlme",
9567};
Johannes Berg55682962007-09-20 13:09:35 -04009568
9569/* multicast groups */
9570static struct genl_multicast_group nl80211_config_mcgrp = {
9571 .name = "config",
9572};
Johannes Berg2a519312009-02-10 21:25:55 +01009573static struct genl_multicast_group nl80211_scan_mcgrp = {
9574 .name = "scan",
9575};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009576static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9577 .name = "regulatory",
9578};
Johannes Berg55682962007-09-20 13:09:35 -04009579
9580/* notification functions */
9581
9582void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9583{
9584 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009585 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009586
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009588 if (!msg)
9589 return;
9590
Johannes Berg86e8cf92013-06-19 10:57:22 +02009591 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009592 nlmsg_free(msg);
9593 return;
9594 }
9595
Johannes Berg463d0182009-07-14 00:33:35 +02009596 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9597 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009598}
9599
Johannes Berg362a4152009-05-24 16:43:15 +02009600static int nl80211_add_scan_req(struct sk_buff *msg,
9601 struct cfg80211_registered_device *rdev)
9602{
9603 struct cfg80211_scan_request *req = rdev->scan_req;
9604 struct nlattr *nest;
9605 int i;
9606
9607 if (WARN_ON(!req))
9608 return 0;
9609
9610 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9611 if (!nest)
9612 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009613 for (i = 0; i < req->n_ssids; i++) {
9614 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9615 goto nla_put_failure;
9616 }
Johannes Berg362a4152009-05-24 16:43:15 +02009617 nla_nest_end(msg, nest);
9618
9619 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9620 if (!nest)
9621 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009622 for (i = 0; i < req->n_channels; i++) {
9623 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9624 goto nla_put_failure;
9625 }
Johannes Berg362a4152009-05-24 16:43:15 +02009626 nla_nest_end(msg, nest);
9627
David S. Miller9360ffd2012-03-29 04:41:26 -04009628 if (req->ie &&
9629 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9630 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009631
Sam Lefflered4737712012-10-11 21:03:31 -07009632 if (req->flags)
9633 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9634
Johannes Berg362a4152009-05-24 16:43:15 +02009635 return 0;
9636 nla_put_failure:
9637 return -ENOBUFS;
9638}
9639
Johannes Berga538e2d2009-06-16 19:56:42 +02009640static int nl80211_send_scan_msg(struct sk_buff *msg,
9641 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009642 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009643 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009644 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009645{
9646 void *hdr;
9647
Eric W. Biederman15e47302012-09-07 20:12:54 +00009648 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009649 if (!hdr)
9650 return -1;
9651
David S. Miller9360ffd2012-03-29 04:41:26 -04009652 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009653 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9654 wdev->netdev->ifindex)) ||
9655 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009656 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009657
Johannes Berg362a4152009-05-24 16:43:15 +02009658 /* ignore errors and send incomplete event anyway */
9659 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009660
9661 return genlmsg_end(msg, hdr);
9662
9663 nla_put_failure:
9664 genlmsg_cancel(msg, hdr);
9665 return -EMSGSIZE;
9666}
9667
Luciano Coelho807f8a82011-05-11 17:09:35 +03009668static int
9669nl80211_send_sched_scan_msg(struct sk_buff *msg,
9670 struct cfg80211_registered_device *rdev,
9671 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009672 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009673{
9674 void *hdr;
9675
Eric W. Biederman15e47302012-09-07 20:12:54 +00009676 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009677 if (!hdr)
9678 return -1;
9679
David S. Miller9360ffd2012-03-29 04:41:26 -04009680 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9681 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9682 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009683
9684 return genlmsg_end(msg, hdr);
9685
9686 nla_put_failure:
9687 genlmsg_cancel(msg, hdr);
9688 return -EMSGSIZE;
9689}
9690
Johannes Berga538e2d2009-06-16 19:56:42 +02009691void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009692 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009693{
9694 struct sk_buff *msg;
9695
Thomas Graf58050fc2012-06-28 03:57:45 +00009696 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009697 if (!msg)
9698 return;
9699
Johannes Bergfd014282012-06-18 19:17:03 +02009700 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009701 NL80211_CMD_TRIGGER_SCAN) < 0) {
9702 nlmsg_free(msg);
9703 return;
9704 }
9705
Johannes Berg463d0182009-07-14 00:33:35 +02009706 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9707 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009708}
9709
Johannes Berg2a519312009-02-10 21:25:55 +01009710void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009711 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009712{
9713 struct sk_buff *msg;
9714
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009715 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009716 if (!msg)
9717 return;
9718
Johannes Bergfd014282012-06-18 19:17:03 +02009719 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009720 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009721 nlmsg_free(msg);
9722 return;
9723 }
9724
Johannes Berg463d0182009-07-14 00:33:35 +02009725 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9726 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009727}
9728
9729void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009730 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009731{
9732 struct sk_buff *msg;
9733
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009734 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009735 if (!msg)
9736 return;
9737
Johannes Bergfd014282012-06-18 19:17:03 +02009738 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009739 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009740 nlmsg_free(msg);
9741 return;
9742 }
9743
Johannes Berg463d0182009-07-14 00:33:35 +02009744 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9745 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009746}
9747
Luciano Coelho807f8a82011-05-11 17:09:35 +03009748void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9749 struct net_device *netdev)
9750{
9751 struct sk_buff *msg;
9752
9753 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9754 if (!msg)
9755 return;
9756
9757 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9758 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9759 nlmsg_free(msg);
9760 return;
9761 }
9762
9763 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9764 nl80211_scan_mcgrp.id, GFP_KERNEL);
9765}
9766
9767void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9768 struct net_device *netdev, u32 cmd)
9769{
9770 struct sk_buff *msg;
9771
Thomas Graf58050fc2012-06-28 03:57:45 +00009772 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009773 if (!msg)
9774 return;
9775
9776 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9777 nlmsg_free(msg);
9778 return;
9779 }
9780
9781 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9782 nl80211_scan_mcgrp.id, GFP_KERNEL);
9783}
9784
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009785/*
9786 * This can happen on global regulatory changes or device specific settings
9787 * based on custom world regulatory domains.
9788 */
9789void nl80211_send_reg_change_event(struct regulatory_request *request)
9790{
9791 struct sk_buff *msg;
9792 void *hdr;
9793
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009794 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009795 if (!msg)
9796 return;
9797
9798 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9799 if (!hdr) {
9800 nlmsg_free(msg);
9801 return;
9802 }
9803
9804 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009805 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9806 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009807
David S. Miller9360ffd2012-03-29 04:41:26 -04009808 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9809 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9810 NL80211_REGDOM_TYPE_WORLD))
9811 goto nla_put_failure;
9812 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9813 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9814 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9815 goto nla_put_failure;
9816 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9817 request->intersect) {
9818 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9819 NL80211_REGDOM_TYPE_INTERSECTION))
9820 goto nla_put_failure;
9821 } else {
9822 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9823 NL80211_REGDOM_TYPE_COUNTRY) ||
9824 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9825 request->alpha2))
9826 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009827 }
9828
Johannes Bergf4173762012-12-03 18:23:37 +01009829 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009830 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9831 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009832
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009833 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009834
Johannes Bergbc43b282009-07-25 10:54:13 +02009835 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009836 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009837 GFP_ATOMIC);
9838 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009839
9840 return;
9841
9842nla_put_failure:
9843 genlmsg_cancel(msg, hdr);
9844 nlmsg_free(msg);
9845}
9846
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009847static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9848 struct net_device *netdev,
9849 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009850 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009851{
9852 struct sk_buff *msg;
9853 void *hdr;
9854
Johannes Berge6d6e342009-07-01 21:26:47 +02009855 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009856 if (!msg)
9857 return;
9858
9859 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9860 if (!hdr) {
9861 nlmsg_free(msg);
9862 return;
9863 }
9864
David S. Miller9360ffd2012-03-29 04:41:26 -04009865 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9866 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9867 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9868 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009869
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009870 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009871
Johannes Berg463d0182009-07-14 00:33:35 +02009872 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9873 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009874 return;
9875
9876 nla_put_failure:
9877 genlmsg_cancel(msg, hdr);
9878 nlmsg_free(msg);
9879}
9880
9881void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009882 struct net_device *netdev, const u8 *buf,
9883 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009884{
9885 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009886 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009887}
9888
9889void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9890 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009891 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009892{
Johannes Berge6d6e342009-07-01 21:26:47 +02009893 nl80211_send_mlme_event(rdev, netdev, buf, len,
9894 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009895}
9896
Jouni Malinen53b46b82009-03-27 20:53:56 +02009897void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009898 struct net_device *netdev, const u8 *buf,
9899 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009900{
9901 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009902 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009903}
9904
Jouni Malinen53b46b82009-03-27 20:53:56 +02009905void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9906 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009907 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009908{
9909 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009910 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009911}
9912
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009913void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9914 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009915{
Johannes Berg947add32013-02-22 22:05:20 +01009916 struct wireless_dev *wdev = dev->ieee80211_ptr;
9917 struct wiphy *wiphy = wdev->wiphy;
9918 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009919 const struct ieee80211_mgmt *mgmt = (void *)buf;
9920 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009921
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009922 if (WARN_ON(len < 2))
9923 return;
9924
9925 if (ieee80211_is_deauth(mgmt->frame_control))
9926 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9927 else
9928 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9929
9930 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9931 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009932}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009933EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009934
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009935static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9936 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009937 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009938{
9939 struct sk_buff *msg;
9940 void *hdr;
9941
Johannes Berge6d6e342009-07-01 21:26:47 +02009942 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009943 if (!msg)
9944 return;
9945
9946 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9947 if (!hdr) {
9948 nlmsg_free(msg);
9949 return;
9950 }
9951
David S. Miller9360ffd2012-03-29 04:41:26 -04009952 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9953 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9954 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9955 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9956 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009957
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009958 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009959
Johannes Berg463d0182009-07-14 00:33:35 +02009960 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9961 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009962 return;
9963
9964 nla_put_failure:
9965 genlmsg_cancel(msg, hdr);
9966 nlmsg_free(msg);
9967}
9968
9969void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009970 struct net_device *netdev, const u8 *addr,
9971 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009972{
9973 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009974 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009975}
9976
9977void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009978 struct net_device *netdev, const u8 *addr,
9979 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009980{
Johannes Berge6d6e342009-07-01 21:26:47 +02009981 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9982 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009983}
9984
Samuel Ortizb23aa672009-07-01 21:26:54 +02009985void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9986 struct net_device *netdev, const u8 *bssid,
9987 const u8 *req_ie, size_t req_ie_len,
9988 const u8 *resp_ie, size_t resp_ie_len,
9989 u16 status, gfp_t gfp)
9990{
9991 struct sk_buff *msg;
9992 void *hdr;
9993
Thomas Graf58050fc2012-06-28 03:57:45 +00009994 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009995 if (!msg)
9996 return;
9997
9998 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9999 if (!hdr) {
10000 nlmsg_free(msg);
10001 return;
10002 }
10003
David S. Miller9360ffd2012-03-29 04:41:26 -040010004 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10005 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10006 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10007 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10008 (req_ie &&
10009 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10010 (resp_ie &&
10011 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10012 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010013
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010014 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010015
Johannes Berg463d0182009-07-14 00:33:35 +020010016 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10017 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010018 return;
10019
10020 nla_put_failure:
10021 genlmsg_cancel(msg, hdr);
10022 nlmsg_free(msg);
10023
10024}
10025
10026void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10027 struct net_device *netdev, const u8 *bssid,
10028 const u8 *req_ie, size_t req_ie_len,
10029 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10030{
10031 struct sk_buff *msg;
10032 void *hdr;
10033
Thomas Graf58050fc2012-06-28 03:57:45 +000010034 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010035 if (!msg)
10036 return;
10037
10038 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10039 if (!hdr) {
10040 nlmsg_free(msg);
10041 return;
10042 }
10043
David S. Miller9360ffd2012-03-29 04:41:26 -040010044 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10045 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10046 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10047 (req_ie &&
10048 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10049 (resp_ie &&
10050 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10051 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010052
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010053 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010054
Johannes Berg463d0182009-07-14 00:33:35 +020010055 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10056 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010057 return;
10058
10059 nla_put_failure:
10060 genlmsg_cancel(msg, hdr);
10061 nlmsg_free(msg);
10062
10063}
10064
10065void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10066 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010067 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010068{
10069 struct sk_buff *msg;
10070 void *hdr;
10071
Thomas Graf58050fc2012-06-28 03:57:45 +000010072 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010073 if (!msg)
10074 return;
10075
10076 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10077 if (!hdr) {
10078 nlmsg_free(msg);
10079 return;
10080 }
10081
David S. Miller9360ffd2012-03-29 04:41:26 -040010082 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10083 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10084 (from_ap && reason &&
10085 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10086 (from_ap &&
10087 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10088 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10089 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010090
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010091 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010092
Johannes Berg463d0182009-07-14 00:33:35 +020010093 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10094 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010095 return;
10096
10097 nla_put_failure:
10098 genlmsg_cancel(msg, hdr);
10099 nlmsg_free(msg);
10100
10101}
10102
Johannes Berg04a773a2009-04-19 21:24:32 +020010103void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10104 struct net_device *netdev, const u8 *bssid,
10105 gfp_t gfp)
10106{
10107 struct sk_buff *msg;
10108 void *hdr;
10109
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010110 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010111 if (!msg)
10112 return;
10113
10114 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10115 if (!hdr) {
10116 nlmsg_free(msg);
10117 return;
10118 }
10119
David S. Miller9360ffd2012-03-29 04:41:26 -040010120 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10121 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10122 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10123 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010124
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010125 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010126
Johannes Berg463d0182009-07-14 00:33:35 +020010127 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10128 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010129 return;
10130
10131 nla_put_failure:
10132 genlmsg_cancel(msg, hdr);
10133 nlmsg_free(msg);
10134}
10135
Johannes Berg947add32013-02-22 22:05:20 +010010136void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10137 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010138{
Johannes Berg947add32013-02-22 22:05:20 +010010139 struct wireless_dev *wdev = dev->ieee80211_ptr;
10140 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010141 struct sk_buff *msg;
10142 void *hdr;
10143
Johannes Berg947add32013-02-22 22:05:20 +010010144 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10145 return;
10146
10147 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10148
Javier Cardonac93b5e72011-04-07 15:08:34 -070010149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10150 if (!msg)
10151 return;
10152
10153 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10154 if (!hdr) {
10155 nlmsg_free(msg);
10156 return;
10157 }
10158
David S. Miller9360ffd2012-03-29 04:41:26 -040010159 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010160 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10161 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010162 (ie_len && ie &&
10163 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10164 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010165
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010166 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010167
10168 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10169 nl80211_mlme_mcgrp.id, gfp);
10170 return;
10171
10172 nla_put_failure:
10173 genlmsg_cancel(msg, hdr);
10174 nlmsg_free(msg);
10175}
Johannes Berg947add32013-02-22 22:05:20 +010010176EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010177
Jouni Malinena3b8b052009-03-27 21:59:49 +020010178void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10179 struct net_device *netdev, const u8 *addr,
10180 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010181 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010182{
10183 struct sk_buff *msg;
10184 void *hdr;
10185
Johannes Berge6d6e342009-07-01 21:26:47 +020010186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010187 if (!msg)
10188 return;
10189
10190 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10191 if (!hdr) {
10192 nlmsg_free(msg);
10193 return;
10194 }
10195
David S. Miller9360ffd2012-03-29 04:41:26 -040010196 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10197 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10198 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10199 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10200 (key_id != -1 &&
10201 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10202 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10203 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010204
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010205 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010206
Johannes Berg463d0182009-07-14 00:33:35 +020010207 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10208 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010209 return;
10210
10211 nla_put_failure:
10212 genlmsg_cancel(msg, hdr);
10213 nlmsg_free(msg);
10214}
10215
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010216void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10217 struct ieee80211_channel *channel_before,
10218 struct ieee80211_channel *channel_after)
10219{
10220 struct sk_buff *msg;
10221 void *hdr;
10222 struct nlattr *nl_freq;
10223
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010225 if (!msg)
10226 return;
10227
10228 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10229 if (!hdr) {
10230 nlmsg_free(msg);
10231 return;
10232 }
10233
10234 /*
10235 * Since we are applying the beacon hint to a wiphy we know its
10236 * wiphy_idx is valid
10237 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010238 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10239 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010240
10241 /* Before */
10242 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10243 if (!nl_freq)
10244 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010245 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010246 goto nla_put_failure;
10247 nla_nest_end(msg, nl_freq);
10248
10249 /* After */
10250 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10251 if (!nl_freq)
10252 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010253 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010254 goto nla_put_failure;
10255 nla_nest_end(msg, nl_freq);
10256
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010257 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010258
Johannes Berg463d0182009-07-14 00:33:35 +020010259 rcu_read_lock();
10260 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10261 GFP_ATOMIC);
10262 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010263
10264 return;
10265
10266nla_put_failure:
10267 genlmsg_cancel(msg, hdr);
10268 nlmsg_free(msg);
10269}
10270
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010271static void nl80211_send_remain_on_chan_event(
10272 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010273 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010274 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010275 unsigned int duration, gfp_t gfp)
10276{
10277 struct sk_buff *msg;
10278 void *hdr;
10279
10280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10281 if (!msg)
10282 return;
10283
10284 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10285 if (!hdr) {
10286 nlmsg_free(msg);
10287 return;
10288 }
10289
David S. Miller9360ffd2012-03-29 04:41:26 -040010290 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010291 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10292 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010293 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010294 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010295 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10296 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010297 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10298 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010299
David S. Miller9360ffd2012-03-29 04:41:26 -040010300 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10301 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10302 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010303
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010304 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010305
10306 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10307 nl80211_mlme_mcgrp.id, gfp);
10308 return;
10309
10310 nla_put_failure:
10311 genlmsg_cancel(msg, hdr);
10312 nlmsg_free(msg);
10313}
10314
Johannes Berg947add32013-02-22 22:05:20 +010010315void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10316 struct ieee80211_channel *chan,
10317 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010318{
Johannes Berg947add32013-02-22 22:05:20 +010010319 struct wiphy *wiphy = wdev->wiphy;
10320 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10321
10322 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010323 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010324 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010325 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010326}
Johannes Berg947add32013-02-22 22:05:20 +010010327EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010328
Johannes Berg947add32013-02-22 22:05:20 +010010329void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10330 struct ieee80211_channel *chan,
10331 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010332{
Johannes Berg947add32013-02-22 22:05:20 +010010333 struct wiphy *wiphy = wdev->wiphy;
10334 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10335
10336 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010337 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010338 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010339}
Johannes Berg947add32013-02-22 22:05:20 +010010340EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010341
Johannes Berg947add32013-02-22 22:05:20 +010010342void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10343 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010344{
Johannes Berg947add32013-02-22 22:05:20 +010010345 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10346 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010347 struct sk_buff *msg;
10348
Johannes Berg947add32013-02-22 22:05:20 +010010349 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10350
Thomas Graf58050fc2012-06-28 03:57:45 +000010351 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010352 if (!msg)
10353 return;
10354
John W. Linville66266b32012-03-15 13:25:41 -040010355 if (nl80211_send_station(msg, 0, 0, 0,
10356 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010357 nlmsg_free(msg);
10358 return;
10359 }
10360
10361 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10362 nl80211_mlme_mcgrp.id, gfp);
10363}
Johannes Berg947add32013-02-22 22:05:20 +010010364EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010365
Johannes Berg947add32013-02-22 22:05:20 +010010366void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010367{
Johannes Berg947add32013-02-22 22:05:20 +010010368 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10369 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010370 struct sk_buff *msg;
10371 void *hdr;
10372
Johannes Berg947add32013-02-22 22:05:20 +010010373 trace_cfg80211_del_sta(dev, mac_addr);
10374
Thomas Graf58050fc2012-06-28 03:57:45 +000010375 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010376 if (!msg)
10377 return;
10378
10379 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10380 if (!hdr) {
10381 nlmsg_free(msg);
10382 return;
10383 }
10384
David S. Miller9360ffd2012-03-29 04:41:26 -040010385 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10386 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10387 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010388
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010389 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010390
10391 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10392 nl80211_mlme_mcgrp.id, gfp);
10393 return;
10394
10395 nla_put_failure:
10396 genlmsg_cancel(msg, hdr);
10397 nlmsg_free(msg);
10398}
Johannes Berg947add32013-02-22 22:05:20 +010010399EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010400
Johannes Berg947add32013-02-22 22:05:20 +010010401void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10402 enum nl80211_connect_failed_reason reason,
10403 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010404{
Johannes Berg947add32013-02-22 22:05:20 +010010405 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10406 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010407 struct sk_buff *msg;
10408 void *hdr;
10409
10410 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10411 if (!msg)
10412 return;
10413
10414 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10415 if (!hdr) {
10416 nlmsg_free(msg);
10417 return;
10418 }
10419
10420 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10421 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10422 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10423 goto nla_put_failure;
10424
10425 genlmsg_end(msg, hdr);
10426
10427 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10428 nl80211_mlme_mcgrp.id, gfp);
10429 return;
10430
10431 nla_put_failure:
10432 genlmsg_cancel(msg, hdr);
10433 nlmsg_free(msg);
10434}
Johannes Berg947add32013-02-22 22:05:20 +010010435EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010436
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010437static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10438 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010439{
10440 struct wireless_dev *wdev = dev->ieee80211_ptr;
10441 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10442 struct sk_buff *msg;
10443 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010444 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010445
Eric W. Biederman15e47302012-09-07 20:12:54 +000010446 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010447 return false;
10448
10449 msg = nlmsg_new(100, gfp);
10450 if (!msg)
10451 return true;
10452
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010453 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010454 if (!hdr) {
10455 nlmsg_free(msg);
10456 return true;
10457 }
10458
David S. Miller9360ffd2012-03-29 04:41:26 -040010459 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10460 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10461 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10462 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010463
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010464 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010465 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010466 return true;
10467
10468 nla_put_failure:
10469 genlmsg_cancel(msg, hdr);
10470 nlmsg_free(msg);
10471 return true;
10472}
10473
Johannes Berg947add32013-02-22 22:05:20 +010010474bool cfg80211_rx_spurious_frame(struct net_device *dev,
10475 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010476{
Johannes Berg947add32013-02-22 22:05:20 +010010477 struct wireless_dev *wdev = dev->ieee80211_ptr;
10478 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010479
Johannes Berg947add32013-02-22 22:05:20 +010010480 trace_cfg80211_rx_spurious_frame(dev, addr);
10481
10482 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10483 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10484 trace_cfg80211_return_bool(false);
10485 return false;
10486 }
10487 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10488 addr, gfp);
10489 trace_cfg80211_return_bool(ret);
10490 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010491}
Johannes Berg947add32013-02-22 22:05:20 +010010492EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10493
10494bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10495 const u8 *addr, gfp_t gfp)
10496{
10497 struct wireless_dev *wdev = dev->ieee80211_ptr;
10498 bool ret;
10499
10500 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10501
10502 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10503 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10504 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10505 trace_cfg80211_return_bool(false);
10506 return false;
10507 }
10508 ret = __nl80211_unexpected_frame(dev,
10509 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10510 addr, gfp);
10511 trace_cfg80211_return_bool(ret);
10512 return ret;
10513}
10514EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010515
Johannes Berg2e161f72010-08-12 15:38:38 +020010516int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010517 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010518 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010519 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010520{
Johannes Berg71bbc992012-06-15 15:30:18 +020010521 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010522 struct sk_buff *msg;
10523 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010524
10525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10526 if (!msg)
10527 return -ENOMEM;
10528
Johannes Berg2e161f72010-08-12 15:38:38 +020010529 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010530 if (!hdr) {
10531 nlmsg_free(msg);
10532 return -ENOMEM;
10533 }
10534
David S. Miller9360ffd2012-03-29 04:41:26 -040010535 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010536 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10537 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010538 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010539 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10540 (sig_dbm &&
10541 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010542 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10543 (flags &&
10544 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010545 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010546
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010547 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010548
Eric W. Biederman15e47302012-09-07 20:12:54 +000010549 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010550
10551 nla_put_failure:
10552 genlmsg_cancel(msg, hdr);
10553 nlmsg_free(msg);
10554 return -ENOBUFS;
10555}
10556
Johannes Berg947add32013-02-22 22:05:20 +010010557void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10558 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010559{
Johannes Berg947add32013-02-22 22:05:20 +010010560 struct wiphy *wiphy = wdev->wiphy;
10561 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010562 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010563 struct sk_buff *msg;
10564 void *hdr;
10565
Johannes Berg947add32013-02-22 22:05:20 +010010566 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10567
Jouni Malinen026331c2010-02-15 12:53:10 +020010568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10569 if (!msg)
10570 return;
10571
Johannes Berg2e161f72010-08-12 15:38:38 +020010572 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010573 if (!hdr) {
10574 nlmsg_free(msg);
10575 return;
10576 }
10577
David S. Miller9360ffd2012-03-29 04:41:26 -040010578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010579 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10580 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010581 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010582 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10583 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10584 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10585 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010586
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010587 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010588
Michal Kaziora0ec5702013-06-25 09:17:17 +020010589 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10590 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010591 return;
10592
10593 nla_put_failure:
10594 genlmsg_cancel(msg, hdr);
10595 nlmsg_free(msg);
10596}
Johannes Berg947add32013-02-22 22:05:20 +010010597EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010598
Johannes Berg947add32013-02-22 22:05:20 +010010599void cfg80211_cqm_rssi_notify(struct net_device *dev,
10600 enum nl80211_cqm_rssi_threshold_event rssi_event,
10601 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010602{
Johannes Berg947add32013-02-22 22:05:20 +010010603 struct wireless_dev *wdev = dev->ieee80211_ptr;
10604 struct wiphy *wiphy = wdev->wiphy;
10605 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010606 struct sk_buff *msg;
10607 struct nlattr *pinfoattr;
10608 void *hdr;
10609
Johannes Berg947add32013-02-22 22:05:20 +010010610 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10611
Thomas Graf58050fc2012-06-28 03:57:45 +000010612 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010613 if (!msg)
10614 return;
10615
10616 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10617 if (!hdr) {
10618 nlmsg_free(msg);
10619 return;
10620 }
10621
David S. Miller9360ffd2012-03-29 04:41:26 -040010622 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010623 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010624 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010625
10626 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10627 if (!pinfoattr)
10628 goto nla_put_failure;
10629
David S. Miller9360ffd2012-03-29 04:41:26 -040010630 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10631 rssi_event))
10632 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010633
10634 nla_nest_end(msg, pinfoattr);
10635
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010636 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010637
10638 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10639 nl80211_mlme_mcgrp.id, gfp);
10640 return;
10641
10642 nla_put_failure:
10643 genlmsg_cancel(msg, hdr);
10644 nlmsg_free(msg);
10645}
Johannes Berg947add32013-02-22 22:05:20 +010010646EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010647
Johannes Berg947add32013-02-22 22:05:20 +010010648static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10649 struct net_device *netdev, const u8 *bssid,
10650 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010651{
10652 struct sk_buff *msg;
10653 struct nlattr *rekey_attr;
10654 void *hdr;
10655
Thomas Graf58050fc2012-06-28 03:57:45 +000010656 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010657 if (!msg)
10658 return;
10659
10660 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10661 if (!hdr) {
10662 nlmsg_free(msg);
10663 return;
10664 }
10665
David S. Miller9360ffd2012-03-29 04:41:26 -040010666 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10667 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10668 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10669 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010670
10671 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10672 if (!rekey_attr)
10673 goto nla_put_failure;
10674
David S. Miller9360ffd2012-03-29 04:41:26 -040010675 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10676 NL80211_REPLAY_CTR_LEN, replay_ctr))
10677 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010678
10679 nla_nest_end(msg, rekey_attr);
10680
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010681 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010682
10683 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10684 nl80211_mlme_mcgrp.id, gfp);
10685 return;
10686
10687 nla_put_failure:
10688 genlmsg_cancel(msg, hdr);
10689 nlmsg_free(msg);
10690}
10691
Johannes Berg947add32013-02-22 22:05:20 +010010692void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10693 const u8 *replay_ctr, gfp_t gfp)
10694{
10695 struct wireless_dev *wdev = dev->ieee80211_ptr;
10696 struct wiphy *wiphy = wdev->wiphy;
10697 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10698
10699 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10700 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10701}
10702EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10703
10704static void
10705nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10706 struct net_device *netdev, int index,
10707 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010708{
10709 struct sk_buff *msg;
10710 struct nlattr *attr;
10711 void *hdr;
10712
Thomas Graf58050fc2012-06-28 03:57:45 +000010713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010714 if (!msg)
10715 return;
10716
10717 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10718 if (!hdr) {
10719 nlmsg_free(msg);
10720 return;
10721 }
10722
David S. Miller9360ffd2012-03-29 04:41:26 -040010723 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10724 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10725 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010726
10727 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10728 if (!attr)
10729 goto nla_put_failure;
10730
David S. Miller9360ffd2012-03-29 04:41:26 -040010731 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10732 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10733 (preauth &&
10734 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10735 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010736
10737 nla_nest_end(msg, attr);
10738
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010739 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010740
10741 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10742 nl80211_mlme_mcgrp.id, gfp);
10743 return;
10744
10745 nla_put_failure:
10746 genlmsg_cancel(msg, hdr);
10747 nlmsg_free(msg);
10748}
10749
Johannes Berg947add32013-02-22 22:05:20 +010010750void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10751 const u8 *bssid, bool preauth, gfp_t gfp)
10752{
10753 struct wireless_dev *wdev = dev->ieee80211_ptr;
10754 struct wiphy *wiphy = wdev->wiphy;
10755 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10756
10757 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10758 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10759}
10760EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10761
10762static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10763 struct net_device *netdev,
10764 struct cfg80211_chan_def *chandef,
10765 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010766{
10767 struct sk_buff *msg;
10768 void *hdr;
10769
Thomas Graf58050fc2012-06-28 03:57:45 +000010770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010771 if (!msg)
10772 return;
10773
10774 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10775 if (!hdr) {
10776 nlmsg_free(msg);
10777 return;
10778 }
10779
Johannes Berg683b6d32012-11-08 21:25:48 +010010780 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10781 goto nla_put_failure;
10782
10783 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010784 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010785
10786 genlmsg_end(msg, hdr);
10787
10788 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10789 nl80211_mlme_mcgrp.id, gfp);
10790 return;
10791
10792 nla_put_failure:
10793 genlmsg_cancel(msg, hdr);
10794 nlmsg_free(msg);
10795}
10796
Johannes Berg947add32013-02-22 22:05:20 +010010797void cfg80211_ch_switch_notify(struct net_device *dev,
10798 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010799{
Johannes Berg947add32013-02-22 22:05:20 +010010800 struct wireless_dev *wdev = dev->ieee80211_ptr;
10801 struct wiphy *wiphy = wdev->wiphy;
10802 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10803
10804 trace_cfg80211_ch_switch_notify(dev, chandef);
10805
10806 wdev_lock(wdev);
10807
10808 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020010809 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070010810 wdev->iftype != NL80211_IFTYPE_ADHOC &&
10811 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Johannes Berg947add32013-02-22 22:05:20 +010010812 goto out;
10813
10814 wdev->channel = chandef->chan;
10815 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10816out:
10817 wdev_unlock(wdev);
10818 return;
10819}
10820EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10821
10822void cfg80211_cqm_txe_notify(struct net_device *dev,
10823 const u8 *peer, u32 num_packets,
10824 u32 rate, u32 intvl, gfp_t gfp)
10825{
10826 struct wireless_dev *wdev = dev->ieee80211_ptr;
10827 struct wiphy *wiphy = wdev->wiphy;
10828 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010829 struct sk_buff *msg;
10830 struct nlattr *pinfoattr;
10831 void *hdr;
10832
10833 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10834 if (!msg)
10835 return;
10836
10837 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10838 if (!hdr) {
10839 nlmsg_free(msg);
10840 return;
10841 }
10842
10843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010845 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10846 goto nla_put_failure;
10847
10848 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10849 if (!pinfoattr)
10850 goto nla_put_failure;
10851
10852 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10853 goto nla_put_failure;
10854
10855 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10856 goto nla_put_failure;
10857
10858 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10859 goto nla_put_failure;
10860
10861 nla_nest_end(msg, pinfoattr);
10862
10863 genlmsg_end(msg, hdr);
10864
10865 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10866 nl80211_mlme_mcgrp.id, gfp);
10867 return;
10868
10869 nla_put_failure:
10870 genlmsg_cancel(msg, hdr);
10871 nlmsg_free(msg);
10872}
Johannes Berg947add32013-02-22 22:05:20 +010010873EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010874
10875void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010876nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10877 struct cfg80211_chan_def *chandef,
10878 enum nl80211_radar_event event,
10879 struct net_device *netdev, gfp_t gfp)
10880{
10881 struct sk_buff *msg;
10882 void *hdr;
10883
10884 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10885 if (!msg)
10886 return;
10887
10888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10889 if (!hdr) {
10890 nlmsg_free(msg);
10891 return;
10892 }
10893
10894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10895 goto nla_put_failure;
10896
10897 /* NOP and radar events don't need a netdev parameter */
10898 if (netdev) {
10899 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10900
10901 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10902 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10903 goto nla_put_failure;
10904 }
10905
10906 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10907 goto nla_put_failure;
10908
10909 if (nl80211_send_chandef(msg, chandef))
10910 goto nla_put_failure;
10911
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010912 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010913
10914 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10915 nl80211_mlme_mcgrp.id, gfp);
10916 return;
10917
10918 nla_put_failure:
10919 genlmsg_cancel(msg, hdr);
10920 nlmsg_free(msg);
10921}
10922
Johannes Berg947add32013-02-22 22:05:20 +010010923void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10924 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010925{
Johannes Berg947add32013-02-22 22:05:20 +010010926 struct wireless_dev *wdev = dev->ieee80211_ptr;
10927 struct wiphy *wiphy = wdev->wiphy;
10928 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010929 struct sk_buff *msg;
10930 struct nlattr *pinfoattr;
10931 void *hdr;
10932
Johannes Berg947add32013-02-22 22:05:20 +010010933 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10934
Thomas Graf58050fc2012-06-28 03:57:45 +000010935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010936 if (!msg)
10937 return;
10938
10939 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10940 if (!hdr) {
10941 nlmsg_free(msg);
10942 return;
10943 }
10944
David S. Miller9360ffd2012-03-29 04:41:26 -040010945 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010946 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010947 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10948 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010949
10950 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10951 if (!pinfoattr)
10952 goto nla_put_failure;
10953
David S. Miller9360ffd2012-03-29 04:41:26 -040010954 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10955 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010956
10957 nla_nest_end(msg, pinfoattr);
10958
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010959 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010960
10961 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10962 nl80211_mlme_mcgrp.id, gfp);
10963 return;
10964
10965 nla_put_failure:
10966 genlmsg_cancel(msg, hdr);
10967 nlmsg_free(msg);
10968}
Johannes Berg947add32013-02-22 22:05:20 +010010969EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010970
Johannes Berg7f6cf312011-11-04 11:18:15 +010010971void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10972 u64 cookie, bool acked, gfp_t gfp)
10973{
10974 struct wireless_dev *wdev = dev->ieee80211_ptr;
10975 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10976 struct sk_buff *msg;
10977 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010978
Beni Lev4ee3e062012-08-27 12:49:39 +030010979 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10980
Thomas Graf58050fc2012-06-28 03:57:45 +000010981 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010982
Johannes Berg7f6cf312011-11-04 11:18:15 +010010983 if (!msg)
10984 return;
10985
10986 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10987 if (!hdr) {
10988 nlmsg_free(msg);
10989 return;
10990 }
10991
David S. Miller9360ffd2012-03-29 04:41:26 -040010992 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10994 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10995 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10996 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10997 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010998
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010999 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011000
11001 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11002 nl80211_mlme_mcgrp.id, gfp);
11003 return;
11004
11005 nla_put_failure:
11006 genlmsg_cancel(msg, hdr);
11007 nlmsg_free(msg);
11008}
11009EXPORT_SYMBOL(cfg80211_probe_status);
11010
Johannes Berg5e7602302011-11-04 11:18:17 +010011011void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11012 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011013 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010011014{
11015 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11016 struct sk_buff *msg;
11017 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011018 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010011019
Beni Lev4ee3e062012-08-27 12:49:39 +030011020 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11021
Ben Greear37c73b52012-10-26 14:49:25 -070011022 spin_lock_bh(&rdev->beacon_registrations_lock);
11023 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11024 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11025 if (!msg) {
11026 spin_unlock_bh(&rdev->beacon_registrations_lock);
11027 return;
11028 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011029
Ben Greear37c73b52012-10-26 14:49:25 -070011030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11031 if (!hdr)
11032 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010011033
Ben Greear37c73b52012-10-26 14:49:25 -070011034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11035 (freq &&
11036 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11037 (sig_dbm &&
11038 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11039 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11040 goto nla_put_failure;
11041
11042 genlmsg_end(msg, hdr);
11043
11044 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010011045 }
Ben Greear37c73b52012-10-26 14:49:25 -070011046 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011047 return;
11048
11049 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011050 spin_unlock_bh(&rdev->beacon_registrations_lock);
11051 if (hdr)
11052 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011053 nlmsg_free(msg);
11054}
11055EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11056
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011057#ifdef CONFIG_PM
11058void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11059 struct cfg80211_wowlan_wakeup *wakeup,
11060 gfp_t gfp)
11061{
11062 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11063 struct sk_buff *msg;
11064 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011065 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011066
11067 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11068
11069 if (wakeup)
11070 size += wakeup->packet_present_len;
11071
11072 msg = nlmsg_new(size, gfp);
11073 if (!msg)
11074 return;
11075
11076 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11077 if (!hdr)
11078 goto free_msg;
11079
11080 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11081 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11082 goto free_msg;
11083
11084 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11085 wdev->netdev->ifindex))
11086 goto free_msg;
11087
11088 if (wakeup) {
11089 struct nlattr *reasons;
11090
11091 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11092
11093 if (wakeup->disconnect &&
11094 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11095 goto free_msg;
11096 if (wakeup->magic_pkt &&
11097 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11098 goto free_msg;
11099 if (wakeup->gtk_rekey_failure &&
11100 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11101 goto free_msg;
11102 if (wakeup->eap_identity_req &&
11103 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11104 goto free_msg;
11105 if (wakeup->four_way_handshake &&
11106 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11107 goto free_msg;
11108 if (wakeup->rfkill_release &&
11109 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11110 goto free_msg;
11111
11112 if (wakeup->pattern_idx >= 0 &&
11113 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11114 wakeup->pattern_idx))
11115 goto free_msg;
11116
Johannes Berg2a0e0472013-01-23 22:57:40 +010011117 if (wakeup->tcp_match)
11118 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11119
11120 if (wakeup->tcp_connlost)
11121 nla_put_flag(msg,
11122 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11123
11124 if (wakeup->tcp_nomoretokens)
11125 nla_put_flag(msg,
11126 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11127
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011128 if (wakeup->packet) {
11129 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11130 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11131
11132 if (!wakeup->packet_80211) {
11133 pkt_attr =
11134 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11135 len_attr =
11136 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11137 }
11138
11139 if (wakeup->packet_len &&
11140 nla_put_u32(msg, len_attr, wakeup->packet_len))
11141 goto free_msg;
11142
11143 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11144 wakeup->packet))
11145 goto free_msg;
11146 }
11147
11148 nla_nest_end(msg, reasons);
11149 }
11150
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011151 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011152
11153 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11154 nl80211_mlme_mcgrp.id, gfp);
11155 return;
11156
11157 free_msg:
11158 nlmsg_free(msg);
11159}
11160EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11161#endif
11162
Jouni Malinen3475b092012-11-16 22:49:57 +020011163void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11164 enum nl80211_tdls_operation oper,
11165 u16 reason_code, gfp_t gfp)
11166{
11167 struct wireless_dev *wdev = dev->ieee80211_ptr;
11168 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11169 struct sk_buff *msg;
11170 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011171
11172 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11173 reason_code);
11174
11175 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11176 if (!msg)
11177 return;
11178
11179 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11180 if (!hdr) {
11181 nlmsg_free(msg);
11182 return;
11183 }
11184
11185 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11186 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11187 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11188 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11189 (reason_code > 0 &&
11190 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11191 goto nla_put_failure;
11192
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011193 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011194
11195 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11196 nl80211_mlme_mcgrp.id, gfp);
11197 return;
11198
11199 nla_put_failure:
11200 genlmsg_cancel(msg, hdr);
11201 nlmsg_free(msg);
11202}
11203EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11204
Jouni Malinen026331c2010-02-15 12:53:10 +020011205static int nl80211_netlink_notify(struct notifier_block * nb,
11206 unsigned long state,
11207 void *_notify)
11208{
11209 struct netlink_notify *notify = _notify;
11210 struct cfg80211_registered_device *rdev;
11211 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011212 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011213
11214 if (state != NETLINK_URELEASE)
11215 return NOTIFY_DONE;
11216
11217 rcu_read_lock();
11218
Johannes Berg5e7602302011-11-04 11:18:17 +010011219 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011220 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011221 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011222
11223 spin_lock_bh(&rdev->beacon_registrations_lock);
11224 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11225 list) {
11226 if (reg->nlportid == notify->portid) {
11227 list_del(&reg->list);
11228 kfree(reg);
11229 break;
11230 }
11231 }
11232 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011233 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011234
11235 rcu_read_unlock();
11236
11237 return NOTIFY_DONE;
11238}
11239
11240static struct notifier_block nl80211_netlink_notifier = {
11241 .notifier_call = nl80211_netlink_notify,
11242};
11243
Jouni Malinen355199e2013-02-27 17:14:27 +020011244void cfg80211_ft_event(struct net_device *netdev,
11245 struct cfg80211_ft_event_params *ft_event)
11246{
11247 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11248 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11249 struct sk_buff *msg;
11250 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011251
11252 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11253
11254 if (!ft_event->target_ap)
11255 return;
11256
11257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11258 if (!msg)
11259 return;
11260
11261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11262 if (!hdr) {
11263 nlmsg_free(msg);
11264 return;
11265 }
11266
11267 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11268 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11269 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11270 if (ft_event->ies)
11271 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11272 if (ft_event->ric_ies)
11273 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11274 ft_event->ric_ies);
11275
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011276 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011277
11278 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11279 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11280}
11281EXPORT_SYMBOL(cfg80211_ft_event);
11282
Arend van Spriel5de17982013-04-18 15:49:00 +020011283void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11284{
11285 struct cfg80211_registered_device *rdev;
11286 struct sk_buff *msg;
11287 void *hdr;
11288 u32 nlportid;
11289
11290 rdev = wiphy_to_dev(wdev->wiphy);
11291 if (!rdev->crit_proto_nlportid)
11292 return;
11293
11294 nlportid = rdev->crit_proto_nlportid;
11295 rdev->crit_proto_nlportid = 0;
11296
11297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11298 if (!msg)
11299 return;
11300
11301 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11302 if (!hdr)
11303 goto nla_put_failure;
11304
11305 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11306 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11307 goto nla_put_failure;
11308
11309 genlmsg_end(msg, hdr);
11310
11311 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11312 return;
11313
11314 nla_put_failure:
11315 if (hdr)
11316 genlmsg_cancel(msg, hdr);
11317 nlmsg_free(msg);
11318
11319}
11320EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11321
Johannes Berg55682962007-09-20 13:09:35 -040011322/* initialisation/exit functions */
11323
11324int nl80211_init(void)
11325{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011326 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011327
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011328 err = genl_register_family_with_ops(&nl80211_fam,
11329 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011330 if (err)
11331 return err;
11332
Johannes Berg55682962007-09-20 13:09:35 -040011333 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11334 if (err)
11335 goto err_out;
11336
Johannes Berg2a519312009-02-10 21:25:55 +010011337 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11338 if (err)
11339 goto err_out;
11340
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011341 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11342 if (err)
11343 goto err_out;
11344
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011345 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11346 if (err)
11347 goto err_out;
11348
Johannes Bergaff89a92009-07-01 21:26:51 +020011349#ifdef CONFIG_NL80211_TESTMODE
11350 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11351 if (err)
11352 goto err_out;
11353#endif
11354
Jouni Malinen026331c2010-02-15 12:53:10 +020011355 err = netlink_register_notifier(&nl80211_netlink_notifier);
11356 if (err)
11357 goto err_out;
11358
Johannes Berg55682962007-09-20 13:09:35 -040011359 return 0;
11360 err_out:
11361 genl_unregister_family(&nl80211_fam);
11362 return err;
11363}
11364
11365void nl80211_exit(void)
11366{
Jouni Malinen026331c2010-02-15 12:53:10 +020011367 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011368 genl_unregister_family(&nl80211_fam);
11369}