blob: 2838206ddad3b5b05ea2eb2a6bfbc281593f9b41 [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 },
Johannes Berg55682962007-09-20 13:09:35 -0400357};
358
Johannes Berge31b8212010-10-05 19:39:30 +0200359/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000360static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200361 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200362 [NL80211_KEY_IDX] = { .type = NLA_U8 },
363 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200364 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200365 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
366 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200367 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100368 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
369};
370
371/* policy for the key default flags */
372static const struct nla_policy
373nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
374 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
375 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200376};
377
Johannes Bergff1b6e62011-05-04 15:37:28 +0200378/* policy for WoWLAN attributes */
379static const struct nla_policy
380nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
381 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
384 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200385 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
386 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
387 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
388 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100389 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
390};
391
392static const struct nla_policy
393nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
394 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
395 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
396 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
397 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
398 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
399 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
400 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
401 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
402 },
403 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
404 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
405 },
406 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
407 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
408 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200409};
410
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700411/* policy for coalesce rule attributes */
412static const struct nla_policy
413nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
414 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
415 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
416 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
417};
418
Johannes Berge5497d72011-07-05 16:35:40 +0200419/* policy for GTK rekey offload attributes */
420static const struct nla_policy
421nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
422 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
423 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
424 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
425};
426
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300427static const struct nla_policy
428nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200429 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300430 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700431 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300432};
433
Johannes Berg97990a02013-04-19 01:02:55 +0200434static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
435 struct netlink_callback *cb,
436 struct cfg80211_registered_device **rdev,
437 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100438{
Johannes Berg67748892010-10-04 21:14:06 +0200439 int err;
440
Johannes Berg67748892010-10-04 21:14:06 +0200441 rtnl_lock();
442
Johannes Berg97990a02013-04-19 01:02:55 +0200443 if (!cb->args[0]) {
444 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
445 nl80211_fam.attrbuf, nl80211_fam.maxattr,
446 nl80211_policy);
447 if (err)
448 goto out_unlock;
449
450 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
451 nl80211_fam.attrbuf);
452 if (IS_ERR(*wdev)) {
453 err = PTR_ERR(*wdev);
454 goto out_unlock;
455 }
456 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200457 /* 0 is the first index - add 1 to parse only once */
458 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200459 cb->args[1] = (*wdev)->identifier;
460 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200461 /* subtract the 1 again here */
462 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200463 struct wireless_dev *tmp;
464
465 if (!wiphy) {
466 err = -ENODEV;
467 goto out_unlock;
468 }
469 *rdev = wiphy_to_dev(wiphy);
470 *wdev = NULL;
471
Johannes Berg97990a02013-04-19 01:02:55 +0200472 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
473 if (tmp->identifier == cb->args[1]) {
474 *wdev = tmp;
475 break;
476 }
477 }
Johannes Berg97990a02013-04-19 01:02:55 +0200478
479 if (!*wdev) {
480 err = -ENODEV;
481 goto out_unlock;
482 }
Johannes Berg67748892010-10-04 21:14:06 +0200483 }
484
Johannes Berg67748892010-10-04 21:14:06 +0200485 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200486 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200487 rtnl_unlock();
488 return err;
489}
490
Johannes Berg97990a02013-04-19 01:02:55 +0200491static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200492{
Johannes Berg67748892010-10-04 21:14:06 +0200493 rtnl_unlock();
494}
495
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100496/* IE validation */
497static bool is_valid_ie_attr(const struct nlattr *attr)
498{
499 const u8 *pos;
500 int len;
501
502 if (!attr)
503 return true;
504
505 pos = nla_data(attr);
506 len = nla_len(attr);
507
508 while (len) {
509 u8 elemlen;
510
511 if (len < 2)
512 return false;
513 len -= 2;
514
515 elemlen = pos[1];
516 if (elemlen > len)
517 return false;
518
519 len -= elemlen;
520 pos += 2 + elemlen;
521 }
522
523 return true;
524}
525
Johannes Berg55682962007-09-20 13:09:35 -0400526/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000527static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400528 int flags, u8 cmd)
529{
530 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000531 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400532}
533
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400534static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100535 struct ieee80211_channel *chan,
536 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400537{
David S. Miller9360ffd2012-03-29 04:41:26 -0400538 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
539 chan->center_freq))
540 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400541
David S. Miller9360ffd2012-03-29 04:41:26 -0400542 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
543 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
544 goto nla_put_failure;
545 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
546 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
547 goto nla_put_failure;
548 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
549 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
550 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100551 if (chan->flags & IEEE80211_CHAN_RADAR) {
552 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
553 goto nla_put_failure;
554 if (large) {
555 u32 time;
556
557 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
558
559 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
560 chan->dfs_state))
561 goto nla_put_failure;
562 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
563 time))
564 goto nla_put_failure;
565 }
566 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400567
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100568 if (large) {
569 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
570 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
571 goto nla_put_failure;
572 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
573 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
574 goto nla_put_failure;
575 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
576 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
577 goto nla_put_failure;
578 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
579 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
580 goto nla_put_failure;
581 }
582
David S. Miller9360ffd2012-03-29 04:41:26 -0400583 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
584 DBM_TO_MBM(chan->max_power)))
585 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400586
587 return 0;
588
589 nla_put_failure:
590 return -ENOBUFS;
591}
592
Johannes Berg55682962007-09-20 13:09:35 -0400593/* netlink command implementations */
594
Johannes Bergb9454e82009-07-08 13:29:08 +0200595struct key_parse {
596 struct key_params p;
597 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200598 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200599 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100600 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200601};
602
603static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
604{
605 struct nlattr *tb[NL80211_KEY_MAX + 1];
606 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
607 nl80211_key_policy);
608 if (err)
609 return err;
610
611 k->def = !!tb[NL80211_KEY_DEFAULT];
612 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
613
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100614 if (k->def) {
615 k->def_uni = true;
616 k->def_multi = true;
617 }
618 if (k->defmgmt)
619 k->def_multi = true;
620
Johannes Bergb9454e82009-07-08 13:29:08 +0200621 if (tb[NL80211_KEY_IDX])
622 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
623
624 if (tb[NL80211_KEY_DATA]) {
625 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
626 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
627 }
628
629 if (tb[NL80211_KEY_SEQ]) {
630 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
631 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
632 }
633
634 if (tb[NL80211_KEY_CIPHER])
635 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
636
Johannes Berge31b8212010-10-05 19:39:30 +0200637 if (tb[NL80211_KEY_TYPE]) {
638 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
639 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
640 return -EINVAL;
641 }
642
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100643 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
644 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100645 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
646 tb[NL80211_KEY_DEFAULT_TYPES],
647 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100648 if (err)
649 return err;
650
651 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
652 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
653 }
654
Johannes Bergb9454e82009-07-08 13:29:08 +0200655 return 0;
656}
657
658static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
659{
660 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
661 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
662 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
663 }
664
665 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
666 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
667 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
668 }
669
670 if (info->attrs[NL80211_ATTR_KEY_IDX])
671 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
672
673 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
674 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
675
676 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
677 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
678
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100679 if (k->def) {
680 k->def_uni = true;
681 k->def_multi = true;
682 }
683 if (k->defmgmt)
684 k->def_multi = true;
685
Johannes Berge31b8212010-10-05 19:39:30 +0200686 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
687 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
688 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
689 return -EINVAL;
690 }
691
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100692 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
693 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
694 int err = nla_parse_nested(
695 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
696 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
697 nl80211_key_default_policy);
698 if (err)
699 return err;
700
701 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
702 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
703 }
704
Johannes Bergb9454e82009-07-08 13:29:08 +0200705 return 0;
706}
707
708static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
709{
710 int err;
711
712 memset(k, 0, sizeof(*k));
713 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200714 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200715
716 if (info->attrs[NL80211_ATTR_KEY])
717 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
718 else
719 err = nl80211_parse_key_old(info, k);
720
721 if (err)
722 return err;
723
724 if (k->def && k->defmgmt)
725 return -EINVAL;
726
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100727 if (k->defmgmt) {
728 if (k->def_uni || !k->def_multi)
729 return -EINVAL;
730 }
731
Johannes Bergb9454e82009-07-08 13:29:08 +0200732 if (k->idx != -1) {
733 if (k->defmgmt) {
734 if (k->idx < 4 || k->idx > 5)
735 return -EINVAL;
736 } else if (k->def) {
737 if (k->idx < 0 || k->idx > 3)
738 return -EINVAL;
739 } else {
740 if (k->idx < 0 || k->idx > 5)
741 return -EINVAL;
742 }
743 }
744
745 return 0;
746}
747
Johannes Bergfffd0932009-07-08 14:22:54 +0200748static struct cfg80211_cached_keys *
749nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530750 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200751{
752 struct key_parse parse;
753 struct nlattr *key;
754 struct cfg80211_cached_keys *result;
755 int rem, err, def = 0;
756
757 result = kzalloc(sizeof(*result), GFP_KERNEL);
758 if (!result)
759 return ERR_PTR(-ENOMEM);
760
761 result->def = -1;
762 result->defmgmt = -1;
763
764 nla_for_each_nested(key, keys, rem) {
765 memset(&parse, 0, sizeof(parse));
766 parse.idx = -1;
767
768 err = nl80211_parse_key_new(key, &parse);
769 if (err)
770 goto error;
771 err = -EINVAL;
772 if (!parse.p.key)
773 goto error;
774 if (parse.idx < 0 || parse.idx > 4)
775 goto error;
776 if (parse.def) {
777 if (def)
778 goto error;
779 def = 1;
780 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100781 if (!parse.def_uni || !parse.def_multi)
782 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200783 } else if (parse.defmgmt)
784 goto error;
785 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200786 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200787 if (err)
788 goto error;
789 result->params[parse.idx].cipher = parse.p.cipher;
790 result->params[parse.idx].key_len = parse.p.key_len;
791 result->params[parse.idx].key = result->data[parse.idx];
792 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530793
794 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
795 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
796 if (no_ht)
797 *no_ht = true;
798 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200799 }
800
801 return result;
802 error:
803 kfree(result);
804 return ERR_PTR(err);
805}
806
807static int nl80211_key_allowed(struct wireless_dev *wdev)
808{
809 ASSERT_WDEV_LOCK(wdev);
810
Johannes Bergfffd0932009-07-08 14:22:54 +0200811 switch (wdev->iftype) {
812 case NL80211_IFTYPE_AP:
813 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200814 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700815 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200816 break;
817 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200818 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200819 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200820 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200821 return -ENOLINK;
822 break;
823 default:
824 return -EINVAL;
825 }
826
827 return 0;
828}
829
Johannes Berg7527a782011-05-13 10:58:57 +0200830static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
831{
832 struct nlattr *nl_modes = nla_nest_start(msg, attr);
833 int i;
834
835 if (!nl_modes)
836 goto nla_put_failure;
837
838 i = 0;
839 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400840 if ((ifmodes & 1) && nla_put_flag(msg, i))
841 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200842 ifmodes >>= 1;
843 i++;
844 }
845
846 nla_nest_end(msg, nl_modes);
847 return 0;
848
849nla_put_failure:
850 return -ENOBUFS;
851}
852
853static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100854 struct sk_buff *msg,
855 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200856{
857 struct nlattr *nl_combis;
858 int i, j;
859
860 nl_combis = nla_nest_start(msg,
861 NL80211_ATTR_INTERFACE_COMBINATIONS);
862 if (!nl_combis)
863 goto nla_put_failure;
864
865 for (i = 0; i < wiphy->n_iface_combinations; i++) {
866 const struct ieee80211_iface_combination *c;
867 struct nlattr *nl_combi, *nl_limits;
868
869 c = &wiphy->iface_combinations[i];
870
871 nl_combi = nla_nest_start(msg, i + 1);
872 if (!nl_combi)
873 goto nla_put_failure;
874
875 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
876 if (!nl_limits)
877 goto nla_put_failure;
878
879 for (j = 0; j < c->n_limits; j++) {
880 struct nlattr *nl_limit;
881
882 nl_limit = nla_nest_start(msg, j + 1);
883 if (!nl_limit)
884 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400885 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
886 c->limits[j].max))
887 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200888 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
889 c->limits[j].types))
890 goto nla_put_failure;
891 nla_nest_end(msg, nl_limit);
892 }
893
894 nla_nest_end(msg, nl_limits);
895
David S. Miller9360ffd2012-03-29 04:41:26 -0400896 if (c->beacon_int_infra_match &&
897 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
898 goto nla_put_failure;
899 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
900 c->num_different_channels) ||
901 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
902 c->max_interfaces))
903 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100904 if (large &&
905 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
906 c->radar_detect_widths))
907 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200908
909 nla_nest_end(msg, nl_combi);
910 }
911
912 nla_nest_end(msg, nl_combis);
913
914 return 0;
915nla_put_failure:
916 return -ENOBUFS;
917}
918
Johannes Berg3713b4e2013-02-14 16:19:38 +0100919#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100920static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
921 struct sk_buff *msg)
922{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200923 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100924 struct nlattr *nl_tcp;
925
926 if (!tcp)
927 return 0;
928
929 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
930 if (!nl_tcp)
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
934 tcp->data_payload_max))
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
938 tcp->data_payload_max))
939 return -ENOBUFS;
940
941 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
942 return -ENOBUFS;
943
944 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
945 sizeof(*tcp->tok), tcp->tok))
946 return -ENOBUFS;
947
948 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
949 tcp->data_interval_max))
950 return -ENOBUFS;
951
952 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
953 tcp->wake_payload_max))
954 return -ENOBUFS;
955
956 nla_nest_end(msg, nl_tcp);
957 return 0;
958}
959
Johannes Berg3713b4e2013-02-14 16:19:38 +0100960static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100961 struct cfg80211_registered_device *dev,
962 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963{
964 struct nlattr *nl_wowlan;
965
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 return 0;
968
969 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
970 if (!nl_wowlan)
971 return -ENOBUFS;
972
Johannes Berg964dc9e2013-06-03 17:25:34 +0200973 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100974 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200975 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100976 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200977 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100978 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200979 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100980 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200981 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200983 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100984 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200985 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100986 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200987 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100988 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
989 return -ENOBUFS;
990
Johannes Berg964dc9e2013-06-03 17:25:34 +0200991 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700992 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200993 .max_patterns = dev->wiphy.wowlan->n_patterns,
994 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
995 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
996 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100997 };
998
999 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1000 sizeof(pat), &pat))
1001 return -ENOBUFS;
1002 }
1003
Johannes Bergb56cf722013-02-20 01:02:38 +01001004 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1005 return -ENOBUFS;
1006
Johannes Berg3713b4e2013-02-14 16:19:38 +01001007 nla_nest_end(msg, nl_wowlan);
1008
1009 return 0;
1010}
1011#endif
1012
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001013static int nl80211_send_coalesce(struct sk_buff *msg,
1014 struct cfg80211_registered_device *dev)
1015{
1016 struct nl80211_coalesce_rule_support rule;
1017
1018 if (!dev->wiphy.coalesce)
1019 return 0;
1020
1021 rule.max_rules = dev->wiphy.coalesce->n_rules;
1022 rule.max_delay = dev->wiphy.coalesce->max_delay;
1023 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1024 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1025 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1026 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1027
1028 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1029 return -ENOBUFS;
1030
1031 return 0;
1032}
1033
Johannes Berg3713b4e2013-02-14 16:19:38 +01001034static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1035 struct ieee80211_supported_band *sband)
1036{
1037 struct nlattr *nl_rates, *nl_rate;
1038 struct ieee80211_rate *rate;
1039 int i;
1040
1041 /* add HT info */
1042 if (sband->ht_cap.ht_supported &&
1043 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1044 sizeof(sband->ht_cap.mcs),
1045 &sband->ht_cap.mcs) ||
1046 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1047 sband->ht_cap.cap) ||
1048 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1049 sband->ht_cap.ampdu_factor) ||
1050 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1051 sband->ht_cap.ampdu_density)))
1052 return -ENOBUFS;
1053
1054 /* add VHT info */
1055 if (sband->vht_cap.vht_supported &&
1056 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1057 sizeof(sband->vht_cap.vht_mcs),
1058 &sband->vht_cap.vht_mcs) ||
1059 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1060 sband->vht_cap.cap)))
1061 return -ENOBUFS;
1062
1063 /* add bitrates */
1064 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1065 if (!nl_rates)
1066 return -ENOBUFS;
1067
1068 for (i = 0; i < sband->n_bitrates; i++) {
1069 nl_rate = nla_nest_start(msg, i);
1070 if (!nl_rate)
1071 return -ENOBUFS;
1072
1073 rate = &sband->bitrates[i];
1074 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1075 rate->bitrate))
1076 return -ENOBUFS;
1077 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1078 nla_put_flag(msg,
1079 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1080 return -ENOBUFS;
1081
1082 nla_nest_end(msg, nl_rate);
1083 }
1084
1085 nla_nest_end(msg, nl_rates);
1086
1087 return 0;
1088}
1089
1090static int
1091nl80211_send_mgmt_stypes(struct sk_buff *msg,
1092 const struct ieee80211_txrx_stypes *mgmt_stypes)
1093{
1094 u16 stypes;
1095 struct nlattr *nl_ftypes, *nl_ifs;
1096 enum nl80211_iftype ift;
1097 int i;
1098
1099 if (!mgmt_stypes)
1100 return 0;
1101
1102 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1103 if (!nl_ifs)
1104 return -ENOBUFS;
1105
1106 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1107 nl_ftypes = nla_nest_start(msg, ift);
1108 if (!nl_ftypes)
1109 return -ENOBUFS;
1110 i = 0;
1111 stypes = mgmt_stypes[ift].tx;
1112 while (stypes) {
1113 if ((stypes & 1) &&
1114 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1115 (i << 4) | IEEE80211_FTYPE_MGMT))
1116 return -ENOBUFS;
1117 stypes >>= 1;
1118 i++;
1119 }
1120 nla_nest_end(msg, nl_ftypes);
1121 }
1122
1123 nla_nest_end(msg, nl_ifs);
1124
1125 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1126 if (!nl_ifs)
1127 return -ENOBUFS;
1128
1129 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1130 nl_ftypes = nla_nest_start(msg, ift);
1131 if (!nl_ftypes)
1132 return -ENOBUFS;
1133 i = 0;
1134 stypes = mgmt_stypes[ift].rx;
1135 while (stypes) {
1136 if ((stypes & 1) &&
1137 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1138 (i << 4) | IEEE80211_FTYPE_MGMT))
1139 return -ENOBUFS;
1140 stypes >>= 1;
1141 i++;
1142 }
1143 nla_nest_end(msg, nl_ftypes);
1144 }
1145 nla_nest_end(msg, nl_ifs);
1146
1147 return 0;
1148}
1149
Johannes Berg86e8cf92013-06-19 10:57:22 +02001150struct nl80211_dump_wiphy_state {
1151 s64 filter_wiphy;
1152 long start;
1153 long split_start, band_start, chan_start;
1154 bool split;
1155};
1156
Johannes Berg3713b4e2013-02-14 16:19:38 +01001157static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1158 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001159 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001160{
1161 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001162 struct nlattr *nl_bands, *nl_band;
1163 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001164 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001165 enum ieee80211_band band;
1166 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001167 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001168 const struct ieee80211_txrx_stypes *mgmt_stypes =
1169 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001170 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001171
Eric W. Biederman15e47302012-09-07 20:12:54 +00001172 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001173 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001174 return -ENOBUFS;
1175
Johannes Berg86e8cf92013-06-19 10:57:22 +02001176 if (WARN_ON(!state))
1177 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001178
David S. Miller9360ffd2012-03-29 04:41:26 -04001179 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001180 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1181 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001182 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001183 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001184 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001185
Johannes Berg86e8cf92013-06-19 10:57:22 +02001186 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001187 case 0:
1188 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1189 dev->wiphy.retry_short) ||
1190 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1191 dev->wiphy.retry_long) ||
1192 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1193 dev->wiphy.frag_threshold) ||
1194 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1195 dev->wiphy.rts_threshold) ||
1196 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1197 dev->wiphy.coverage_class) ||
1198 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1199 dev->wiphy.max_scan_ssids) ||
1200 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1201 dev->wiphy.max_sched_scan_ssids) ||
1202 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1203 dev->wiphy.max_scan_ie_len) ||
1204 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1205 dev->wiphy.max_sched_scan_ie_len) ||
1206 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1207 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001208 goto nla_put_failure;
1209
Johannes Berg3713b4e2013-02-14 16:19:38 +01001210 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1211 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1212 goto nla_put_failure;
1213 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1214 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1215 goto nla_put_failure;
1216 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1217 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1218 goto nla_put_failure;
1219 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1220 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1221 goto nla_put_failure;
1222 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1223 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1224 goto nla_put_failure;
1225 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1226 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001227 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001228 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1229 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1230 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001231
Johannes Berg86e8cf92013-06-19 10:57:22 +02001232 state->split_start++;
1233 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 break;
1235 case 1:
1236 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1237 sizeof(u32) * dev->wiphy.n_cipher_suites,
1238 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001239 goto nla_put_failure;
1240
Johannes Berg3713b4e2013-02-14 16:19:38 +01001241 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1242 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001243 goto nla_put_failure;
1244
Johannes Berg3713b4e2013-02-14 16:19:38 +01001245 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1246 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1247 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001248
Johannes Berg3713b4e2013-02-14 16:19:38 +01001249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1250 dev->wiphy.available_antennas_tx) ||
1251 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1252 dev->wiphy.available_antennas_rx))
1253 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001254
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1256 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1257 dev->wiphy.probe_resp_offload))
1258 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001259
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 if ((dev->wiphy.available_antennas_tx ||
1261 dev->wiphy.available_antennas_rx) &&
1262 dev->ops->get_antenna) {
1263 u32 tx_ant = 0, rx_ant = 0;
1264 int res;
1265 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1266 if (!res) {
1267 if (nla_put_u32(msg,
1268 NL80211_ATTR_WIPHY_ANTENNA_TX,
1269 tx_ant) ||
1270 nla_put_u32(msg,
1271 NL80211_ATTR_WIPHY_ANTENNA_RX,
1272 rx_ant))
1273 goto nla_put_failure;
1274 }
Johannes Bergee688b002008-01-24 19:38:39 +01001275 }
1276
Johannes Berg86e8cf92013-06-19 10:57:22 +02001277 state->split_start++;
1278 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 break;
1280 case 2:
1281 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1282 dev->wiphy.interface_modes))
1283 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001284 state->split_start++;
1285 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 break;
1287 case 3:
1288 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1289 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001290 goto nla_put_failure;
1291
Johannes Berg86e8cf92013-06-19 10:57:22 +02001292 for (band = state->band_start;
1293 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 struct ieee80211_supported_band *sband;
1295
1296 sband = dev->wiphy.bands[band];
1297
1298 if (!sband)
1299 continue;
1300
1301 nl_band = nla_nest_start(msg, band);
1302 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001303 goto nla_put_failure;
1304
Johannes Berg86e8cf92013-06-19 10:57:22 +02001305 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 case 0:
1307 if (nl80211_send_band_rateinfo(msg, sband))
1308 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001309 state->chan_start++;
1310 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 break;
1312 default:
1313 /* add frequencies */
1314 nl_freqs = nla_nest_start(
1315 msg, NL80211_BAND_ATTR_FREQS);
1316 if (!nl_freqs)
1317 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001318
Johannes Berg86e8cf92013-06-19 10:57:22 +02001319 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 i < sband->n_channels;
1321 i++) {
1322 nl_freq = nla_nest_start(msg, i);
1323 if (!nl_freq)
1324 goto nla_put_failure;
1325
1326 chan = &sband->channels[i];
1327
Johannes Berg86e8cf92013-06-19 10:57:22 +02001328 if (nl80211_msg_put_channel(
1329 msg, chan,
1330 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001331 goto nla_put_failure;
1332
1333 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001334 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 break;
1336 }
1337 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001338 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001340 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_nest_end(msg, nl_freqs);
1342 }
1343
1344 nla_nest_end(msg, nl_band);
1345
Johannes Berg86e8cf92013-06-19 10:57:22 +02001346 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001348 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001349 band--;
1350 break;
1351 }
Johannes Bergee688b002008-01-24 19:38:39 +01001352 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001354
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001359
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001361 if (state->band_start == 0 && state->chan_start == 0)
1362 state->split_start++;
1363 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 break;
1365 case 4:
1366 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1367 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001368 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369
1370 i = 0;
1371#define CMD(op, n) \
1372 do { \
1373 if (dev->ops->op) { \
1374 i++; \
1375 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1376 goto nla_put_failure; \
1377 } \
1378 } while (0)
1379
1380 CMD(add_virtual_intf, NEW_INTERFACE);
1381 CMD(change_virtual_intf, SET_INTERFACE);
1382 CMD(add_key, NEW_KEY);
1383 CMD(start_ap, START_AP);
1384 CMD(add_station, NEW_STATION);
1385 CMD(add_mpath, NEW_MPATH);
1386 CMD(update_mesh_config, SET_MESH_CONFIG);
1387 CMD(change_bss, SET_BSS);
1388 CMD(auth, AUTHENTICATE);
1389 CMD(assoc, ASSOCIATE);
1390 CMD(deauth, DEAUTHENTICATE);
1391 CMD(disassoc, DISASSOCIATE);
1392 CMD(join_ibss, JOIN_IBSS);
1393 CMD(join_mesh, JOIN_MESH);
1394 CMD(set_pmksa, SET_PMKSA);
1395 CMD(del_pmksa, DEL_PMKSA);
1396 CMD(flush_pmksa, FLUSH_PMKSA);
1397 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1398 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1399 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1400 CMD(mgmt_tx, FRAME);
1401 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1402 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1403 i++;
1404 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1405 goto nla_put_failure;
1406 }
1407 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1408 dev->ops->join_mesh) {
1409 i++;
1410 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1411 goto nla_put_failure;
1412 }
1413 CMD(set_wds_peer, SET_WDS_PEER);
1414 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1415 CMD(tdls_mgmt, TDLS_MGMT);
1416 CMD(tdls_oper, TDLS_OPER);
1417 }
1418 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1419 CMD(sched_scan_start, START_SCHED_SCAN);
1420 CMD(probe_client, PROBE_CLIENT);
1421 CMD(set_noack_map, SET_NOACK_MAP);
1422 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1423 i++;
1424 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1425 goto nla_put_failure;
1426 }
1427 CMD(start_p2p_device, START_P2P_DEVICE);
1428 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001430 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1431 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001432 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1433 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001434 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001435
Kalle Valo4745fc02011-11-17 19:06:10 +02001436#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001438#endif
1439
Johannes Berg8fdc6212009-03-14 09:34:01 +01001440#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001441
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 if (dev->ops->connect || dev->ops->auth) {
1443 i++;
1444 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001445 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001446 }
1447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 if (dev->ops->disconnect || dev->ops->deauth) {
1449 i++;
1450 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1451 goto nla_put_failure;
1452 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001453
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 state->split_start++;
1456 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 break;
1458 case 5:
1459 if (dev->ops->remain_on_channel &&
1460 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1461 nla_put_u32(msg,
1462 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1463 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001464 goto nla_put_failure;
1465
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1467 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1468 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001469
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1471 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001472 state->split_start++;
1473 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 break;
1475 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001476#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001477 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001479 state->split_start++;
1480 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001481 break;
1482#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001483 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484#endif
1485 case 7:
1486 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1487 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001488 goto nla_put_failure;
1489
Johannes Berg86e8cf92013-06-19 10:57:22 +02001490 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1491 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001493
Johannes Berg86e8cf92013-06-19 10:57:22 +02001494 state->split_start++;
1495 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 break;
1497 case 8:
1498 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1499 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1500 dev->wiphy.ap_sme_capa))
1501 goto nla_put_failure;
1502
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001503 features = dev->wiphy.features;
1504 /*
1505 * We can only add the per-channel limit information if the
1506 * dump is split, otherwise it makes it too big. Therefore
1507 * only advertise it in that case.
1508 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001509 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001510 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1511 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 goto nla_put_failure;
1513
1514 if (dev->wiphy.ht_capa_mod_mask &&
1515 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1516 sizeof(*dev->wiphy.ht_capa_mod_mask),
1517 dev->wiphy.ht_capa_mod_mask))
1518 goto nla_put_failure;
1519
1520 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1521 dev->wiphy.max_acl_mac_addrs &&
1522 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1523 dev->wiphy.max_acl_mac_addrs))
1524 goto nla_put_failure;
1525
1526 /*
1527 * Any information below this point is only available to
1528 * applications that can deal with it being split. This
1529 * helps ensure that newly added capabilities don't break
1530 * older tools by overrunning their buffers.
1531 *
1532 * We still increment split_start so that in the split
1533 * case we'll continue with more data in the next round,
1534 * but break unconditionally so unsplit data stops here.
1535 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001536 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001537 break;
1538 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001539 if (dev->wiphy.extended_capabilities &&
1540 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1541 dev->wiphy.extended_capabilities_len,
1542 dev->wiphy.extended_capabilities) ||
1543 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1544 dev->wiphy.extended_capabilities_len,
1545 dev->wiphy.extended_capabilities_mask)))
1546 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547
Johannes Bergee2aca32013-02-21 17:36:01 +01001548 if (dev->wiphy.vht_capa_mod_mask &&
1549 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1550 sizeof(*dev->wiphy.vht_capa_mod_mask),
1551 dev->wiphy.vht_capa_mod_mask))
1552 goto nla_put_failure;
1553
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001554 state->split_start++;
1555 break;
1556 case 10:
1557 if (nl80211_send_coalesce(msg, dev))
1558 goto nla_put_failure;
1559
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001561 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001563 }
Johannes Berg55682962007-09-20 13:09:35 -04001564 return genlmsg_end(msg, hdr);
1565
1566 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001567 genlmsg_cancel(msg, hdr);
1568 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001569}
1570
Johannes Berg86e8cf92013-06-19 10:57:22 +02001571static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1572 struct netlink_callback *cb,
1573 struct nl80211_dump_wiphy_state *state)
1574{
1575 struct nlattr **tb = nl80211_fam.attrbuf;
1576 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1577 tb, nl80211_fam.maxattr, nl80211_policy);
1578 /* ignore parse errors for backward compatibility */
1579 if (ret)
1580 return 0;
1581
1582 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1583 if (tb[NL80211_ATTR_WIPHY])
1584 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1585 if (tb[NL80211_ATTR_WDEV])
1586 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1587 if (tb[NL80211_ATTR_IFINDEX]) {
1588 struct net_device *netdev;
1589 struct cfg80211_registered_device *rdev;
1590 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1591
1592 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1593 if (!netdev)
1594 return -ENODEV;
1595 if (netdev->ieee80211_ptr) {
1596 rdev = wiphy_to_dev(
1597 netdev->ieee80211_ptr->wiphy);
1598 state->filter_wiphy = rdev->wiphy_idx;
1599 }
1600 dev_put(netdev);
1601 }
1602
1603 return 0;
1604}
1605
Johannes Berg55682962007-09-20 13:09:35 -04001606static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1607{
Johannes Berg645e77d2013-03-01 14:03:49 +01001608 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001610 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001611
Johannes Berg5fe231e2013-05-08 21:45:15 +02001612 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001613 if (!state) {
1614 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001615 if (!state) {
1616 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001619 state->filter_wiphy = -1;
1620 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1621 if (ret) {
1622 kfree(state);
1623 rtnl_unlock();
1624 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001625 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001626 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 }
1628
Johannes Berg79c97e92009-07-07 03:56:12 +02001629 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001630 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1631 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001632 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001633 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 if (state->filter_wiphy != -1 &&
1635 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001636 continue;
1637 /* attempt to fit multiple wiphy data chunks into the skb */
1638 do {
1639 ret = nl80211_send_wiphy(dev, skb,
1640 NETLINK_CB(cb->skb).portid,
1641 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001642 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001643 if (ret < 0) {
1644 /*
1645 * If sending the wiphy data didn't fit (ENOBUFS
1646 * or EMSGSIZE returned), this SKB is still
1647 * empty (so it's not too big because another
1648 * wiphy dataset is already in the skb) and
1649 * we've not tried to adjust the dump allocation
1650 * yet ... then adjust the alloc size to be
1651 * bigger, and return 1 but with the empty skb.
1652 * This results in an empty message being RX'ed
1653 * in userspace, but that is ignored.
1654 *
1655 * We can then retry with the larger buffer.
1656 */
1657 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1658 !skb->len &&
1659 cb->min_dump_alloc < 4096) {
1660 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001661 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001662 return 1;
1663 }
1664 idx--;
1665 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001666 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001667 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 break;
Johannes Berg55682962007-09-20 13:09:35 -04001669 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001670 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001671
Johannes Berg86e8cf92013-06-19 10:57:22 +02001672 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001673
1674 return skb->len;
1675}
1676
Johannes Berg86e8cf92013-06-19 10:57:22 +02001677static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1678{
1679 kfree((void *)cb->args[0]);
1680 return 0;
1681}
1682
Johannes Berg55682962007-09-20 13:09:35 -04001683static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1684{
1685 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001686 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001687 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001688
Johannes Berg645e77d2013-03-01 14:03:49 +01001689 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001690 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001691 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001692
Johannes Berg3713b4e2013-02-14 16:19:38 +01001693 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001694 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001695 nlmsg_free(msg);
1696 return -ENOBUFS;
1697 }
Johannes Berg55682962007-09-20 13:09:35 -04001698
Johannes Berg134e6372009-07-10 09:51:34 +00001699 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001700}
1701
Jouni Malinen31888482008-10-30 16:59:24 +02001702static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1703 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1704 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1705 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1706 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1707 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1708};
1709
1710static int parse_txq_params(struct nlattr *tb[],
1711 struct ieee80211_txq_params *txq_params)
1712{
Johannes Berga3304b02012-03-28 11:04:24 +02001713 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001714 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1715 !tb[NL80211_TXQ_ATTR_AIFS])
1716 return -EINVAL;
1717
Johannes Berga3304b02012-03-28 11:04:24 +02001718 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001719 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1720 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1721 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1722 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1723
Johannes Berga3304b02012-03-28 11:04:24 +02001724 if (txq_params->ac >= NL80211_NUM_ACS)
1725 return -EINVAL;
1726
Jouni Malinen31888482008-10-30 16:59:24 +02001727 return 0;
1728}
1729
Johannes Bergf444de02010-05-05 15:25:02 +02001730static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1731{
1732 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001733 * You can only set the channel explicitly for WDS interfaces,
1734 * all others have their channel managed via their respective
1735 * "establish a connection" command (connect, join, ...)
1736 *
1737 * For AP/GO and mesh mode, the channel can be set with the
1738 * channel userspace API, but is only stored and passed to the
1739 * low-level driver when the AP starts or the mesh is joined.
1740 * This is for backward compatibility, userspace can also give
1741 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001742 *
1743 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001744 * whatever else is going on, so they have their own special
1745 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001746 */
1747 return !wdev ||
1748 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001749 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001750 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1751 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001752}
1753
Johannes Berg683b6d32012-11-08 21:25:48 +01001754static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1755 struct genl_info *info,
1756 struct cfg80211_chan_def *chandef)
1757{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301758 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001759
1760 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1761 return -EINVAL;
1762
1763 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1764
1765 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001766 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1767 chandef->center_freq1 = control_freq;
1768 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001769
1770 /* Primary channel not allowed */
1771 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1772 return -EINVAL;
1773
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001774 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1775 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001776
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001777 chantype = nla_get_u32(
1778 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1779
1780 switch (chantype) {
1781 case NL80211_CHAN_NO_HT:
1782 case NL80211_CHAN_HT20:
1783 case NL80211_CHAN_HT40PLUS:
1784 case NL80211_CHAN_HT40MINUS:
1785 cfg80211_chandef_create(chandef, chandef->chan,
1786 chantype);
1787 break;
1788 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001789 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001790 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001791 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1792 chandef->width =
1793 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1794 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1795 chandef->center_freq1 =
1796 nla_get_u32(
1797 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1798 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1799 chandef->center_freq2 =
1800 nla_get_u32(
1801 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1802 }
1803
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001804 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001805 return -EINVAL;
1806
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001807 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1808 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001809 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001810
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001811 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1812 chandef->width == NL80211_CHAN_WIDTH_10) &&
1813 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1814 return -EINVAL;
1815
Johannes Berg683b6d32012-11-08 21:25:48 +01001816 return 0;
1817}
1818
Johannes Bergf444de02010-05-05 15:25:02 +02001819static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1820 struct wireless_dev *wdev,
1821 struct genl_info *info)
1822{
Johannes Berg683b6d32012-11-08 21:25:48 +01001823 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001824 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001825 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1826
1827 if (wdev)
1828 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001829
Johannes Bergf444de02010-05-05 15:25:02 +02001830 if (!nl80211_can_set_dev_channel(wdev))
1831 return -EOPNOTSUPP;
1832
Johannes Berg683b6d32012-11-08 21:25:48 +01001833 result = nl80211_parse_chandef(rdev, info, &chandef);
1834 if (result)
1835 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001836
Johannes Berge8c9bd52012-06-06 08:18:22 +02001837 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001838 case NL80211_IFTYPE_AP:
1839 case NL80211_IFTYPE_P2P_GO:
1840 if (wdev->beacon_interval) {
1841 result = -EBUSY;
1842 break;
1843 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001844 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001845 result = -EINVAL;
1846 break;
1847 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001848 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001849 result = 0;
1850 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001851 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001852 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001853 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001854 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001855 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001856 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001857 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001858 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001859 }
Johannes Bergf444de02010-05-05 15:25:02 +02001860
1861 return result;
1862}
1863
1864static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1865{
Johannes Berg4c476992010-10-04 21:36:35 +02001866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1867 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001868
Johannes Berg4c476992010-10-04 21:36:35 +02001869 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001870}
1871
Bill Jordane8347eb2010-10-01 13:54:28 -04001872static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1873{
Johannes Berg43b19952010-10-07 13:10:30 +02001874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1875 struct net_device *dev = info->user_ptr[1];
1876 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001877 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001878
1879 if (!info->attrs[NL80211_ATTR_MAC])
1880 return -EINVAL;
1881
Johannes Berg43b19952010-10-07 13:10:30 +02001882 if (netif_running(dev))
1883 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001884
Johannes Berg43b19952010-10-07 13:10:30 +02001885 if (!rdev->ops->set_wds_peer)
1886 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001887
Johannes Berg43b19952010-10-07 13:10:30 +02001888 if (wdev->iftype != NL80211_IFTYPE_WDS)
1889 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001890
1891 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001892 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001893}
1894
1895
Johannes Berg55682962007-09-20 13:09:35 -04001896static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1897{
1898 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001899 struct net_device *netdev = NULL;
1900 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001901 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001902 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001903 u32 changed;
1904 u8 retry_short = 0, retry_long = 0;
1905 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001906 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001907
Johannes Berg5fe231e2013-05-08 21:45:15 +02001908 ASSERT_RTNL();
1909
Johannes Bergf444de02010-05-05 15:25:02 +02001910 /*
1911 * Try to find the wiphy and netdev. Normally this
1912 * function shouldn't need the netdev, but this is
1913 * done for backward compatibility -- previously
1914 * setting the channel was done per wiphy, but now
1915 * it is per netdev. Previous userland like hostapd
1916 * also passed a netdev to set_wiphy, so that it is
1917 * possible to let that go to the right netdev!
1918 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001919
Johannes Bergf444de02010-05-05 15:25:02 +02001920 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1921 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1922
1923 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001924 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001925 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001926 else
Johannes Bergf444de02010-05-05 15:25:02 +02001927 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001928 }
1929
Johannes Bergf444de02010-05-05 15:25:02 +02001930 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001931 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1932 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001933 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001934 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001935 wdev = NULL;
1936 netdev = NULL;
1937 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001938 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001939 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001940
1941 /*
1942 * end workaround code, by now the rdev is available
1943 * and locked, and wdev may or may not be NULL.
1944 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001945
1946 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001947 result = cfg80211_dev_rename(
1948 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001949
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001950 if (result)
1951 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001952
Jouni Malinen31888482008-10-30 16:59:24 +02001953 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1954 struct ieee80211_txq_params txq_params;
1955 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1956
1957 if (!rdev->ops->set_txq_params) {
1958 result = -EOPNOTSUPP;
1959 goto bad_res;
1960 }
1961
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001962 if (!netdev) {
1963 result = -EINVAL;
1964 goto bad_res;
1965 }
1966
Johannes Berg133a3ff2011-11-03 14:50:13 +01001967 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1968 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1969 result = -EINVAL;
1970 goto bad_res;
1971 }
1972
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001973 if (!netif_running(netdev)) {
1974 result = -ENETDOWN;
1975 goto bad_res;
1976 }
1977
Jouni Malinen31888482008-10-30 16:59:24 +02001978 nla_for_each_nested(nl_txq_params,
1979 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1980 rem_txq_params) {
1981 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1982 nla_data(nl_txq_params),
1983 nla_len(nl_txq_params),
1984 txq_params_policy);
1985 result = parse_txq_params(tb, &txq_params);
1986 if (result)
1987 goto bad_res;
1988
Hila Gonene35e4d22012-06-27 17:19:42 +03001989 result = rdev_set_txq_params(rdev, netdev,
1990 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001991 if (result)
1992 goto bad_res;
1993 }
1994 }
1995
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001996 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001997 result = __nl80211_set_channel(rdev,
1998 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1999 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002000 if (result)
2001 goto bad_res;
2002 }
2003
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002004 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002005 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002006 enum nl80211_tx_power_setting type;
2007 int idx, mbm = 0;
2008
Johannes Bergc8442112012-10-24 10:17:18 +02002009 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2010 txp_wdev = NULL;
2011
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002012 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002013 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002014 goto bad_res;
2015 }
2016
2017 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2018 type = nla_get_u32(info->attrs[idx]);
2019
2020 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2021 (type != NL80211_TX_POWER_AUTOMATIC)) {
2022 result = -EINVAL;
2023 goto bad_res;
2024 }
2025
2026 if (type != NL80211_TX_POWER_AUTOMATIC) {
2027 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2028 mbm = nla_get_u32(info->attrs[idx]);
2029 }
2030
Johannes Bergc8442112012-10-24 10:17:18 +02002031 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002032 if (result)
2033 goto bad_res;
2034 }
2035
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002036 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2037 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2038 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002039 if ((!rdev->wiphy.available_antennas_tx &&
2040 !rdev->wiphy.available_antennas_rx) ||
2041 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002042 result = -EOPNOTSUPP;
2043 goto bad_res;
2044 }
2045
2046 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2047 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2048
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002049 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002050 * available antenna masks, except for the "all" mask */
2051 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2052 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002053 result = -EINVAL;
2054 goto bad_res;
2055 }
2056
Bruno Randolf7f531e02010-12-16 11:30:22 +09002057 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2058 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002059
Hila Gonene35e4d22012-06-27 17:19:42 +03002060 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002061 if (result)
2062 goto bad_res;
2063 }
2064
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002065 changed = 0;
2066
2067 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2068 retry_short = nla_get_u8(
2069 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2070 if (retry_short == 0) {
2071 result = -EINVAL;
2072 goto bad_res;
2073 }
2074 changed |= WIPHY_PARAM_RETRY_SHORT;
2075 }
2076
2077 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2078 retry_long = nla_get_u8(
2079 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2080 if (retry_long == 0) {
2081 result = -EINVAL;
2082 goto bad_res;
2083 }
2084 changed |= WIPHY_PARAM_RETRY_LONG;
2085 }
2086
2087 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2088 frag_threshold = nla_get_u32(
2089 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2090 if (frag_threshold < 256) {
2091 result = -EINVAL;
2092 goto bad_res;
2093 }
2094 if (frag_threshold != (u32) -1) {
2095 /*
2096 * Fragments (apart from the last one) are required to
2097 * have even length. Make the fragmentation code
2098 * simpler by stripping LSB should someone try to use
2099 * odd threshold value.
2100 */
2101 frag_threshold &= ~0x1;
2102 }
2103 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2104 }
2105
2106 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2107 rts_threshold = nla_get_u32(
2108 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2109 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2110 }
2111
Lukáš Turek81077e82009-12-21 22:50:47 +01002112 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2113 coverage_class = nla_get_u8(
2114 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2115 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2116 }
2117
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002118 if (changed) {
2119 u8 old_retry_short, old_retry_long;
2120 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002121 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002122
2123 if (!rdev->ops->set_wiphy_params) {
2124 result = -EOPNOTSUPP;
2125 goto bad_res;
2126 }
2127
2128 old_retry_short = rdev->wiphy.retry_short;
2129 old_retry_long = rdev->wiphy.retry_long;
2130 old_frag_threshold = rdev->wiphy.frag_threshold;
2131 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002132 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002133
2134 if (changed & WIPHY_PARAM_RETRY_SHORT)
2135 rdev->wiphy.retry_short = retry_short;
2136 if (changed & WIPHY_PARAM_RETRY_LONG)
2137 rdev->wiphy.retry_long = retry_long;
2138 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2139 rdev->wiphy.frag_threshold = frag_threshold;
2140 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2141 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002142 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2143 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002144
Hila Gonene35e4d22012-06-27 17:19:42 +03002145 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002146 if (result) {
2147 rdev->wiphy.retry_short = old_retry_short;
2148 rdev->wiphy.retry_long = old_retry_long;
2149 rdev->wiphy.frag_threshold = old_frag_threshold;
2150 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002151 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002152 }
2153 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002154
Johannes Berg306d6112008-12-08 12:39:04 +01002155 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002156 if (netdev)
2157 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002158 return result;
2159}
2160
Johannes Berg71bbc992012-06-15 15:30:18 +02002161static inline u64 wdev_id(struct wireless_dev *wdev)
2162{
2163 return (u64)wdev->identifier |
2164 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2165}
Johannes Berg55682962007-09-20 13:09:35 -04002166
Johannes Berg683b6d32012-11-08 21:25:48 +01002167static int nl80211_send_chandef(struct sk_buff *msg,
2168 struct cfg80211_chan_def *chandef)
2169{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002170 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002171
Johannes Berg683b6d32012-11-08 21:25:48 +01002172 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2173 chandef->chan->center_freq))
2174 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002175 switch (chandef->width) {
2176 case NL80211_CHAN_WIDTH_20_NOHT:
2177 case NL80211_CHAN_WIDTH_20:
2178 case NL80211_CHAN_WIDTH_40:
2179 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2180 cfg80211_get_chandef_type(chandef)))
2181 return -ENOBUFS;
2182 break;
2183 default:
2184 break;
2185 }
2186 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2187 return -ENOBUFS;
2188 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2189 return -ENOBUFS;
2190 if (chandef->center_freq2 &&
2191 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002192 return -ENOBUFS;
2193 return 0;
2194}
2195
Eric W. Biederman15e47302012-09-07 20:12:54 +00002196static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002197 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002198 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002199{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002200 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002201 void *hdr;
2202
Eric W. Biederman15e47302012-09-07 20:12:54 +00002203 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002204 if (!hdr)
2205 return -1;
2206
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002207 if (dev &&
2208 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002209 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002210 goto nla_put_failure;
2211
2212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2213 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002214 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002215 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002216 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2217 rdev->devlist_generation ^
2218 (cfg80211_rdev_list_generation << 2)))
2219 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002220
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002221 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002222 int ret;
2223 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002224
Johannes Berg683b6d32012-11-08 21:25:48 +01002225 ret = rdev_get_channel(rdev, wdev, &chandef);
2226 if (ret == 0) {
2227 if (nl80211_send_chandef(msg, &chandef))
2228 goto nla_put_failure;
2229 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002230 }
2231
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002232 if (wdev->ssid_len) {
2233 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2234 goto nla_put_failure;
2235 }
2236
Johannes Berg55682962007-09-20 13:09:35 -04002237 return genlmsg_end(msg, hdr);
2238
2239 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002240 genlmsg_cancel(msg, hdr);
2241 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002242}
2243
2244static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2245{
2246 int wp_idx = 0;
2247 int if_idx = 0;
2248 int wp_start = cb->args[0];
2249 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002250 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002251 struct wireless_dev *wdev;
2252
Johannes Berg5fe231e2013-05-08 21:45:15 +02002253 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002254 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2255 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002256 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002257 if (wp_idx < wp_start) {
2258 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002259 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002260 }
Johannes Berg55682962007-09-20 13:09:35 -04002261 if_idx = 0;
2262
Johannes Berg89a54e42012-06-15 14:33:17 +02002263 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002264 if (if_idx < if_start) {
2265 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002266 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002267 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002268 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002269 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002270 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002271 goto out;
2272 }
2273 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002274 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002275
2276 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002277 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002278 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002279 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002280
2281 cb->args[0] = wp_idx;
2282 cb->args[1] = if_idx;
2283
2284 return skb->len;
2285}
2286
2287static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2288{
2289 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002290 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002291 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002292
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002294 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002295 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002296
Eric W. Biederman15e47302012-09-07 20:12:54 +00002297 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002298 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002299 nlmsg_free(msg);
2300 return -ENOBUFS;
2301 }
Johannes Berg55682962007-09-20 13:09:35 -04002302
Johannes Berg134e6372009-07-10 09:51:34 +00002303 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002304}
2305
Michael Wu66f7ac52008-01-31 19:48:22 +01002306static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2307 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2308 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2309 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2310 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2311 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002312 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002313};
2314
2315static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2316{
2317 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2318 int flag;
2319
2320 *mntrflags = 0;
2321
2322 if (!nla)
2323 return -EINVAL;
2324
2325 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2326 nla, mntr_flags_policy))
2327 return -EINVAL;
2328
2329 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2330 if (flags[flag])
2331 *mntrflags |= (1<<flag);
2332
2333 return 0;
2334}
2335
Johannes Berg9bc383d2009-11-19 11:55:19 +01002336static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002337 struct net_device *netdev, u8 use_4addr,
2338 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002339{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002340 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002341 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002342 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002343 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002344 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002345
2346 switch (iftype) {
2347 case NL80211_IFTYPE_AP_VLAN:
2348 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2349 return 0;
2350 break;
2351 case NL80211_IFTYPE_STATION:
2352 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2353 return 0;
2354 break;
2355 default:
2356 break;
2357 }
2358
2359 return -EOPNOTSUPP;
2360}
2361
Johannes Berg55682962007-09-20 13:09:35 -04002362static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2363{
Johannes Berg4c476992010-10-04 21:36:35 +02002364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002365 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002366 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002367 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002368 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002369 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002370 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002371
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002372 memset(&params, 0, sizeof(params));
2373
Johannes Berg04a773a2009-04-19 21:24:32 +02002374 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002375
Johannes Berg723b0382008-09-16 20:22:09 +02002376 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002377 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002378 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002379 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002380 if (ntype > NL80211_IFTYPE_MAX)
2381 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002382 }
2383
Johannes Berg92ffe052008-09-16 20:39:36 +02002384 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002385 struct wireless_dev *wdev = dev->ieee80211_ptr;
2386
Johannes Berg4c476992010-10-04 21:36:35 +02002387 if (ntype != NL80211_IFTYPE_MESH_POINT)
2388 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002389 if (netif_running(dev))
2390 return -EBUSY;
2391
2392 wdev_lock(wdev);
2393 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2394 IEEE80211_MAX_MESH_ID_LEN);
2395 wdev->mesh_id_up_len =
2396 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2397 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2398 wdev->mesh_id_up_len);
2399 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002400 }
2401
Felix Fietkau8b787642009-11-10 18:53:10 +01002402 if (info->attrs[NL80211_ATTR_4ADDR]) {
2403 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2404 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002405 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002406 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002407 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002408 } else {
2409 params.use_4addr = -1;
2410 }
2411
Johannes Berg92ffe052008-09-16 20:39:36 +02002412 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002413 if (ntype != NL80211_IFTYPE_MONITOR)
2414 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002415 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2416 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002417 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002418 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002419
2420 flags = &_flags;
2421 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002422 }
Johannes Berg3b858752009-03-12 09:55:09 +01002423
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002424 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2425 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2426 return -EOPNOTSUPP;
2427
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002428 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002429 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002430 else
2431 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002432
Johannes Berg9bc383d2009-11-19 11:55:19 +01002433 if (!err && params.use_4addr != -1)
2434 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2435
Johannes Berg55682962007-09-20 13:09:35 -04002436 return err;
2437}
2438
2439static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2440{
Johannes Berg4c476992010-10-04 21:36:35 +02002441 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002442 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002443 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002444 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002445 int err;
2446 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002447 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002448
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002449 memset(&params, 0, sizeof(params));
2450
Johannes Berg55682962007-09-20 13:09:35 -04002451 if (!info->attrs[NL80211_ATTR_IFNAME])
2452 return -EINVAL;
2453
2454 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2455 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2456 if (type > NL80211_IFTYPE_MAX)
2457 return -EINVAL;
2458 }
2459
Johannes Berg79c97e92009-07-07 03:56:12 +02002460 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002461 !(rdev->wiphy.interface_modes & (1 << type)))
2462 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002463
Arend van Spriel1c18f142013-01-08 10:17:27 +01002464 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2465 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2466 ETH_ALEN);
2467 if (!is_valid_ether_addr(params.macaddr))
2468 return -EADDRNOTAVAIL;
2469 }
2470
Johannes Berg9bc383d2009-11-19 11:55:19 +01002471 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002472 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002473 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002474 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002475 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002476 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002477
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2479 if (!msg)
2480 return -ENOMEM;
2481
Michael Wu66f7ac52008-01-31 19:48:22 +01002482 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2483 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2484 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002485
2486 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2487 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2488 return -EOPNOTSUPP;
2489
Hila Gonene35e4d22012-06-27 17:19:42 +03002490 wdev = rdev_add_virtual_intf(rdev,
2491 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2492 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002493 if (IS_ERR(wdev)) {
2494 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002495 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002496 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002497
Johannes Berg98104fde2012-06-16 00:19:54 +02002498 switch (type) {
2499 case NL80211_IFTYPE_MESH_POINT:
2500 if (!info->attrs[NL80211_ATTR_MESH_ID])
2501 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002502 wdev_lock(wdev);
2503 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2504 IEEE80211_MAX_MESH_ID_LEN);
2505 wdev->mesh_id_up_len =
2506 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2507 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2508 wdev->mesh_id_up_len);
2509 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002510 break;
2511 case NL80211_IFTYPE_P2P_DEVICE:
2512 /*
2513 * P2P Device doesn't have a netdev, so doesn't go
2514 * through the netdev notifier and must be added here
2515 */
2516 mutex_init(&wdev->mtx);
2517 INIT_LIST_HEAD(&wdev->event_list);
2518 spin_lock_init(&wdev->event_lock);
2519 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2520 spin_lock_init(&wdev->mgmt_registrations_lock);
2521
Johannes Berg98104fde2012-06-16 00:19:54 +02002522 wdev->identifier = ++rdev->wdev_id;
2523 list_add_rcu(&wdev->list, &rdev->wdev_list);
2524 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002525 break;
2526 default:
2527 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002528 }
2529
Eric W. Biederman15e47302012-09-07 20:12:54 +00002530 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002531 rdev, wdev) < 0) {
2532 nlmsg_free(msg);
2533 return -ENOBUFS;
2534 }
2535
2536 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002537}
2538
2539static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2540{
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002542 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002543
Johannes Berg4c476992010-10-04 21:36:35 +02002544 if (!rdev->ops->del_virtual_intf)
2545 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002546
Johannes Berg84efbb82012-06-16 00:00:26 +02002547 /*
2548 * If we remove a wireless device without a netdev then clear
2549 * user_ptr[1] so that nl80211_post_doit won't dereference it
2550 * to check if it needs to do dev_put(). Otherwise it crashes
2551 * since the wdev has been freed, unlike with a netdev where
2552 * we need the dev_put() for the netdev to really be freed.
2553 */
2554 if (!wdev->netdev)
2555 info->user_ptr[1] = NULL;
2556
Hila Gonene35e4d22012-06-27 17:19:42 +03002557 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002558}
2559
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002560static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2561{
2562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2563 struct net_device *dev = info->user_ptr[1];
2564 u16 noack_map;
2565
2566 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2567 return -EINVAL;
2568
2569 if (!rdev->ops->set_noack_map)
2570 return -EOPNOTSUPP;
2571
2572 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2573
Hila Gonene35e4d22012-06-27 17:19:42 +03002574 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002575}
2576
Johannes Berg41ade002007-12-19 02:03:29 +01002577struct get_key_cookie {
2578 struct sk_buff *msg;
2579 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002580 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002581};
2582
2583static void get_key_callback(void *c, struct key_params *params)
2584{
Johannes Bergb9454e82009-07-08 13:29:08 +02002585 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002586 struct get_key_cookie *cookie = c;
2587
David S. Miller9360ffd2012-03-29 04:41:26 -04002588 if ((params->key &&
2589 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2590 params->key_len, params->key)) ||
2591 (params->seq &&
2592 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2593 params->seq_len, params->seq)) ||
2594 (params->cipher &&
2595 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2596 params->cipher)))
2597 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002598
Johannes Bergb9454e82009-07-08 13:29:08 +02002599 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2600 if (!key)
2601 goto nla_put_failure;
2602
David S. Miller9360ffd2012-03-29 04:41:26 -04002603 if ((params->key &&
2604 nla_put(cookie->msg, NL80211_KEY_DATA,
2605 params->key_len, params->key)) ||
2606 (params->seq &&
2607 nla_put(cookie->msg, NL80211_KEY_SEQ,
2608 params->seq_len, params->seq)) ||
2609 (params->cipher &&
2610 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2611 params->cipher)))
2612 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002613
David S. Miller9360ffd2012-03-29 04:41:26 -04002614 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2615 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002616
2617 nla_nest_end(cookie->msg, key);
2618
Johannes Berg41ade002007-12-19 02:03:29 +01002619 return;
2620 nla_put_failure:
2621 cookie->error = 1;
2622}
2623
2624static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2625{
Johannes Berg4c476992010-10-04 21:36:35 +02002626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002627 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002628 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002629 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002630 const u8 *mac_addr = NULL;
2631 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002632 struct get_key_cookie cookie = {
2633 .error = 0,
2634 };
2635 void *hdr;
2636 struct sk_buff *msg;
2637
2638 if (info->attrs[NL80211_ATTR_KEY_IDX])
2639 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2640
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002641 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002642 return -EINVAL;
2643
2644 if (info->attrs[NL80211_ATTR_MAC])
2645 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2646
Johannes Berge31b8212010-10-05 19:39:30 +02002647 pairwise = !!mac_addr;
2648 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2649 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2650 if (kt >= NUM_NL80211_KEYTYPES)
2651 return -EINVAL;
2652 if (kt != NL80211_KEYTYPE_GROUP &&
2653 kt != NL80211_KEYTYPE_PAIRWISE)
2654 return -EINVAL;
2655 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2656 }
2657
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (!rdev->ops->get_key)
2659 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002660
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002662 if (!msg)
2663 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002664
Eric W. Biederman15e47302012-09-07 20:12:54 +00002665 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002666 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002667 if (!hdr)
2668 return -ENOBUFS;
Johannes Berg41ade002007-12-19 02:03:29 +01002669
2670 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002671 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002672
David S. Miller9360ffd2012-03-29 04:41:26 -04002673 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2674 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2675 goto nla_put_failure;
2676 if (mac_addr &&
2677 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2678 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002679
Johannes Berge31b8212010-10-05 19:39:30 +02002680 if (pairwise && mac_addr &&
2681 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2682 return -ENOENT;
2683
Hila Gonene35e4d22012-06-27 17:19:42 +03002684 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2685 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002686
2687 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002688 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002689
2690 if (cookie.error)
2691 goto nla_put_failure;
2692
2693 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002694 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002695
2696 nla_put_failure:
2697 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002698 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002699 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002700 return err;
2701}
2702
2703static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2704{
Johannes Berg4c476992010-10-04 21:36:35 +02002705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002706 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002707 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002708 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002709
Johannes Bergb9454e82009-07-08 13:29:08 +02002710 err = nl80211_parse_key(info, &key);
2711 if (err)
2712 return err;
2713
2714 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002715 return -EINVAL;
2716
Johannes Bergb9454e82009-07-08 13:29:08 +02002717 /* only support setting default key */
2718 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002719 return -EINVAL;
2720
Johannes Bergfffd0932009-07-08 14:22:54 +02002721 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002722
2723 if (key.def) {
2724 if (!rdev->ops->set_default_key) {
2725 err = -EOPNOTSUPP;
2726 goto out;
2727 }
2728
2729 err = nl80211_key_allowed(dev->ieee80211_ptr);
2730 if (err)
2731 goto out;
2732
Hila Gonene35e4d22012-06-27 17:19:42 +03002733 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002734 key.def_uni, key.def_multi);
2735
2736 if (err)
2737 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002738
Johannes Berg3d23e342009-09-29 23:27:28 +02002739#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002740 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002741#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002742 } else {
2743 if (key.def_uni || !key.def_multi) {
2744 err = -EINVAL;
2745 goto out;
2746 }
2747
2748 if (!rdev->ops->set_default_mgmt_key) {
2749 err = -EOPNOTSUPP;
2750 goto out;
2751 }
2752
2753 err = nl80211_key_allowed(dev->ieee80211_ptr);
2754 if (err)
2755 goto out;
2756
Hila Gonene35e4d22012-06-27 17:19:42 +03002757 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002758 if (err)
2759 goto out;
2760
2761#ifdef CONFIG_CFG80211_WEXT
2762 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2763#endif
2764 }
2765
2766 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002767 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002768
Johannes Berg41ade002007-12-19 02:03:29 +01002769 return err;
2770}
2771
2772static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2773{
Johannes Berg4c476992010-10-04 21:36:35 +02002774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002775 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002776 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002777 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002778 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002779
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 err = nl80211_parse_key(info, &key);
2781 if (err)
2782 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002783
Johannes Bergb9454e82009-07-08 13:29:08 +02002784 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002785 return -EINVAL;
2786
Johannes Berg41ade002007-12-19 02:03:29 +01002787 if (info->attrs[NL80211_ATTR_MAC])
2788 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2789
Johannes Berge31b8212010-10-05 19:39:30 +02002790 if (key.type == -1) {
2791 if (mac_addr)
2792 key.type = NL80211_KEYTYPE_PAIRWISE;
2793 else
2794 key.type = NL80211_KEYTYPE_GROUP;
2795 }
2796
2797 /* for now */
2798 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2799 key.type != NL80211_KEYTYPE_GROUP)
2800 return -EINVAL;
2801
Johannes Berg4c476992010-10-04 21:36:35 +02002802 if (!rdev->ops->add_key)
2803 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002804
Johannes Berge31b8212010-10-05 19:39:30 +02002805 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2806 key.type == NL80211_KEYTYPE_PAIRWISE,
2807 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002808 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002809
2810 wdev_lock(dev->ieee80211_ptr);
2811 err = nl80211_key_allowed(dev->ieee80211_ptr);
2812 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002813 err = rdev_add_key(rdev, dev, key.idx,
2814 key.type == NL80211_KEYTYPE_PAIRWISE,
2815 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002816 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002817
Johannes Berg41ade002007-12-19 02:03:29 +01002818 return err;
2819}
2820
2821static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2822{
Johannes Berg4c476992010-10-04 21:36:35 +02002823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002824 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002825 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002826 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002827 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002828
Johannes Bergb9454e82009-07-08 13:29:08 +02002829 err = nl80211_parse_key(info, &key);
2830 if (err)
2831 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002832
2833 if (info->attrs[NL80211_ATTR_MAC])
2834 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2835
Johannes Berge31b8212010-10-05 19:39:30 +02002836 if (key.type == -1) {
2837 if (mac_addr)
2838 key.type = NL80211_KEYTYPE_PAIRWISE;
2839 else
2840 key.type = NL80211_KEYTYPE_GROUP;
2841 }
2842
2843 /* for now */
2844 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2845 key.type != NL80211_KEYTYPE_GROUP)
2846 return -EINVAL;
2847
Johannes Berg4c476992010-10-04 21:36:35 +02002848 if (!rdev->ops->del_key)
2849 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002850
Johannes Bergfffd0932009-07-08 14:22:54 +02002851 wdev_lock(dev->ieee80211_ptr);
2852 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002853
2854 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2855 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2856 err = -ENOENT;
2857
Johannes Bergfffd0932009-07-08 14:22:54 +02002858 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002859 err = rdev_del_key(rdev, dev, key.idx,
2860 key.type == NL80211_KEYTYPE_PAIRWISE,
2861 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002862
Johannes Berg3d23e342009-09-29 23:27:28 +02002863#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002864 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002865 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002866 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002867 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002868 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2869 }
2870#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002871 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002872
Johannes Berg41ade002007-12-19 02:03:29 +01002873 return err;
2874}
2875
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302876/* This function returns an error or the number of nested attributes */
2877static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2878{
2879 struct nlattr *attr;
2880 int n_entries = 0, tmp;
2881
2882 nla_for_each_nested(attr, nl_attr, tmp) {
2883 if (nla_len(attr) != ETH_ALEN)
2884 return -EINVAL;
2885
2886 n_entries++;
2887 }
2888
2889 return n_entries;
2890}
2891
2892/*
2893 * This function parses ACL information and allocates memory for ACL data.
2894 * On successful return, the calling function is responsible to free the
2895 * ACL buffer returned by this function.
2896 */
2897static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2898 struct genl_info *info)
2899{
2900 enum nl80211_acl_policy acl_policy;
2901 struct nlattr *attr;
2902 struct cfg80211_acl_data *acl;
2903 int i = 0, n_entries, tmp;
2904
2905 if (!wiphy->max_acl_mac_addrs)
2906 return ERR_PTR(-EOPNOTSUPP);
2907
2908 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2909 return ERR_PTR(-EINVAL);
2910
2911 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2912 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2913 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2914 return ERR_PTR(-EINVAL);
2915
2916 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2917 return ERR_PTR(-EINVAL);
2918
2919 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2920 if (n_entries < 0)
2921 return ERR_PTR(n_entries);
2922
2923 if (n_entries > wiphy->max_acl_mac_addrs)
2924 return ERR_PTR(-ENOTSUPP);
2925
2926 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2927 GFP_KERNEL);
2928 if (!acl)
2929 return ERR_PTR(-ENOMEM);
2930
2931 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2932 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2933 i++;
2934 }
2935
2936 acl->n_acl_entries = n_entries;
2937 acl->acl_policy = acl_policy;
2938
2939 return acl;
2940}
2941
2942static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2943{
2944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2945 struct net_device *dev = info->user_ptr[1];
2946 struct cfg80211_acl_data *acl;
2947 int err;
2948
2949 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2950 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2951 return -EOPNOTSUPP;
2952
2953 if (!dev->ieee80211_ptr->beacon_interval)
2954 return -EINVAL;
2955
2956 acl = parse_acl_data(&rdev->wiphy, info);
2957 if (IS_ERR(acl))
2958 return PTR_ERR(acl);
2959
2960 err = rdev_set_mac_acl(rdev, dev, acl);
2961
2962 kfree(acl);
2963
2964 return err;
2965}
2966
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002967static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002968 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002969{
Johannes Berg88600202012-02-13 15:17:18 +01002970 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002971
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002972 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2973 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2974 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2975 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002976 return -EINVAL;
2977
Johannes Berg88600202012-02-13 15:17:18 +01002978 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002979
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002980 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2981 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2982 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002983 if (!bcn->head_len)
2984 return -EINVAL;
2985 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002986 }
2987
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002988 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2989 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2990 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002991 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002992 }
2993
Johannes Berg4c476992010-10-04 21:36:35 +02002994 if (!haveinfo)
2995 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002996
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002997 if (attrs[NL80211_ATTR_IE]) {
2998 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2999 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003000 }
3001
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003003 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003004 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003005 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003006 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003007 }
3008
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003009 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003010 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003011 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003012 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003013 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003014 }
3015
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003016 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3017 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3018 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003019 }
3020
Johannes Berg88600202012-02-13 15:17:18 +01003021 return 0;
3022}
3023
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003024static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3025 struct cfg80211_ap_settings *params)
3026{
3027 struct wireless_dev *wdev;
3028 bool ret = false;
3029
Johannes Berg89a54e42012-06-15 14:33:17 +02003030 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003031 if (wdev->iftype != NL80211_IFTYPE_AP &&
3032 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3033 continue;
3034
Johannes Berg683b6d32012-11-08 21:25:48 +01003035 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003036 continue;
3037
Johannes Berg683b6d32012-11-08 21:25:48 +01003038 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003039 ret = true;
3040 break;
3041 }
3042
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003043 return ret;
3044}
3045
Jouni Malinene39e5b52012-09-30 19:29:39 +03003046static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3047 enum nl80211_auth_type auth_type,
3048 enum nl80211_commands cmd)
3049{
3050 if (auth_type > NL80211_AUTHTYPE_MAX)
3051 return false;
3052
3053 switch (cmd) {
3054 case NL80211_CMD_AUTHENTICATE:
3055 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3056 auth_type == NL80211_AUTHTYPE_SAE)
3057 return false;
3058 return true;
3059 case NL80211_CMD_CONNECT:
3060 case NL80211_CMD_START_AP:
3061 /* SAE not supported yet */
3062 if (auth_type == NL80211_AUTHTYPE_SAE)
3063 return false;
3064 return true;
3065 default:
3066 return false;
3067 }
3068}
3069
Johannes Berg88600202012-02-13 15:17:18 +01003070static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3071{
3072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3073 struct net_device *dev = info->user_ptr[1];
3074 struct wireless_dev *wdev = dev->ieee80211_ptr;
3075 struct cfg80211_ap_settings params;
3076 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003077 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003078
3079 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3080 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3081 return -EOPNOTSUPP;
3082
3083 if (!rdev->ops->start_ap)
3084 return -EOPNOTSUPP;
3085
3086 if (wdev->beacon_interval)
3087 return -EALREADY;
3088
3089 memset(&params, 0, sizeof(params));
3090
3091 /* these are required for START_AP */
3092 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3093 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3094 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3095 return -EINVAL;
3096
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003097 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003098 if (err)
3099 return err;
3100
3101 params.beacon_interval =
3102 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3103 params.dtim_period =
3104 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3105
3106 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3107 if (err)
3108 return err;
3109
3110 /*
3111 * In theory, some of these attributes should be required here
3112 * but since they were not used when the command was originally
3113 * added, keep them optional for old user space programs to let
3114 * them continue to work with drivers that do not need the
3115 * additional information -- drivers must check!
3116 */
3117 if (info->attrs[NL80211_ATTR_SSID]) {
3118 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3119 params.ssid_len =
3120 nla_len(info->attrs[NL80211_ATTR_SSID]);
3121 if (params.ssid_len == 0 ||
3122 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3123 return -EINVAL;
3124 }
3125
3126 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3127 params.hidden_ssid = nla_get_u32(
3128 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3129 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3130 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3131 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3132 return -EINVAL;
3133 }
3134
3135 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3136
3137 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3138 params.auth_type = nla_get_u32(
3139 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003140 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3141 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003142 return -EINVAL;
3143 } else
3144 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3145
3146 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3147 NL80211_MAX_NR_CIPHER_SUITES);
3148 if (err)
3149 return err;
3150
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303151 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3152 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3153 return -EOPNOTSUPP;
3154 params.inactivity_timeout = nla_get_u16(
3155 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3156 }
3157
Johannes Berg53cabad2012-11-14 15:17:28 +01003158 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3159 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3160 return -EINVAL;
3161 params.p2p_ctwindow =
3162 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3163 if (params.p2p_ctwindow > 127)
3164 return -EINVAL;
3165 if (params.p2p_ctwindow != 0 &&
3166 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3167 return -EINVAL;
3168 }
3169
3170 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3171 u8 tmp;
3172
3173 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3174 return -EINVAL;
3175 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3176 if (tmp > 1)
3177 return -EINVAL;
3178 params.p2p_opp_ps = tmp;
3179 if (params.p2p_opp_ps != 0 &&
3180 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3181 return -EINVAL;
3182 }
3183
Johannes Bergaa430da2012-05-16 23:50:18 +02003184 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003185 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3186 if (err)
3187 return err;
3188 } else if (wdev->preset_chandef.chan) {
3189 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003190 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003191 return -EINVAL;
3192
Johannes Berg683b6d32012-11-08 21:25:48 +01003193 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003194 return -EINVAL;
3195
Simon Wunderlich04f39042013-02-08 18:16:19 +01003196 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3197 if (err < 0)
3198 return err;
3199 if (err) {
3200 radar_detect_width = BIT(params.chandef.width);
3201 params.radar_required = true;
3202 }
3203
Simon Wunderlich04f39042013-02-08 18:16:19 +01003204 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3205 params.chandef.chan,
3206 CHAN_MODE_SHARED,
3207 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003208 if (err)
3209 return err;
3210
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303211 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3212 params.acl = parse_acl_data(&rdev->wiphy, info);
3213 if (IS_ERR(params.acl))
3214 return PTR_ERR(params.acl);
3215 }
3216
Hila Gonene35e4d22012-06-27 17:19:42 +03003217 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003218 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003219 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003220 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003221 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003222 wdev->ssid_len = params.ssid_len;
3223 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003224 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303225
3226 kfree(params.acl);
3227
Johannes Berg56d18932011-05-09 18:41:15 +02003228 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003229}
3230
Johannes Berg88600202012-02-13 15:17:18 +01003231static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3232{
3233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3234 struct net_device *dev = info->user_ptr[1];
3235 struct wireless_dev *wdev = dev->ieee80211_ptr;
3236 struct cfg80211_beacon_data params;
3237 int err;
3238
3239 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3240 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3241 return -EOPNOTSUPP;
3242
3243 if (!rdev->ops->change_beacon)
3244 return -EOPNOTSUPP;
3245
3246 if (!wdev->beacon_interval)
3247 return -EINVAL;
3248
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003249 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003250 if (err)
3251 return err;
3252
Hila Gonene35e4d22012-06-27 17:19:42 +03003253 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003254}
3255
3256static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003257{
Johannes Berg4c476992010-10-04 21:36:35 +02003258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3259 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003260
Michal Kazior60771782012-06-29 12:46:56 +02003261 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003262}
3263
Johannes Berg5727ef12007-12-19 02:03:34 +01003264static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3265 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3266 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3267 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003268 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003269 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003270 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003271};
3272
Johannes Bergeccb8e82009-05-11 21:57:56 +03003273static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003274 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003275 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003276{
3277 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003278 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003279 int flag;
3280
Johannes Bergeccb8e82009-05-11 21:57:56 +03003281 /*
3282 * Try parsing the new attribute first so userspace
3283 * can specify both for older kernels.
3284 */
3285 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3286 if (nla) {
3287 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003288
Johannes Bergeccb8e82009-05-11 21:57:56 +03003289 sta_flags = nla_data(nla);
3290 params->sta_flags_mask = sta_flags->mask;
3291 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003292 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003293 if ((params->sta_flags_mask |
3294 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3295 return -EINVAL;
3296 return 0;
3297 }
3298
3299 /* if present, parse the old attribute */
3300
3301 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003302 if (!nla)
3303 return 0;
3304
3305 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3306 nla, sta_flags_policy))
3307 return -EINVAL;
3308
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003309 /*
3310 * Only allow certain flags for interface types so that
3311 * other attributes are silently ignored. Remember that
3312 * this is backward compatibility code with old userspace
3313 * and shouldn't be hit in other cases anyway.
3314 */
3315 switch (iftype) {
3316 case NL80211_IFTYPE_AP:
3317 case NL80211_IFTYPE_AP_VLAN:
3318 case NL80211_IFTYPE_P2P_GO:
3319 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3320 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3321 BIT(NL80211_STA_FLAG_WME) |
3322 BIT(NL80211_STA_FLAG_MFP);
3323 break;
3324 case NL80211_IFTYPE_P2P_CLIENT:
3325 case NL80211_IFTYPE_STATION:
3326 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3327 BIT(NL80211_STA_FLAG_TDLS_PEER);
3328 break;
3329 case NL80211_IFTYPE_MESH_POINT:
3330 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3331 BIT(NL80211_STA_FLAG_MFP) |
3332 BIT(NL80211_STA_FLAG_AUTHORIZED);
3333 default:
3334 return -EINVAL;
3335 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003336
Johannes Berg3383b5a2012-05-10 20:14:43 +02003337 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3338 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003339 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003340
Johannes Berg3383b5a2012-05-10 20:14:43 +02003341 /* no longer support new API additions in old API */
3342 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3343 return -EINVAL;
3344 }
3345 }
3346
Johannes Berg5727ef12007-12-19 02:03:34 +01003347 return 0;
3348}
3349
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003350static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3351 int attr)
3352{
3353 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003354 u32 bitrate;
3355 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003356
3357 rate = nla_nest_start(msg, attr);
3358 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003359 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003360
3361 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3362 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003363 /* report 16-bit bitrate only if we can */
3364 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003365 if (bitrate > 0 &&
3366 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3367 return false;
3368 if (bitrate_compat > 0 &&
3369 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3370 return false;
3371
3372 if (info->flags & RATE_INFO_FLAGS_MCS) {
3373 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3374 return false;
3375 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3376 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3377 return false;
3378 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3379 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3380 return false;
3381 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3382 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3383 return false;
3384 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3385 return false;
3386 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3387 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3388 return false;
3389 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3390 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3391 return false;
3392 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3393 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3394 return false;
3395 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3396 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3397 return false;
3398 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3399 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3400 return false;
3401 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003402
3403 nla_nest_end(msg, rate);
3404 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003405}
3406
Felix Fietkau119363c2013-04-22 16:29:30 +02003407static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3408 int id)
3409{
3410 void *attr;
3411 int i = 0;
3412
3413 if (!mask)
3414 return true;
3415
3416 attr = nla_nest_start(msg, id);
3417 if (!attr)
3418 return false;
3419
3420 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3421 if (!(mask & BIT(i)))
3422 continue;
3423
3424 if (nla_put_u8(msg, i, signal[i]))
3425 return false;
3426 }
3427
3428 nla_nest_end(msg, attr);
3429
3430 return true;
3431}
3432
Eric W. Biederman15e47302012-09-07 20:12:54 +00003433static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003434 int flags,
3435 struct cfg80211_registered_device *rdev,
3436 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003437 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003438{
3439 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003440 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003441
Eric W. Biederman15e47302012-09-07 20:12:54 +00003442 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003443 if (!hdr)
3444 return -1;
3445
David S. Miller9360ffd2012-03-29 04:41:26 -04003446 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3447 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3448 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3449 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003450
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003451 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3452 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003453 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003454 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3455 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3456 sinfo->connected_time))
3457 goto nla_put_failure;
3458 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3459 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3460 sinfo->inactive_time))
3461 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003462 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3463 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003464 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003465 (u32)sinfo->rx_bytes))
3466 goto nla_put_failure;
3467 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003468 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003469 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3470 (u32)sinfo->tx_bytes))
3471 goto nla_put_failure;
3472 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3473 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003474 sinfo->rx_bytes))
3475 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003476 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3477 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003478 sinfo->tx_bytes))
3479 goto nla_put_failure;
3480 if ((sinfo->filled & STATION_INFO_LLID) &&
3481 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3482 goto nla_put_failure;
3483 if ((sinfo->filled & STATION_INFO_PLID) &&
3484 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3485 goto nla_put_failure;
3486 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3487 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3488 sinfo->plink_state))
3489 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003490 switch (rdev->wiphy.signal_type) {
3491 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003492 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3493 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3494 sinfo->signal))
3495 goto nla_put_failure;
3496 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3497 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3498 sinfo->signal_avg))
3499 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003500 break;
3501 default:
3502 break;
3503 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003504 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3505 if (!nl80211_put_signal(msg, sinfo->chains,
3506 sinfo->chain_signal,
3507 NL80211_STA_INFO_CHAIN_SIGNAL))
3508 goto nla_put_failure;
3509 }
3510 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3511 if (!nl80211_put_signal(msg, sinfo->chains,
3512 sinfo->chain_signal_avg,
3513 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3514 goto nla_put_failure;
3515 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003516 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003517 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3518 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003519 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003520 }
3521 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3522 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3523 NL80211_STA_INFO_RX_BITRATE))
3524 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003525 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003526 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3527 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3528 sinfo->rx_packets))
3529 goto nla_put_failure;
3530 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3531 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3532 sinfo->tx_packets))
3533 goto nla_put_failure;
3534 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3535 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3536 sinfo->tx_retries))
3537 goto nla_put_failure;
3538 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3539 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3540 sinfo->tx_failed))
3541 goto nla_put_failure;
3542 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3543 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3544 sinfo->beacon_loss_count))
3545 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003546 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3547 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3548 sinfo->local_pm))
3549 goto nla_put_failure;
3550 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3551 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3552 sinfo->peer_pm))
3553 goto nla_put_failure;
3554 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3555 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3556 sinfo->nonpeer_pm))
3557 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003558 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3559 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3560 if (!bss_param)
3561 goto nla_put_failure;
3562
David S. Miller9360ffd2012-03-29 04:41:26 -04003563 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3564 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3565 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3566 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3567 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3568 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3569 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3570 sinfo->bss_param.dtim_period) ||
3571 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3572 sinfo->bss_param.beacon_interval))
3573 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003574
3575 nla_nest_end(msg, bss_param);
3576 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003577 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3578 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3579 sizeof(struct nl80211_sta_flag_update),
3580 &sinfo->sta_flags))
3581 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003582 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3583 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3584 sinfo->t_offset))
3585 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003586 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003587
David S. Miller9360ffd2012-03-29 04:41:26 -04003588 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3589 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3590 sinfo->assoc_req_ies))
3591 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003592
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003593 return genlmsg_end(msg, hdr);
3594
3595 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003596 genlmsg_cancel(msg, hdr);
3597 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003598}
3599
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003600static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003601 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003602{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003603 struct station_info sinfo;
3604 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003605 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003606 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003607 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003608 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003609
Johannes Berg97990a02013-04-19 01:02:55 +02003610 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003611 if (err)
3612 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003613
Johannes Berg97990a02013-04-19 01:02:55 +02003614 if (!wdev->netdev) {
3615 err = -EINVAL;
3616 goto out_err;
3617 }
3618
Johannes Bergbba95fe2008-07-29 13:22:51 +02003619 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003620 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003621 goto out_err;
3622 }
3623
Johannes Bergbba95fe2008-07-29 13:22:51 +02003624 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003625 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003626 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003627 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003628 if (err == -ENOENT)
3629 break;
3630 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003631 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003632
3633 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003634 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003635 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003636 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003637 &sinfo) < 0)
3638 goto out;
3639
3640 sta_idx++;
3641 }
3642
3643
3644 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003645 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003646 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003647 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003648 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003649
3650 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003651}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003652
Johannes Berg5727ef12007-12-19 02:03:34 +01003653static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3654{
Johannes Berg4c476992010-10-04 21:36:35 +02003655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3656 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003657 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003658 struct sk_buff *msg;
3659 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003660 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003661
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003662 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003663
3664 if (!info->attrs[NL80211_ATTR_MAC])
3665 return -EINVAL;
3666
3667 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3668
Johannes Berg4c476992010-10-04 21:36:35 +02003669 if (!rdev->ops->get_station)
3670 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003671
Hila Gonene35e4d22012-06-27 17:19:42 +03003672 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003673 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003674 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003675
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003676 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003677 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003678 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003679
Eric W. Biederman15e47302012-09-07 20:12:54 +00003680 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003681 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003682 nlmsg_free(msg);
3683 return -ENOBUFS;
3684 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003685
Johannes Berg4c476992010-10-04 21:36:35 +02003686 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003687}
3688
Johannes Berg77ee7c82013-02-15 00:48:33 +01003689int cfg80211_check_station_change(struct wiphy *wiphy,
3690 struct station_parameters *params,
3691 enum cfg80211_station_type statype)
3692{
3693 if (params->listen_interval != -1)
3694 return -EINVAL;
3695 if (params->aid)
3696 return -EINVAL;
3697
3698 /* When you run into this, adjust the code below for the new flag */
3699 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3700
3701 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003702 case CFG80211_STA_MESH_PEER_KERNEL:
3703 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003704 /*
3705 * No ignoring the TDLS flag here -- the userspace mesh
3706 * code doesn't have the bug of including TDLS in the
3707 * mask everywhere.
3708 */
3709 if (params->sta_flags_mask &
3710 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3711 BIT(NL80211_STA_FLAG_MFP) |
3712 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3713 return -EINVAL;
3714 break;
3715 case CFG80211_STA_TDLS_PEER_SETUP:
3716 case CFG80211_STA_TDLS_PEER_ACTIVE:
3717 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3718 return -EINVAL;
3719 /* ignore since it can't change */
3720 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3721 break;
3722 default:
3723 /* disallow mesh-specific things */
3724 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3725 return -EINVAL;
3726 if (params->local_pm)
3727 return -EINVAL;
3728 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3729 return -EINVAL;
3730 }
3731
3732 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3733 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3734 /* TDLS can't be set, ... */
3735 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3736 return -EINVAL;
3737 /*
3738 * ... but don't bother the driver with it. This works around
3739 * a hostapd/wpa_supplicant issue -- it always includes the
3740 * TLDS_PEER flag in the mask even for AP mode.
3741 */
3742 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3743 }
3744
3745 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3746 /* reject other things that can't change */
3747 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3748 return -EINVAL;
3749 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3750 return -EINVAL;
3751 if (params->supported_rates)
3752 return -EINVAL;
3753 if (params->ext_capab || params->ht_capa || params->vht_capa)
3754 return -EINVAL;
3755 }
3756
3757 if (statype != CFG80211_STA_AP_CLIENT) {
3758 if (params->vlan)
3759 return -EINVAL;
3760 }
3761
3762 switch (statype) {
3763 case CFG80211_STA_AP_MLME_CLIENT:
3764 /* Use this only for authorizing/unauthorizing a station */
3765 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3766 return -EOPNOTSUPP;
3767 break;
3768 case CFG80211_STA_AP_CLIENT:
3769 /* accept only the listed bits */
3770 if (params->sta_flags_mask &
3771 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3772 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3773 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3774 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3775 BIT(NL80211_STA_FLAG_WME) |
3776 BIT(NL80211_STA_FLAG_MFP)))
3777 return -EINVAL;
3778
3779 /* but authenticated/associated only if driver handles it */
3780 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3781 params->sta_flags_mask &
3782 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3783 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3784 return -EINVAL;
3785 break;
3786 case CFG80211_STA_IBSS:
3787 case CFG80211_STA_AP_STA:
3788 /* reject any changes other than AUTHORIZED */
3789 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3790 return -EINVAL;
3791 break;
3792 case CFG80211_STA_TDLS_PEER_SETUP:
3793 /* reject any changes other than AUTHORIZED or WME */
3794 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3795 BIT(NL80211_STA_FLAG_WME)))
3796 return -EINVAL;
3797 /* force (at least) rates when authorizing */
3798 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3799 !params->supported_rates)
3800 return -EINVAL;
3801 break;
3802 case CFG80211_STA_TDLS_PEER_ACTIVE:
3803 /* reject any changes */
3804 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003805 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003806 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3807 return -EINVAL;
3808 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003809 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003810 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3811 return -EINVAL;
3812 break;
3813 }
3814
3815 return 0;
3816}
3817EXPORT_SYMBOL(cfg80211_check_station_change);
3818
Johannes Berg5727ef12007-12-19 02:03:34 +01003819/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003820 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003821 */
Johannes Berg80b99892011-11-18 16:23:01 +01003822static struct net_device *get_vlan(struct genl_info *info,
3823 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003824{
Johannes Berg463d0182009-07-14 00:33:35 +02003825 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003826 struct net_device *v;
3827 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003828
Johannes Berg80b99892011-11-18 16:23:01 +01003829 if (!vlanattr)
3830 return NULL;
3831
3832 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3833 if (!v)
3834 return ERR_PTR(-ENODEV);
3835
3836 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3837 ret = -EINVAL;
3838 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003839 }
Johannes Berg80b99892011-11-18 16:23:01 +01003840
Johannes Berg77ee7c82013-02-15 00:48:33 +01003841 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3842 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3843 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3844 ret = -EINVAL;
3845 goto error;
3846 }
3847
Johannes Berg80b99892011-11-18 16:23:01 +01003848 if (!netif_running(v)) {
3849 ret = -ENETDOWN;
3850 goto error;
3851 }
3852
3853 return v;
3854 error:
3855 dev_put(v);
3856 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003857}
3858
Jouni Malinendf881292013-02-14 21:10:54 +02003859static struct nla_policy
3860nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3861 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3862 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3863};
3864
Johannes Bergff276692013-02-15 00:09:01 +01003865static int nl80211_parse_sta_wme(struct genl_info *info,
3866 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003867{
Jouni Malinendf881292013-02-14 21:10:54 +02003868 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3869 struct nlattr *nla;
3870 int err;
3871
Jouni Malinendf881292013-02-14 21:10:54 +02003872 /* parse WME attributes if present */
3873 if (!info->attrs[NL80211_ATTR_STA_WME])
3874 return 0;
3875
3876 nla = info->attrs[NL80211_ATTR_STA_WME];
3877 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3878 nl80211_sta_wme_policy);
3879 if (err)
3880 return err;
3881
3882 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3883 params->uapsd_queues = nla_get_u8(
3884 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3885 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3886 return -EINVAL;
3887
3888 if (tb[NL80211_STA_WME_MAX_SP])
3889 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3890
3891 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3892 return -EINVAL;
3893
3894 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3895
3896 return 0;
3897}
3898
Johannes Bergff276692013-02-15 00:09:01 +01003899static int nl80211_set_station_tdls(struct genl_info *info,
3900 struct station_parameters *params)
3901{
3902 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003903 if (info->attrs[NL80211_ATTR_PEER_AID])
3904 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003905 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3906 params->ht_capa =
3907 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3908 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3909 params->vht_capa =
3910 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3911
3912 return nl80211_parse_sta_wme(info, params);
3913}
3914
Johannes Berg5727ef12007-12-19 02:03:34 +01003915static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3916{
Johannes Berg4c476992010-10-04 21:36:35 +02003917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003918 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003919 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003920 u8 *mac_addr;
3921 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003922
3923 memset(&params, 0, sizeof(params));
3924
3925 params.listen_interval = -1;
3926
Johannes Berg77ee7c82013-02-15 00:48:33 +01003927 if (!rdev->ops->change_station)
3928 return -EOPNOTSUPP;
3929
Johannes Berg5727ef12007-12-19 02:03:34 +01003930 if (info->attrs[NL80211_ATTR_STA_AID])
3931 return -EINVAL;
3932
3933 if (!info->attrs[NL80211_ATTR_MAC])
3934 return -EINVAL;
3935
3936 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3937
3938 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3939 params.supported_rates =
3940 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3941 params.supported_rates_len =
3942 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3943 }
3944
Jouni Malinen9d62a982013-02-14 21:10:13 +02003945 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3946 params.capability =
3947 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3948 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3949 }
3950
3951 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3952 params.ext_capab =
3953 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3954 params.ext_capab_len =
3955 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3956 }
3957
Jouni Malinendf881292013-02-14 21:10:54 +02003958 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003959 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003960
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003961 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003962 return -EINVAL;
3963
Johannes Bergf8bacc22013-02-14 23:27:01 +01003964 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003965 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003966 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3967 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3968 return -EINVAL;
3969 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003970
Johannes Bergf8bacc22013-02-14 23:27:01 +01003971 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003972 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003973 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3974 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3975 return -EINVAL;
3976 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3977 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003978
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003979 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3980 enum nl80211_mesh_power_mode pm = nla_get_u32(
3981 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3982
3983 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3984 pm > NL80211_MESH_POWER_MAX)
3985 return -EINVAL;
3986
3987 params.local_pm = pm;
3988 }
3989
Johannes Berg77ee7c82013-02-15 00:48:33 +01003990 /* Include parameters for TDLS peer (will check later) */
3991 err = nl80211_set_station_tdls(info, &params);
3992 if (err)
3993 return err;
3994
3995 params.vlan = get_vlan(info, rdev);
3996 if (IS_ERR(params.vlan))
3997 return PTR_ERR(params.vlan);
3998
Johannes Berga97f4422009-06-18 17:23:43 +02003999 switch (dev->ieee80211_ptr->iftype) {
4000 case NL80211_IFTYPE_AP:
4001 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004002 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004003 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004004 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004005 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004006 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004007 break;
4008 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004009 err = -EOPNOTSUPP;
4010 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004011 }
4012
Johannes Berg77ee7c82013-02-15 00:48:33 +01004013 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004014 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004015
Johannes Berg77ee7c82013-02-15 00:48:33 +01004016 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004017 if (params.vlan)
4018 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004019
Johannes Berg5727ef12007-12-19 02:03:34 +01004020 return err;
4021}
4022
4023static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4024{
Johannes Berg4c476992010-10-04 21:36:35 +02004025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004026 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004027 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004028 struct station_parameters params;
4029 u8 *mac_addr = NULL;
4030
4031 memset(&params, 0, sizeof(params));
4032
Johannes Berg984c3112013-02-14 23:43:25 +01004033 if (!rdev->ops->add_station)
4034 return -EOPNOTSUPP;
4035
Johannes Berg5727ef12007-12-19 02:03:34 +01004036 if (!info->attrs[NL80211_ATTR_MAC])
4037 return -EINVAL;
4038
Johannes Berg5727ef12007-12-19 02:03:34 +01004039 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4040 return -EINVAL;
4041
4042 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4043 return -EINVAL;
4044
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004045 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4046 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004047 return -EINVAL;
4048
Johannes Berg5727ef12007-12-19 02:03:34 +01004049 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4050 params.supported_rates =
4051 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4052 params.supported_rates_len =
4053 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4054 params.listen_interval =
4055 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004056
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004057 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004058 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004059 else
4060 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004061 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4062 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004063
Jouni Malinen9d62a982013-02-14 21:10:13 +02004064 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4065 params.capability =
4066 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4067 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4068 }
4069
4070 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4071 params.ext_capab =
4072 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4073 params.ext_capab_len =
4074 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4075 }
4076
Jouni Malinen36aedc902008-08-25 11:58:58 +03004077 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4078 params.ht_capa =
4079 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004080
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004081 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4082 params.vht_capa =
4083 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4084
Johannes Bergf8bacc22013-02-14 23:27:01 +01004085 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004086 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004087 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4088 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4089 return -EINVAL;
4090 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004091
Johannes Bergff276692013-02-15 00:09:01 +01004092 err = nl80211_parse_sta_wme(info, &params);
4093 if (err)
4094 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004095
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004096 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004097 return -EINVAL;
4098
Johannes Berg77ee7c82013-02-15 00:48:33 +01004099 /* When you run into this, adjust the code below for the new flag */
4100 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4101
Johannes Bergbdd90d52011-12-14 12:20:27 +01004102 switch (dev->ieee80211_ptr->iftype) {
4103 case NL80211_IFTYPE_AP:
4104 case NL80211_IFTYPE_AP_VLAN:
4105 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004106 /* ignore WME attributes if iface/sta is not capable */
4107 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4108 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4109 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004110
Johannes Bergbdd90d52011-12-14 12:20:27 +01004111 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004112 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4113 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004114 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004115 /* but don't bother the driver with it */
4116 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004117
Johannes Bergd582cff2012-10-26 17:53:44 +02004118 /* allow authenticated/associated only if driver handles it */
4119 if (!(rdev->wiphy.features &
4120 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4121 params.sta_flags_mask &
4122 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4123 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4124 return -EINVAL;
4125
Johannes Bergbdd90d52011-12-14 12:20:27 +01004126 /* must be last in here for error handling */
4127 params.vlan = get_vlan(info, rdev);
4128 if (IS_ERR(params.vlan))
4129 return PTR_ERR(params.vlan);
4130 break;
4131 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004132 /* ignore uAPSD data */
4133 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4134
Johannes Bergd582cff2012-10-26 17:53:44 +02004135 /* associated is disallowed */
4136 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4137 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004138 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004139 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4140 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004141 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004142 break;
4143 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004144 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004145 /* ignore uAPSD data */
4146 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4147
Johannes Berg77ee7c82013-02-15 00:48:33 +01004148 /* these are disallowed */
4149 if (params.sta_flags_mask &
4150 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4151 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004152 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004153 /* Only TDLS peers can be added */
4154 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4155 return -EINVAL;
4156 /* Can only add if TDLS ... */
4157 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4158 return -EOPNOTSUPP;
4159 /* ... with external setup is supported */
4160 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4161 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004162 /*
4163 * Older wpa_supplicant versions always mark the TDLS peer
4164 * as authorized, but it shouldn't yet be.
4165 */
4166 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004167 break;
4168 default:
4169 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004170 }
4171
Johannes Bergbdd90d52011-12-14 12:20:27 +01004172 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004173
Hila Gonene35e4d22012-06-27 17:19:42 +03004174 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004175
Johannes Berg5727ef12007-12-19 02:03:34 +01004176 if (params.vlan)
4177 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004178 return err;
4179}
4180
4181static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4182{
Johannes Berg4c476992010-10-04 21:36:35 +02004183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4184 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004185 u8 *mac_addr = NULL;
4186
4187 if (info->attrs[NL80211_ATTR_MAC])
4188 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4189
Johannes Berge80cf852009-05-11 14:43:13 +02004190 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004191 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004192 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004193 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4194 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004195
Johannes Berg4c476992010-10-04 21:36:35 +02004196 if (!rdev->ops->del_station)
4197 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004198
Hila Gonene35e4d22012-06-27 17:19:42 +03004199 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004200}
4201
Eric W. Biederman15e47302012-09-07 20:12:54 +00004202static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004203 int flags, struct net_device *dev,
4204 u8 *dst, u8 *next_hop,
4205 struct mpath_info *pinfo)
4206{
4207 void *hdr;
4208 struct nlattr *pinfoattr;
4209
Eric W. Biederman15e47302012-09-07 20:12:54 +00004210 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004211 if (!hdr)
4212 return -1;
4213
David S. Miller9360ffd2012-03-29 04:41:26 -04004214 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4215 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4216 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4217 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4218 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004219
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004220 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4221 if (!pinfoattr)
4222 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004223 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4224 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4225 pinfo->frame_qlen))
4226 goto nla_put_failure;
4227 if (((pinfo->filled & MPATH_INFO_SN) &&
4228 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4229 ((pinfo->filled & MPATH_INFO_METRIC) &&
4230 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4231 pinfo->metric)) ||
4232 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4233 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4234 pinfo->exptime)) ||
4235 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4236 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4237 pinfo->flags)) ||
4238 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4239 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4240 pinfo->discovery_timeout)) ||
4241 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4242 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4243 pinfo->discovery_retries)))
4244 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004245
4246 nla_nest_end(msg, pinfoattr);
4247
4248 return genlmsg_end(msg, hdr);
4249
4250 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004251 genlmsg_cancel(msg, hdr);
4252 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004253}
4254
4255static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004256 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004257{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258 struct mpath_info pinfo;
4259 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004260 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004261 u8 dst[ETH_ALEN];
4262 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004263 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004264 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004265
Johannes Berg97990a02013-04-19 01:02:55 +02004266 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004267 if (err)
4268 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004269
4270 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004271 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004272 goto out_err;
4273 }
4274
Johannes Berg97990a02013-04-19 01:02:55 +02004275 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004276 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004277 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004278 }
4279
Johannes Bergbba95fe2008-07-29 13:22:51 +02004280 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004281 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4282 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004283 if (err == -ENOENT)
4284 break;
4285 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004286 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004287
Eric W. Biederman15e47302012-09-07 20:12:54 +00004288 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004289 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004290 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004291 &pinfo) < 0)
4292 goto out;
4293
4294 path_idx++;
4295 }
4296
4297
4298 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004299 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004300 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004301 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004302 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004303 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004304}
4305
4306static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4307{
Johannes Berg4c476992010-10-04 21:36:35 +02004308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004309 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004310 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004311 struct mpath_info pinfo;
4312 struct sk_buff *msg;
4313 u8 *dst = NULL;
4314 u8 next_hop[ETH_ALEN];
4315
4316 memset(&pinfo, 0, sizeof(pinfo));
4317
4318 if (!info->attrs[NL80211_ATTR_MAC])
4319 return -EINVAL;
4320
4321 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4322
Johannes Berg4c476992010-10-04 21:36:35 +02004323 if (!rdev->ops->get_mpath)
4324 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004325
Johannes Berg4c476992010-10-04 21:36:35 +02004326 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4327 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004328
Hila Gonene35e4d22012-06-27 17:19:42 +03004329 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004330 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004331 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004332
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004333 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004334 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004335 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004336
Eric W. Biederman15e47302012-09-07 20:12:54 +00004337 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004338 dev, dst, next_hop, &pinfo) < 0) {
4339 nlmsg_free(msg);
4340 return -ENOBUFS;
4341 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004342
Johannes Berg4c476992010-10-04 21:36:35 +02004343 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004344}
4345
4346static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4347{
Johannes Berg4c476992010-10-04 21:36:35 +02004348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4349 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004350 u8 *dst = NULL;
4351 u8 *next_hop = NULL;
4352
4353 if (!info->attrs[NL80211_ATTR_MAC])
4354 return -EINVAL;
4355
4356 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4357 return -EINVAL;
4358
4359 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4360 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4361
Johannes Berg4c476992010-10-04 21:36:35 +02004362 if (!rdev->ops->change_mpath)
4363 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004364
Johannes Berg4c476992010-10-04 21:36:35 +02004365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4366 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004367
Hila Gonene35e4d22012-06-27 17:19:42 +03004368 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004369}
Johannes Berg4c476992010-10-04 21:36:35 +02004370
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004371static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4372{
Johannes Berg4c476992010-10-04 21:36:35 +02004373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4374 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004375 u8 *dst = NULL;
4376 u8 *next_hop = NULL;
4377
4378 if (!info->attrs[NL80211_ATTR_MAC])
4379 return -EINVAL;
4380
4381 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4382 return -EINVAL;
4383
4384 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4385 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4386
Johannes Berg4c476992010-10-04 21:36:35 +02004387 if (!rdev->ops->add_mpath)
4388 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004389
Johannes Berg4c476992010-10-04 21:36:35 +02004390 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4391 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004392
Hila Gonene35e4d22012-06-27 17:19:42 +03004393 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004394}
4395
4396static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4397{
Johannes Berg4c476992010-10-04 21:36:35 +02004398 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4399 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400 u8 *dst = NULL;
4401
4402 if (info->attrs[NL80211_ATTR_MAC])
4403 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4404
Johannes Berg4c476992010-10-04 21:36:35 +02004405 if (!rdev->ops->del_mpath)
4406 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004407
Hila Gonene35e4d22012-06-27 17:19:42 +03004408 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004409}
4410
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004411static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4412{
Johannes Berg4c476992010-10-04 21:36:35 +02004413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4414 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004415 struct bss_parameters params;
4416
4417 memset(&params, 0, sizeof(params));
4418 /* default to not changing parameters */
4419 params.use_cts_prot = -1;
4420 params.use_short_preamble = -1;
4421 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004422 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004423 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004424 params.p2p_ctwindow = -1;
4425 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004426
4427 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4428 params.use_cts_prot =
4429 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4430 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4431 params.use_short_preamble =
4432 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4433 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4434 params.use_short_slot_time =
4435 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004436 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4437 params.basic_rates =
4438 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4439 params.basic_rates_len =
4440 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4441 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004442 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4443 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004444 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4445 params.ht_opmode =
4446 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004447
Johannes Berg53cabad2012-11-14 15:17:28 +01004448 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4450 return -EINVAL;
4451 params.p2p_ctwindow =
4452 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4453 if (params.p2p_ctwindow < 0)
4454 return -EINVAL;
4455 if (params.p2p_ctwindow != 0 &&
4456 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4457 return -EINVAL;
4458 }
4459
4460 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4461 u8 tmp;
4462
4463 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4464 return -EINVAL;
4465 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4466 if (tmp > 1)
4467 return -EINVAL;
4468 params.p2p_opp_ps = tmp;
4469 if (params.p2p_opp_ps &&
4470 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4471 return -EINVAL;
4472 }
4473
Johannes Berg4c476992010-10-04 21:36:35 +02004474 if (!rdev->ops->change_bss)
4475 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004476
Johannes Berg074ac8d2010-09-16 14:58:22 +02004477 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004478 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4479 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004480
Hila Gonene35e4d22012-06-27 17:19:42 +03004481 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004482}
4483
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004484static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004485 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4486 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4487 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4488 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4489 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4490 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4491};
4492
4493static int parse_reg_rule(struct nlattr *tb[],
4494 struct ieee80211_reg_rule *reg_rule)
4495{
4496 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4497 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4498
4499 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4500 return -EINVAL;
4501 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4502 return -EINVAL;
4503 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4504 return -EINVAL;
4505 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4506 return -EINVAL;
4507 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4508 return -EINVAL;
4509
4510 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4511
4512 freq_range->start_freq_khz =
4513 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4514 freq_range->end_freq_khz =
4515 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4516 freq_range->max_bandwidth_khz =
4517 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4518
4519 power_rule->max_eirp =
4520 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4521
4522 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4523 power_rule->max_antenna_gain =
4524 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4525
4526 return 0;
4527}
4528
4529static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4530{
4531 int r;
4532 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004533 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004534
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004535 /*
4536 * You should only get this when cfg80211 hasn't yet initialized
4537 * completely when built-in to the kernel right between the time
4538 * window between nl80211_init() and regulatory_init(), if that is
4539 * even possible.
4540 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004541 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004542 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004543
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004544 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4545 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004546
4547 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4548
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004549 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4550 user_reg_hint_type =
4551 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4552 else
4553 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4554
4555 switch (user_reg_hint_type) {
4556 case NL80211_USER_REG_HINT_USER:
4557 case NL80211_USER_REG_HINT_CELL_BASE:
4558 break;
4559 default:
4560 return -EINVAL;
4561 }
4562
4563 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004564
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004565 return r;
4566}
4567
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004568static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004569 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004570{
Johannes Berg4c476992010-10-04 21:36:35 +02004571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004572 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004573 struct wireless_dev *wdev = dev->ieee80211_ptr;
4574 struct mesh_config cur_params;
4575 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004576 void *hdr;
4577 struct nlattr *pinfoattr;
4578 struct sk_buff *msg;
4579
Johannes Berg29cbe682010-12-03 09:20:44 +01004580 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4581 return -EOPNOTSUPP;
4582
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004583 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004584 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004585
Johannes Berg29cbe682010-12-03 09:20:44 +01004586 wdev_lock(wdev);
4587 /* If not connected, get default parameters */
4588 if (!wdev->mesh_id_len)
4589 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4590 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004591 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004592 wdev_unlock(wdev);
4593
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004595 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004596
4597 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004599 if (!msg)
4600 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004601 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004602 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004603 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004604 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004605 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004606 if (!pinfoattr)
4607 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004608 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4609 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4610 cur_params.dot11MeshRetryTimeout) ||
4611 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4612 cur_params.dot11MeshConfirmTimeout) ||
4613 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4614 cur_params.dot11MeshHoldingTimeout) ||
4615 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4616 cur_params.dot11MeshMaxPeerLinks) ||
4617 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4618 cur_params.dot11MeshMaxRetries) ||
4619 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4620 cur_params.dot11MeshTTL) ||
4621 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4622 cur_params.element_ttl) ||
4623 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4624 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004625 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4626 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004627 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4628 cur_params.dot11MeshHWMPmaxPREQretries) ||
4629 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4630 cur_params.path_refresh_time) ||
4631 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4632 cur_params.min_discovery_timeout) ||
4633 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4634 cur_params.dot11MeshHWMPactivePathTimeout) ||
4635 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4636 cur_params.dot11MeshHWMPpreqMinInterval) ||
4637 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4638 cur_params.dot11MeshHWMPperrMinInterval) ||
4639 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4640 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4641 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4642 cur_params.dot11MeshHWMPRootMode) ||
4643 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4644 cur_params.dot11MeshHWMPRannInterval) ||
4645 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4646 cur_params.dot11MeshGateAnnouncementProtocol) ||
4647 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4648 cur_params.dot11MeshForwarding) ||
4649 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004650 cur_params.rssi_threshold) ||
4651 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004652 cur_params.ht_opmode) ||
4653 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4654 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4655 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004656 cur_params.dot11MeshHWMProotInterval) ||
4657 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004658 cur_params.dot11MeshHWMPconfirmationInterval) ||
4659 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4660 cur_params.power_mode) ||
4661 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004662 cur_params.dot11MeshAwakeWindowDuration) ||
4663 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4664 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004665 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004666 nla_nest_end(msg, pinfoattr);
4667 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004668 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004669
Johannes Berg3b858752009-03-12 09:55:09 +01004670 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004671 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004672 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004673 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004674 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004675}
4676
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004677static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004678 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4679 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4680 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4681 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4682 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4683 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004684 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004685 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004686 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004687 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4688 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4689 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4690 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4691 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004692 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004693 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004694 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004695 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004696 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004697 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004698 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4699 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004700 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4701 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004702 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004703 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4704 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004705 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004706};
4707
Javier Cardonac80d5452010-12-16 17:37:49 -08004708static const struct nla_policy
4709 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004710 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004711 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4712 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004713 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004714 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004715 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004716 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004717 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004718 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004719};
4720
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004721static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004722 struct mesh_config *cfg,
4723 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004724{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004725 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004726 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004727
Marco Porschea54fba2013-01-07 16:04:48 +01004728#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4729do { \
4730 if (tb[attr]) { \
4731 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4732 return -EINVAL; \
4733 cfg->param = fn(tb[attr]); \
4734 mask |= (1 << (attr - 1)); \
4735 } \
4736} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004737
4738
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004739 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004740 return -EINVAL;
4741 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004742 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004743 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004744 return -EINVAL;
4745
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004746 /* This makes sure that there aren't more than 32 mesh config
4747 * parameters (otherwise our bitfield scheme would not work.) */
4748 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4749
4750 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004752 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4753 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004755 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4756 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004757 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004758 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4759 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004760 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004761 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4762 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004763 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004764 mask, NL80211_MESHCONF_MAX_RETRIES,
4765 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004766 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004767 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004768 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004769 mask, NL80211_MESHCONF_ELEMENT_TTL,
4770 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004771 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004772 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4773 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004774 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4775 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004776 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4777 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004778 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004779 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4780 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004781 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004782 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4783 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004784 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004785 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4786 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004787 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4788 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004789 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4790 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004791 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004792 1, 65535, mask,
4793 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004794 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004796 1, 65535, mask,
4797 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004798 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004799 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004800 dot11MeshHWMPnetDiameterTraversalTime,
4801 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004802 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4803 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004804 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4805 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4806 nla_get_u8);
4807 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4808 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004809 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004810 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004811 dot11MeshGateAnnouncementProtocol, 0, 1,
4812 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004813 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004814 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004815 mask, NL80211_MESHCONF_FORWARDING,
4816 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004817 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004818 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004819 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004820 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004821 mask, NL80211_MESHCONF_HT_OPMODE,
4822 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004823 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004824 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004825 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4826 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004827 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004828 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4829 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004830 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004831 dot11MeshHWMPconfirmationInterval,
4832 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004833 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4834 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004835 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4836 NL80211_MESH_POWER_ACTIVE,
4837 NL80211_MESH_POWER_MAX,
4838 mask, NL80211_MESHCONF_POWER_MODE,
4839 nla_get_u32);
4840 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4841 0, 65535, mask,
4842 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004843 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4844 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4845 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004846 if (mask_out)
4847 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004848
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004849 return 0;
4850
4851#undef FILL_IN_MESH_PARAM_IF_SET
4852}
4853
Javier Cardonac80d5452010-12-16 17:37:49 -08004854static int nl80211_parse_mesh_setup(struct genl_info *info,
4855 struct mesh_setup *setup)
4856{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004858 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4859
4860 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4861 return -EINVAL;
4862 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4863 info->attrs[NL80211_ATTR_MESH_SETUP],
4864 nl80211_mesh_setup_params_policy))
4865 return -EINVAL;
4866
Javier Cardonad299a1f2012-03-31 11:31:33 -07004867 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4868 setup->sync_method =
4869 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4870 IEEE80211_SYNC_METHOD_VENDOR :
4871 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4872
Javier Cardonac80d5452010-12-16 17:37:49 -08004873 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4874 setup->path_sel_proto =
4875 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4876 IEEE80211_PATH_PROTOCOL_VENDOR :
4877 IEEE80211_PATH_PROTOCOL_HWMP;
4878
4879 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4880 setup->path_metric =
4881 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4882 IEEE80211_PATH_METRIC_VENDOR :
4883 IEEE80211_PATH_METRIC_AIRTIME;
4884
Javier Cardona581a8b02011-04-07 15:08:27 -07004885
4886 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004887 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004888 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004889 if (!is_valid_ie_attr(ieattr))
4890 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004891 setup->ie = nla_data(ieattr);
4892 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004893 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004894 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4895 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4896 return -EINVAL;
4897 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004898 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4899 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004900 if (setup->is_secure)
4901 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004902
Colleen Twitty6e16d902013-05-08 11:45:59 -07004903 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4904 if (!setup->user_mpm)
4905 return -EINVAL;
4906 setup->auth_id =
4907 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4908 }
4909
Javier Cardonac80d5452010-12-16 17:37:49 -08004910 return 0;
4911}
4912
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004913static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004914 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004915{
4916 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4917 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004918 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004919 struct mesh_config cfg;
4920 u32 mask;
4921 int err;
4922
Johannes Berg29cbe682010-12-03 09:20:44 +01004923 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4924 return -EOPNOTSUPP;
4925
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004926 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004927 return -EOPNOTSUPP;
4928
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004929 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004930 if (err)
4931 return err;
4932
Johannes Berg29cbe682010-12-03 09:20:44 +01004933 wdev_lock(wdev);
4934 if (!wdev->mesh_id_len)
4935 err = -ENOLINK;
4936
4937 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004938 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004939
4940 wdev_unlock(wdev);
4941
4942 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004943}
4944
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004945static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4946{
Johannes Berg458f4f92012-12-06 15:47:38 +01004947 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004948 struct sk_buff *msg;
4949 void *hdr = NULL;
4950 struct nlattr *nl_reg_rules;
4951 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004952
4953 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004954 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004955
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004957 if (!msg)
4958 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004959
Eric W. Biederman15e47302012-09-07 20:12:54 +00004960 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004961 NL80211_CMD_GET_REG);
4962 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004963 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004964
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004965 if (reg_last_request_cell_base() &&
4966 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4967 NL80211_USER_REG_HINT_CELL_BASE))
4968 goto nla_put_failure;
4969
Johannes Berg458f4f92012-12-06 15:47:38 +01004970 rcu_read_lock();
4971 regdom = rcu_dereference(cfg80211_regdomain);
4972
4973 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4974 (regdom->dfs_region &&
4975 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4976 goto nla_put_failure_rcu;
4977
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004978 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4979 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004980 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004981
Johannes Berg458f4f92012-12-06 15:47:38 +01004982 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004983 struct nlattr *nl_reg_rule;
4984 const struct ieee80211_reg_rule *reg_rule;
4985 const struct ieee80211_freq_range *freq_range;
4986 const struct ieee80211_power_rule *power_rule;
4987
Johannes Berg458f4f92012-12-06 15:47:38 +01004988 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004989 freq_range = &reg_rule->freq_range;
4990 power_rule = &reg_rule->power_rule;
4991
4992 nl_reg_rule = nla_nest_start(msg, i);
4993 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004994 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004995
David S. Miller9360ffd2012-03-29 04:41:26 -04004996 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4997 reg_rule->flags) ||
4998 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4999 freq_range->start_freq_khz) ||
5000 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5001 freq_range->end_freq_khz) ||
5002 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5003 freq_range->max_bandwidth_khz) ||
5004 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5005 power_rule->max_antenna_gain) ||
5006 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5007 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005008 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005009
5010 nla_nest_end(msg, nl_reg_rule);
5011 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005012 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005013
5014 nla_nest_end(msg, nl_reg_rules);
5015
5016 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005017 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005018
Johannes Berg458f4f92012-12-06 15:47:38 +01005019nla_put_failure_rcu:
5020 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005021nla_put_failure:
5022 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005023put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005024 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005025 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005026}
5027
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005028static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5029{
5030 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5031 struct nlattr *nl_reg_rule;
5032 char *alpha2 = NULL;
5033 int rem_reg_rules = 0, r = 0;
5034 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005035 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005036 struct ieee80211_regdomain *rd = NULL;
5037
5038 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5039 return -EINVAL;
5040
5041 if (!info->attrs[NL80211_ATTR_REG_RULES])
5042 return -EINVAL;
5043
5044 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5045
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005046 if (info->attrs[NL80211_ATTR_DFS_REGION])
5047 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5048
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005049 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005050 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005051 num_rules++;
5052 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005053 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005054 }
5055
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005056 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005057 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005058
5059 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005060 if (!rd)
5061 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005062
5063 rd->n_reg_rules = num_rules;
5064 rd->alpha2[0] = alpha2[0];
5065 rd->alpha2[1] = alpha2[1];
5066
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005067 /*
5068 * Disable DFS master mode if the DFS region was
5069 * not supported or known on this kernel.
5070 */
5071 if (reg_supported_dfs_region(dfs_region))
5072 rd->dfs_region = dfs_region;
5073
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005074 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005075 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005076 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005077 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5078 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005079 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5080 if (r)
5081 goto bad_reg;
5082
5083 rule_idx++;
5084
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005085 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5086 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005087 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005088 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005089 }
5090
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005091 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005092 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005093 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005094
Johannes Bergd2372b32008-10-24 20:32:20 +02005095 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005096 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005097 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005098}
5099
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005100static int validate_scan_freqs(struct nlattr *freqs)
5101{
5102 struct nlattr *attr1, *attr2;
5103 int n_channels = 0, tmp1, tmp2;
5104
5105 nla_for_each_nested(attr1, freqs, tmp1) {
5106 n_channels++;
5107 /*
5108 * Some hardware has a limited channel list for
5109 * scanning, and it is pretty much nonsensical
5110 * to scan for a channel twice, so disallow that
5111 * and don't require drivers to check that the
5112 * channel list they get isn't longer than what
5113 * they can scan, as long as they can scan all
5114 * the channels they registered at once.
5115 */
5116 nla_for_each_nested(attr2, freqs, tmp2)
5117 if (attr1 != attr2 &&
5118 nla_get_u32(attr1) == nla_get_u32(attr2))
5119 return 0;
5120 }
5121
5122 return n_channels;
5123}
5124
Johannes Berg2a519312009-02-10 21:25:55 +01005125static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5126{
Johannes Berg4c476992010-10-04 21:36:35 +02005127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005128 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005129 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005130 struct nlattr *attr;
5131 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005132 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005133 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005134
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005135 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5136 return -EINVAL;
5137
Johannes Berg79c97e92009-07-07 03:56:12 +02005138 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005139
Johannes Berg4c476992010-10-04 21:36:35 +02005140 if (!rdev->ops->scan)
5141 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005142
Johannes Bergf9f47522013-03-19 15:04:07 +01005143 if (rdev->scan_req) {
5144 err = -EBUSY;
5145 goto unlock;
5146 }
Johannes Berg2a519312009-02-10 21:25:55 +01005147
5148 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005149 n_channels = validate_scan_freqs(
5150 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005151 if (!n_channels) {
5152 err = -EINVAL;
5153 goto unlock;
5154 }
Johannes Berg2a519312009-02-10 21:25:55 +01005155 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005156 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005157 n_channels = 0;
5158
Johannes Berg2a519312009-02-10 21:25:55 +01005159 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5160 if (wiphy->bands[band])
5161 n_channels += wiphy->bands[band]->n_channels;
5162 }
5163
5164 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5165 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5166 n_ssids++;
5167
Johannes Bergf9f47522013-03-19 15:04:07 +01005168 if (n_ssids > wiphy->max_scan_ssids) {
5169 err = -EINVAL;
5170 goto unlock;
5171 }
Johannes Berg2a519312009-02-10 21:25:55 +01005172
Jouni Malinen70692ad2009-02-16 19:39:13 +02005173 if (info->attrs[NL80211_ATTR_IE])
5174 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5175 else
5176 ie_len = 0;
5177
Johannes Bergf9f47522013-03-19 15:04:07 +01005178 if (ie_len > wiphy->max_scan_ie_len) {
5179 err = -EINVAL;
5180 goto unlock;
5181 }
Johannes Berg18a83652009-03-31 12:12:05 +02005182
Johannes Berg2a519312009-02-10 21:25:55 +01005183 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005184 + sizeof(*request->ssids) * n_ssids
5185 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005186 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005187 if (!request) {
5188 err = -ENOMEM;
5189 goto unlock;
5190 }
Johannes Berg2a519312009-02-10 21:25:55 +01005191
Johannes Berg2a519312009-02-10 21:25:55 +01005192 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005193 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005194 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005195 if (ie_len) {
5196 if (request->ssids)
5197 request->ie = (void *)(request->ssids + n_ssids);
5198 else
5199 request->ie = (void *)(request->channels + n_channels);
5200 }
Johannes Berg2a519312009-02-10 21:25:55 +01005201
Johannes Berg584991d2009-11-02 13:32:03 +01005202 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005203 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5204 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005205 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005206 struct ieee80211_channel *chan;
5207
5208 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5209
5210 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005211 err = -EINVAL;
5212 goto out_free;
5213 }
Johannes Berg584991d2009-11-02 13:32:03 +01005214
5215 /* ignore disabled channels */
5216 if (chan->flags & IEEE80211_CHAN_DISABLED)
5217 continue;
5218
5219 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005220 i++;
5221 }
5222 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005223 enum ieee80211_band band;
5224
Johannes Berg2a519312009-02-10 21:25:55 +01005225 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005226 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5227 int j;
5228 if (!wiphy->bands[band])
5229 continue;
5230 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005231 struct ieee80211_channel *chan;
5232
5233 chan = &wiphy->bands[band]->channels[j];
5234
5235 if (chan->flags & IEEE80211_CHAN_DISABLED)
5236 continue;
5237
5238 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005239 i++;
5240 }
5241 }
5242 }
5243
Johannes Berg584991d2009-11-02 13:32:03 +01005244 if (!i) {
5245 err = -EINVAL;
5246 goto out_free;
5247 }
5248
5249 request->n_channels = i;
5250
Johannes Berg2a519312009-02-10 21:25:55 +01005251 i = 0;
5252 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5253 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005254 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005255 err = -EINVAL;
5256 goto out_free;
5257 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005258 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005259 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005260 i++;
5261 }
5262 }
5263
Jouni Malinen70692ad2009-02-16 19:39:13 +02005264 if (info->attrs[NL80211_ATTR_IE]) {
5265 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005266 memcpy((void *)request->ie,
5267 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005268 request->ie_len);
5269 }
5270
Johannes Berg34850ab2011-07-18 18:08:35 +02005271 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005272 if (wiphy->bands[i])
5273 request->rates[i] =
5274 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005275
5276 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5277 nla_for_each_nested(attr,
5278 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5279 tmp) {
5280 enum ieee80211_band band = nla_type(attr);
5281
Dan Carpenter84404622011-07-29 11:52:18 +03005282 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005283 err = -EINVAL;
5284 goto out_free;
5285 }
5286 err = ieee80211_get_ratemask(wiphy->bands[band],
5287 nla_data(attr),
5288 nla_len(attr),
5289 &request->rates[band]);
5290 if (err)
5291 goto out_free;
5292 }
5293 }
5294
Sam Leffler46856bb2012-10-11 21:03:32 -07005295 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005296 request->flags = nla_get_u32(
5297 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005298 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5299 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5300 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5301 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005302 err = -EOPNOTSUPP;
5303 goto out_free;
5304 }
5305 }
Sam Lefflered4737712012-10-11 21:03:31 -07005306
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305307 request->no_cck =
5308 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5309
Johannes Bergfd014282012-06-18 19:17:03 +02005310 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005311 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005312 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005313
Johannes Berg79c97e92009-07-07 03:56:12 +02005314 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005315 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005316
Johannes Berg463d0182009-07-14 00:33:35 +02005317 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005318 nl80211_send_scan_start(rdev, wdev);
5319 if (wdev->netdev)
5320 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005321 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005322 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005323 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005324 kfree(request);
5325 }
Johannes Berg3b858752009-03-12 09:55:09 +01005326
Johannes Bergf9f47522013-03-19 15:04:07 +01005327 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005328 return err;
5329}
5330
Luciano Coelho807f8a82011-05-11 17:09:35 +03005331static int nl80211_start_sched_scan(struct sk_buff *skb,
5332 struct genl_info *info)
5333{
5334 struct cfg80211_sched_scan_request *request;
5335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5336 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005337 struct nlattr *attr;
5338 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005339 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005340 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005341 enum ieee80211_band band;
5342 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005343 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005344
5345 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5346 !rdev->ops->sched_scan_start)
5347 return -EOPNOTSUPP;
5348
5349 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5350 return -EINVAL;
5351
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005352 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5353 return -EINVAL;
5354
5355 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5356 if (interval == 0)
5357 return -EINVAL;
5358
Luciano Coelho807f8a82011-05-11 17:09:35 +03005359 wiphy = &rdev->wiphy;
5360
5361 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5362 n_channels = validate_scan_freqs(
5363 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5364 if (!n_channels)
5365 return -EINVAL;
5366 } else {
5367 n_channels = 0;
5368
5369 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5370 if (wiphy->bands[band])
5371 n_channels += wiphy->bands[band]->n_channels;
5372 }
5373
5374 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5375 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5376 tmp)
5377 n_ssids++;
5378
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005379 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005380 return -EINVAL;
5381
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005382 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5383 nla_for_each_nested(attr,
5384 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5385 tmp)
5386 n_match_sets++;
5387
5388 if (n_match_sets > wiphy->max_match_sets)
5389 return -EINVAL;
5390
Luciano Coelho807f8a82011-05-11 17:09:35 +03005391 if (info->attrs[NL80211_ATTR_IE])
5392 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5393 else
5394 ie_len = 0;
5395
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005396 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005397 return -EINVAL;
5398
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005399 if (rdev->sched_scan_req) {
5400 err = -EINPROGRESS;
5401 goto out;
5402 }
5403
Luciano Coelho807f8a82011-05-11 17:09:35 +03005404 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005405 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005406 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005407 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005408 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005409 if (!request) {
5410 err = -ENOMEM;
5411 goto out;
5412 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005413
5414 if (n_ssids)
5415 request->ssids = (void *)&request->channels[n_channels];
5416 request->n_ssids = n_ssids;
5417 if (ie_len) {
5418 if (request->ssids)
5419 request->ie = (void *)(request->ssids + n_ssids);
5420 else
5421 request->ie = (void *)(request->channels + n_channels);
5422 }
5423
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005424 if (n_match_sets) {
5425 if (request->ie)
5426 request->match_sets = (void *)(request->ie + ie_len);
5427 else if (request->ssids)
5428 request->match_sets =
5429 (void *)(request->ssids + n_ssids);
5430 else
5431 request->match_sets =
5432 (void *)(request->channels + n_channels);
5433 }
5434 request->n_match_sets = n_match_sets;
5435
Luciano Coelho807f8a82011-05-11 17:09:35 +03005436 i = 0;
5437 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5438 /* user specified, bail out if channel not found */
5439 nla_for_each_nested(attr,
5440 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5441 tmp) {
5442 struct ieee80211_channel *chan;
5443
5444 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5445
5446 if (!chan) {
5447 err = -EINVAL;
5448 goto out_free;
5449 }
5450
5451 /* ignore disabled channels */
5452 if (chan->flags & IEEE80211_CHAN_DISABLED)
5453 continue;
5454
5455 request->channels[i] = chan;
5456 i++;
5457 }
5458 } else {
5459 /* all channels */
5460 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5461 int j;
5462 if (!wiphy->bands[band])
5463 continue;
5464 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5465 struct ieee80211_channel *chan;
5466
5467 chan = &wiphy->bands[band]->channels[j];
5468
5469 if (chan->flags & IEEE80211_CHAN_DISABLED)
5470 continue;
5471
5472 request->channels[i] = chan;
5473 i++;
5474 }
5475 }
5476 }
5477
5478 if (!i) {
5479 err = -EINVAL;
5480 goto out_free;
5481 }
5482
5483 request->n_channels = i;
5484
5485 i = 0;
5486 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5487 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5488 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005489 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005490 err = -EINVAL;
5491 goto out_free;
5492 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005493 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005494 memcpy(request->ssids[i].ssid, nla_data(attr),
5495 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005496 i++;
5497 }
5498 }
5499
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005500 i = 0;
5501 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5502 nla_for_each_nested(attr,
5503 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5504 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005505 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005506
5507 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5508 nla_data(attr), nla_len(attr),
5509 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005510 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005511 if (ssid) {
5512 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5513 err = -EINVAL;
5514 goto out_free;
5515 }
5516 memcpy(request->match_sets[i].ssid.ssid,
5517 nla_data(ssid), nla_len(ssid));
5518 request->match_sets[i].ssid.ssid_len =
5519 nla_len(ssid);
5520 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005521 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5522 if (rssi)
5523 request->rssi_thold = nla_get_u32(rssi);
5524 else
5525 request->rssi_thold =
5526 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005527 i++;
5528 }
5529 }
5530
Luciano Coelho807f8a82011-05-11 17:09:35 +03005531 if (info->attrs[NL80211_ATTR_IE]) {
5532 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5533 memcpy((void *)request->ie,
5534 nla_data(info->attrs[NL80211_ATTR_IE]),
5535 request->ie_len);
5536 }
5537
Sam Leffler46856bb2012-10-11 21:03:32 -07005538 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005539 request->flags = nla_get_u32(
5540 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005541 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5542 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5543 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5544 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005545 err = -EOPNOTSUPP;
5546 goto out_free;
5547 }
5548 }
Sam Lefflered4737712012-10-11 21:03:31 -07005549
Luciano Coelho807f8a82011-05-11 17:09:35 +03005550 request->dev = dev;
5551 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005552 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005553 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005554
Hila Gonene35e4d22012-06-27 17:19:42 +03005555 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005556 if (!err) {
5557 rdev->sched_scan_req = request;
5558 nl80211_send_sched_scan(rdev, dev,
5559 NL80211_CMD_START_SCHED_SCAN);
5560 goto out;
5561 }
5562
5563out_free:
5564 kfree(request);
5565out:
5566 return err;
5567}
5568
5569static int nl80211_stop_sched_scan(struct sk_buff *skb,
5570 struct genl_info *info)
5571{
5572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5573
5574 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5575 !rdev->ops->sched_scan_stop)
5576 return -EOPNOTSUPP;
5577
Johannes Berg5fe231e2013-05-08 21:45:15 +02005578 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005579}
5580
Simon Wunderlich04f39042013-02-08 18:16:19 +01005581static int nl80211_start_radar_detection(struct sk_buff *skb,
5582 struct genl_info *info)
5583{
5584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5585 struct net_device *dev = info->user_ptr[1];
5586 struct wireless_dev *wdev = dev->ieee80211_ptr;
5587 struct cfg80211_chan_def chandef;
5588 int err;
5589
5590 err = nl80211_parse_chandef(rdev, info, &chandef);
5591 if (err)
5592 return err;
5593
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005594 if (netif_carrier_ok(dev))
5595 return -EBUSY;
5596
Simon Wunderlich04f39042013-02-08 18:16:19 +01005597 if (wdev->cac_started)
5598 return -EBUSY;
5599
5600 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5601 if (err < 0)
5602 return err;
5603
5604 if (err == 0)
5605 return -EINVAL;
5606
5607 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5608 return -EINVAL;
5609
5610 if (!rdev->ops->start_radar_detection)
5611 return -EOPNOTSUPP;
5612
Simon Wunderlich04f39042013-02-08 18:16:19 +01005613 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5614 chandef.chan, CHAN_MODE_SHARED,
5615 BIT(chandef.width));
5616 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005617 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005618
5619 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5620 if (!err) {
5621 wdev->channel = chandef.chan;
5622 wdev->cac_started = true;
5623 wdev->cac_start_time = jiffies;
5624 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005625 return err;
5626}
5627
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005628static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5629{
5630 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5631 struct net_device *dev = info->user_ptr[1];
5632 struct wireless_dev *wdev = dev->ieee80211_ptr;
5633 struct cfg80211_csa_settings params;
5634 /* csa_attrs is defined static to avoid waste of stack size - this
5635 * function is called under RTNL lock, so this should not be a problem.
5636 */
5637 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5638 u8 radar_detect_width = 0;
5639 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005640 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005641
5642 if (!rdev->ops->channel_switch ||
5643 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5644 return -EOPNOTSUPP;
5645
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005646 switch (dev->ieee80211_ptr->iftype) {
5647 case NL80211_IFTYPE_AP:
5648 case NL80211_IFTYPE_P2P_GO:
5649 need_new_beacon = true;
5650
5651 /* useless if AP is not running */
5652 if (!wdev->beacon_interval)
5653 return -EINVAL;
5654 break;
5655 case NL80211_IFTYPE_ADHOC:
5656 break;
5657 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005658 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005659 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005660
5661 memset(&params, 0, sizeof(params));
5662
5663 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5664 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5665 return -EINVAL;
5666
5667 /* only important for AP, IBSS and mesh create IEs internally */
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005668 if (need_new_beacon &&
5669 (!info->attrs[NL80211_ATTR_CSA_IES] ||
5670 !info->attrs[NL80211_ATTR_CSA_C_OFF_BEACON]))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005671 return -EINVAL;
5672
5673 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5674
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005675 if (!need_new_beacon)
5676 goto skip_beacons;
5677
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005678 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5679 if (err)
5680 return err;
5681
5682 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5683 info->attrs[NL80211_ATTR_CSA_IES],
5684 nl80211_policy);
5685 if (err)
5686 return err;
5687
5688 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5689 if (err)
5690 return err;
5691
5692 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5693 return -EINVAL;
5694
5695 params.counter_offset_beacon =
5696 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5697 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5698 return -EINVAL;
5699
5700 /* sanity check - counters should be the same */
5701 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5702 params.count)
5703 return -EINVAL;
5704
5705 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5706 params.counter_offset_presp =
5707 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5708 if (params.counter_offset_presp >=
5709 params.beacon_csa.probe_resp_len)
5710 return -EINVAL;
5711
5712 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5713 params.count)
5714 return -EINVAL;
5715 }
5716
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005717skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005718 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5719 if (err)
5720 return err;
5721
5722 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5723 return -EINVAL;
5724
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005725 /* DFS channels are only supported for AP/P2P GO ... for now. */
5726 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
5727 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO) {
5728 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5729 &params.chandef);
5730 if (err < 0) {
5731 return err;
5732 } else if (err) {
5733 radar_detect_width = BIT(params.chandef.width);
5734 params.radar_required = true;
5735 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005736 }
5737
5738 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5739 params.chandef.chan,
5740 CHAN_MODE_SHARED,
5741 radar_detect_width);
5742 if (err)
5743 return err;
5744
5745 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5746 params.block_tx = true;
5747
5748 return rdev_channel_switch(rdev, dev, &params);
5749}
5750
Johannes Berg9720bb32011-06-21 09:45:33 +02005751static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5752 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005753 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005754 struct wireless_dev *wdev,
5755 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005756{
Johannes Berg48ab9052009-07-10 18:42:31 +02005757 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005758 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005759 void *hdr;
5760 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005761 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005762
5763 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005764
Eric W. Biederman15e47302012-09-07 20:12:54 +00005765 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005766 NL80211_CMD_NEW_SCAN_RESULTS);
5767 if (!hdr)
5768 return -1;
5769
Johannes Berg9720bb32011-06-21 09:45:33 +02005770 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5771
Johannes Berg97990a02013-04-19 01:02:55 +02005772 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5773 goto nla_put_failure;
5774 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005775 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5776 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005777 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5778 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005779
5780 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5781 if (!bss)
5782 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005783 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005784 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005785 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005786
5787 rcu_read_lock();
5788 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005789 if (ies) {
5790 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5791 goto fail_unlock_rcu;
5792 tsf = true;
5793 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5794 ies->len, ies->data))
5795 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005796 }
5797 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005798 if (ies) {
5799 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5800 goto fail_unlock_rcu;
5801 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5802 ies->len, ies->data))
5803 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005804 }
5805 rcu_read_unlock();
5806
David S. Miller9360ffd2012-03-29 04:41:26 -04005807 if (res->beacon_interval &&
5808 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5809 goto nla_put_failure;
5810 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5811 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005812 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005813 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5814 jiffies_to_msecs(jiffies - intbss->ts)))
5815 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005816
Johannes Berg77965c92009-02-18 18:45:06 +01005817 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005818 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005819 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5820 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005821 break;
5822 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005823 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5824 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005825 break;
5826 default:
5827 break;
5828 }
5829
Johannes Berg48ab9052009-07-10 18:42:31 +02005830 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005831 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005832 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005833 if (intbss == wdev->current_bss &&
5834 nla_put_u32(msg, NL80211_BSS_STATUS,
5835 NL80211_BSS_STATUS_ASSOCIATED))
5836 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005837 break;
5838 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005839 if (intbss == wdev->current_bss &&
5840 nla_put_u32(msg, NL80211_BSS_STATUS,
5841 NL80211_BSS_STATUS_IBSS_JOINED))
5842 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005843 break;
5844 default:
5845 break;
5846 }
5847
Johannes Berg2a519312009-02-10 21:25:55 +01005848 nla_nest_end(msg, bss);
5849
5850 return genlmsg_end(msg, hdr);
5851
Johannes Berg8cef2c92013-02-05 16:54:31 +01005852 fail_unlock_rcu:
5853 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005854 nla_put_failure:
5855 genlmsg_cancel(msg, hdr);
5856 return -EMSGSIZE;
5857}
5858
Johannes Berg97990a02013-04-19 01:02:55 +02005859static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005860{
Johannes Berg48ab9052009-07-10 18:42:31 +02005861 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005862 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005863 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005864 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005865 int err;
5866
Johannes Berg97990a02013-04-19 01:02:55 +02005867 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005868 if (err)
5869 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005870
Johannes Berg48ab9052009-07-10 18:42:31 +02005871 wdev_lock(wdev);
5872 spin_lock_bh(&rdev->bss_lock);
5873 cfg80211_bss_expire(rdev);
5874
Johannes Berg9720bb32011-06-21 09:45:33 +02005875 cb->seq = rdev->bss_generation;
5876
Johannes Berg48ab9052009-07-10 18:42:31 +02005877 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005878 if (++idx <= start)
5879 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005880 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005881 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005882 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005883 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005884 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005885 }
5886 }
5887
Johannes Berg48ab9052009-07-10 18:42:31 +02005888 spin_unlock_bh(&rdev->bss_lock);
5889 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005890
Johannes Berg97990a02013-04-19 01:02:55 +02005891 cb->args[2] = idx;
5892 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005893
Johannes Berg67748892010-10-04 21:14:06 +02005894 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005895}
5896
Eric W. Biederman15e47302012-09-07 20:12:54 +00005897static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005898 int flags, struct net_device *dev,
5899 struct survey_info *survey)
5900{
5901 void *hdr;
5902 struct nlattr *infoattr;
5903
Eric W. Biederman15e47302012-09-07 20:12:54 +00005904 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005905 NL80211_CMD_NEW_SURVEY_RESULTS);
5906 if (!hdr)
5907 return -ENOMEM;
5908
David S. Miller9360ffd2012-03-29 04:41:26 -04005909 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5910 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005911
5912 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5913 if (!infoattr)
5914 goto nla_put_failure;
5915
David S. Miller9360ffd2012-03-29 04:41:26 -04005916 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5917 survey->channel->center_freq))
5918 goto nla_put_failure;
5919
5920 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5921 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5922 goto nla_put_failure;
5923 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5924 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5925 goto nla_put_failure;
5926 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5927 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5928 survey->channel_time))
5929 goto nla_put_failure;
5930 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5931 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5932 survey->channel_time_busy))
5933 goto nla_put_failure;
5934 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5935 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5936 survey->channel_time_ext_busy))
5937 goto nla_put_failure;
5938 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5939 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5940 survey->channel_time_rx))
5941 goto nla_put_failure;
5942 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5943 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5944 survey->channel_time_tx))
5945 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005946
5947 nla_nest_end(msg, infoattr);
5948
5949 return genlmsg_end(msg, hdr);
5950
5951 nla_put_failure:
5952 genlmsg_cancel(msg, hdr);
5953 return -EMSGSIZE;
5954}
5955
5956static int nl80211_dump_survey(struct sk_buff *skb,
5957 struct netlink_callback *cb)
5958{
5959 struct survey_info survey;
5960 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005961 struct wireless_dev *wdev;
5962 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005963 int res;
5964
Johannes Berg97990a02013-04-19 01:02:55 +02005965 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005966 if (res)
5967 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005968
Johannes Berg97990a02013-04-19 01:02:55 +02005969 if (!wdev->netdev) {
5970 res = -EINVAL;
5971 goto out_err;
5972 }
5973
Holger Schurig61fa7132009-11-11 12:25:40 +01005974 if (!dev->ops->dump_survey) {
5975 res = -EOPNOTSUPP;
5976 goto out_err;
5977 }
5978
5979 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005980 struct ieee80211_channel *chan;
5981
Johannes Berg97990a02013-04-19 01:02:55 +02005982 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005983 if (res == -ENOENT)
5984 break;
5985 if (res)
5986 goto out_err;
5987
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005988 /* Survey without a channel doesn't make sense */
5989 if (!survey.channel) {
5990 res = -EINVAL;
5991 goto out;
5992 }
5993
5994 chan = ieee80211_get_channel(&dev->wiphy,
5995 survey.channel->center_freq);
5996 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5997 survey_idx++;
5998 continue;
5999 }
6000
Holger Schurig61fa7132009-11-11 12:25:40 +01006001 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006002 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006003 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006004 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006005 goto out;
6006 survey_idx++;
6007 }
6008
6009 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006010 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006011 res = skb->len;
6012 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006013 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006014 return res;
6015}
6016
Samuel Ortizb23aa672009-07-01 21:26:54 +02006017static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6018{
6019 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6020 NL80211_WPA_VERSION_2));
6021}
6022
Jouni Malinen636a5d32009-03-19 13:39:22 +02006023static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6024{
Johannes Berg4c476992010-10-04 21:36:35 +02006025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6026 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006027 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006028 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6029 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006030 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006031 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006032 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006033
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006034 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6035 return -EINVAL;
6036
6037 if (!info->attrs[NL80211_ATTR_MAC])
6038 return -EINVAL;
6039
Jouni Malinen17780922009-03-27 20:52:47 +02006040 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6041 return -EINVAL;
6042
Johannes Berg19957bb2009-07-02 17:20:43 +02006043 if (!info->attrs[NL80211_ATTR_SSID])
6044 return -EINVAL;
6045
6046 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6047 return -EINVAL;
6048
Johannes Bergfffd0932009-07-08 14:22:54 +02006049 err = nl80211_parse_key(info, &key);
6050 if (err)
6051 return err;
6052
6053 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006054 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6055 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006056 if (!key.p.key || !key.p.key_len)
6057 return -EINVAL;
6058 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6059 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6060 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6061 key.p.key_len != WLAN_KEY_LEN_WEP104))
6062 return -EINVAL;
6063 if (key.idx > 4)
6064 return -EINVAL;
6065 } else {
6066 key.p.key_len = 0;
6067 key.p.key = NULL;
6068 }
6069
Johannes Bergafea0b72010-08-10 09:46:42 +02006070 if (key.idx >= 0) {
6071 int i;
6072 bool ok = false;
6073 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6074 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6075 ok = true;
6076 break;
6077 }
6078 }
Johannes Berg4c476992010-10-04 21:36:35 +02006079 if (!ok)
6080 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006081 }
6082
Johannes Berg4c476992010-10-04 21:36:35 +02006083 if (!rdev->ops->auth)
6084 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006085
Johannes Berg074ac8d2010-09-16 14:58:22 +02006086 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006087 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6088 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006089
Johannes Berg19957bb2009-07-02 17:20:43 +02006090 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006091 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006092 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006093 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6094 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006095
Johannes Berg19957bb2009-07-02 17:20:43 +02006096 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6097 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6098
6099 if (info->attrs[NL80211_ATTR_IE]) {
6100 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6101 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6102 }
6103
6104 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006105 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006106 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006107
Jouni Malinene39e5b52012-09-30 19:29:39 +03006108 if (auth_type == NL80211_AUTHTYPE_SAE &&
6109 !info->attrs[NL80211_ATTR_SAE_DATA])
6110 return -EINVAL;
6111
6112 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6113 if (auth_type != NL80211_AUTHTYPE_SAE)
6114 return -EINVAL;
6115 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6116 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6117 /* need to include at least Auth Transaction and Status Code */
6118 if (sae_data_len < 4)
6119 return -EINVAL;
6120 }
6121
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006122 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6123
Johannes Berg95de8172012-01-20 13:55:25 +01006124 /*
6125 * Since we no longer track auth state, ignore
6126 * requests to only change local state.
6127 */
6128 if (local_state_change)
6129 return 0;
6130
Johannes Berg91bf9b22013-05-15 17:44:01 +02006131 wdev_lock(dev->ieee80211_ptr);
6132 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6133 ssid, ssid_len, ie, ie_len,
6134 key.p.key, key.p.key_len, key.idx,
6135 sae_data, sae_data_len);
6136 wdev_unlock(dev->ieee80211_ptr);
6137 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006138}
6139
Johannes Bergc0692b82010-08-27 14:26:53 +03006140static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6141 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006142 struct cfg80211_crypto_settings *settings,
6143 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006144{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006145 memset(settings, 0, sizeof(*settings));
6146
Samuel Ortizb23aa672009-07-01 21:26:54 +02006147 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6148
Johannes Bergc0692b82010-08-27 14:26:53 +03006149 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6150 u16 proto;
6151 proto = nla_get_u16(
6152 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6153 settings->control_port_ethertype = cpu_to_be16(proto);
6154 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6155 proto != ETH_P_PAE)
6156 return -EINVAL;
6157 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6158 settings->control_port_no_encrypt = true;
6159 } else
6160 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6161
Samuel Ortizb23aa672009-07-01 21:26:54 +02006162 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6163 void *data;
6164 int len, i;
6165
6166 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6167 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6168 settings->n_ciphers_pairwise = len / sizeof(u32);
6169
6170 if (len % sizeof(u32))
6171 return -EINVAL;
6172
Johannes Berg3dc27d22009-07-02 21:36:37 +02006173 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006174 return -EINVAL;
6175
6176 memcpy(settings->ciphers_pairwise, data, len);
6177
6178 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006179 if (!cfg80211_supported_cipher_suite(
6180 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006181 settings->ciphers_pairwise[i]))
6182 return -EINVAL;
6183 }
6184
6185 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6186 settings->cipher_group =
6187 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006188 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6189 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006190 return -EINVAL;
6191 }
6192
6193 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6194 settings->wpa_versions =
6195 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6196 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6197 return -EINVAL;
6198 }
6199
6200 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6201 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006202 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006203
6204 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6205 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6206 settings->n_akm_suites = len / sizeof(u32);
6207
6208 if (len % sizeof(u32))
6209 return -EINVAL;
6210
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006211 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6212 return -EINVAL;
6213
Samuel Ortizb23aa672009-07-01 21:26:54 +02006214 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006215 }
6216
6217 return 0;
6218}
6219
Jouni Malinen636a5d32009-03-19 13:39:22 +02006220static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6221{
Johannes Berg4c476992010-10-04 21:36:35 +02006222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6223 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006224 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006225 struct cfg80211_assoc_request req = {};
6226 const u8 *bssid, *ssid;
6227 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006228
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006229 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6230 return -EINVAL;
6231
6232 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006233 !info->attrs[NL80211_ATTR_SSID] ||
6234 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006235 return -EINVAL;
6236
Johannes Berg4c476992010-10-04 21:36:35 +02006237 if (!rdev->ops->assoc)
6238 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006239
Johannes Berg074ac8d2010-09-16 14:58:22 +02006240 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006241 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6242 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006243
Johannes Berg19957bb2009-07-02 17:20:43 +02006244 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006245
Johannes Berg19957bb2009-07-02 17:20:43 +02006246 chan = ieee80211_get_channel(&rdev->wiphy,
6247 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006248 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6249 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006250
Johannes Berg19957bb2009-07-02 17:20:43 +02006251 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6252 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006253
6254 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006255 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6256 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006257 }
6258
Jouni Malinendc6382c2009-05-06 22:09:37 +03006259 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006260 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006261 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006262 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006263 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006264 else if (mfp != NL80211_MFP_NO)
6265 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006266 }
6267
Johannes Berg3e5d7642009-07-07 14:37:26 +02006268 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006269 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006270
Ben Greear7e7c8922011-11-18 11:31:59 -08006271 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006272 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006273
6274 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006275 memcpy(&req.ht_capa_mask,
6276 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6277 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006278
6279 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006280 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006281 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006282 memcpy(&req.ht_capa,
6283 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6284 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006285 }
6286
Johannes Bergee2aca32013-02-21 17:36:01 +01006287 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006288 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006289
6290 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006291 memcpy(&req.vht_capa_mask,
6292 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6293 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006294
6295 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006296 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006297 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006298 memcpy(&req.vht_capa,
6299 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6300 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006301 }
6302
Johannes Bergf62fab72013-02-21 20:09:09 +01006303 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006304 if (!err) {
6305 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006306 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6307 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006308 wdev_unlock(dev->ieee80211_ptr);
6309 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006310
Jouni Malinen636a5d32009-03-19 13:39:22 +02006311 return err;
6312}
6313
6314static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6315{
Johannes Berg4c476992010-10-04 21:36:35 +02006316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6317 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006318 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006319 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006320 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006321 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006322
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006323 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6324 return -EINVAL;
6325
6326 if (!info->attrs[NL80211_ATTR_MAC])
6327 return -EINVAL;
6328
6329 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6330 return -EINVAL;
6331
Johannes Berg4c476992010-10-04 21:36:35 +02006332 if (!rdev->ops->deauth)
6333 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006334
Johannes Berg074ac8d2010-09-16 14:58:22 +02006335 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006336 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6337 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006338
Johannes Berg19957bb2009-07-02 17:20:43 +02006339 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006340
Johannes Berg19957bb2009-07-02 17:20:43 +02006341 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6342 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006343 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006344 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006345 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006346
6347 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006348 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6349 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006350 }
6351
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006352 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6353
Johannes Berg91bf9b22013-05-15 17:44:01 +02006354 wdev_lock(dev->ieee80211_ptr);
6355 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6356 local_state_change);
6357 wdev_unlock(dev->ieee80211_ptr);
6358 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006359}
6360
6361static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6362{
Johannes Berg4c476992010-10-04 21:36:35 +02006363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6364 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006365 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006366 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006367 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006368 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006369
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006370 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6371 return -EINVAL;
6372
6373 if (!info->attrs[NL80211_ATTR_MAC])
6374 return -EINVAL;
6375
6376 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6377 return -EINVAL;
6378
Johannes Berg4c476992010-10-04 21:36:35 +02006379 if (!rdev->ops->disassoc)
6380 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006381
Johannes Berg074ac8d2010-09-16 14:58:22 +02006382 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006383 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6384 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006385
Johannes Berg19957bb2009-07-02 17:20:43 +02006386 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006387
Johannes Berg19957bb2009-07-02 17:20:43 +02006388 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6389 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006390 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006391 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006392 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006393
6394 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006395 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6396 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006397 }
6398
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006399 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6400
Johannes Berg91bf9b22013-05-15 17:44:01 +02006401 wdev_lock(dev->ieee80211_ptr);
6402 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6403 local_state_change);
6404 wdev_unlock(dev->ieee80211_ptr);
6405 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006406}
6407
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006408static bool
6409nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6410 int mcast_rate[IEEE80211_NUM_BANDS],
6411 int rateval)
6412{
6413 struct wiphy *wiphy = &rdev->wiphy;
6414 bool found = false;
6415 int band, i;
6416
6417 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6418 struct ieee80211_supported_band *sband;
6419
6420 sband = wiphy->bands[band];
6421 if (!sband)
6422 continue;
6423
6424 for (i = 0; i < sband->n_bitrates; i++) {
6425 if (sband->bitrates[i].bitrate == rateval) {
6426 mcast_rate[band] = i + 1;
6427 found = true;
6428 break;
6429 }
6430 }
6431 }
6432
6433 return found;
6434}
6435
Johannes Berg04a773a2009-04-19 21:24:32 +02006436static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6437{
Johannes Berg4c476992010-10-04 21:36:35 +02006438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6439 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006440 struct cfg80211_ibss_params ibss;
6441 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006442 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006443 int err;
6444
Johannes Berg8e30bc52009-04-22 17:45:38 +02006445 memset(&ibss, 0, sizeof(ibss));
6446
Johannes Berg04a773a2009-04-19 21:24:32 +02006447 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6448 return -EINVAL;
6449
Johannes Berg683b6d32012-11-08 21:25:48 +01006450 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006451 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6452 return -EINVAL;
6453
Johannes Berg8e30bc52009-04-22 17:45:38 +02006454 ibss.beacon_interval = 100;
6455
6456 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6457 ibss.beacon_interval =
6458 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6459 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6460 return -EINVAL;
6461 }
6462
Johannes Berg4c476992010-10-04 21:36:35 +02006463 if (!rdev->ops->join_ibss)
6464 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006465
Johannes Berg4c476992010-10-04 21:36:35 +02006466 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6467 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006468
Johannes Berg79c97e92009-07-07 03:56:12 +02006469 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006470
Johannes Berg39193492011-09-16 13:45:25 +02006471 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006472 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006473
6474 if (!is_valid_ether_addr(ibss.bssid))
6475 return -EINVAL;
6476 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006477 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6478 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6479
6480 if (info->attrs[NL80211_ATTR_IE]) {
6481 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6482 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6483 }
6484
Johannes Berg683b6d32012-11-08 21:25:48 +01006485 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6486 if (err)
6487 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006488
Johannes Berg683b6d32012-11-08 21:25:48 +01006489 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006490 return -EINVAL;
6491
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006492 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006493 case NL80211_CHAN_WIDTH_5:
6494 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006495 case NL80211_CHAN_WIDTH_20_NOHT:
6496 break;
6497 case NL80211_CHAN_WIDTH_20:
6498 case NL80211_CHAN_WIDTH_40:
6499 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6500 break;
6501 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006502 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006503 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006504
Johannes Berg04a773a2009-04-19 21:24:32 +02006505 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006506 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006507
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006508 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6509 u8 *rates =
6510 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6511 int n_rates =
6512 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6513 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006514 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006515
Johannes Berg34850ab2011-07-18 18:08:35 +02006516 err = ieee80211_get_ratemask(sband, rates, n_rates,
6517 &ibss.basic_rates);
6518 if (err)
6519 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006520 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006521
Simon Wunderlich803768f2013-06-28 10:39:58 +02006522 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6523 memcpy(&ibss.ht_capa_mask,
6524 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6525 sizeof(ibss.ht_capa_mask));
6526
6527 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6528 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6529 return -EINVAL;
6530 memcpy(&ibss.ht_capa,
6531 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6532 sizeof(ibss.ht_capa));
6533 }
6534
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006535 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6536 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6537 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6538 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006539
Johannes Berg4c476992010-10-04 21:36:35 +02006540 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306541 bool no_ht = false;
6542
Johannes Berg4c476992010-10-04 21:36:35 +02006543 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306544 info->attrs[NL80211_ATTR_KEYS],
6545 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006546 if (IS_ERR(connkeys))
6547 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306548
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006549 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6550 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306551 kfree(connkeys);
6552 return -EINVAL;
6553 }
Johannes Berg4c476992010-10-04 21:36:35 +02006554 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006555
Antonio Quartulli267335d2012-01-31 20:25:47 +01006556 ibss.control_port =
6557 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6558
Johannes Berg4c476992010-10-04 21:36:35 +02006559 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006560 if (err)
6561 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006562 return err;
6563}
6564
6565static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6566{
Johannes Berg4c476992010-10-04 21:36:35 +02006567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6568 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006569
Johannes Berg4c476992010-10-04 21:36:35 +02006570 if (!rdev->ops->leave_ibss)
6571 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006572
Johannes Berg4c476992010-10-04 21:36:35 +02006573 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6574 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006575
Johannes Berg4c476992010-10-04 21:36:35 +02006576 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006577}
6578
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006579static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6580{
6581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6582 struct net_device *dev = info->user_ptr[1];
6583 int mcast_rate[IEEE80211_NUM_BANDS];
6584 u32 nla_rate;
6585 int err;
6586
6587 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6588 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6589 return -EOPNOTSUPP;
6590
6591 if (!rdev->ops->set_mcast_rate)
6592 return -EOPNOTSUPP;
6593
6594 memset(mcast_rate, 0, sizeof(mcast_rate));
6595
6596 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6597 return -EINVAL;
6598
6599 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6600 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6601 return -EINVAL;
6602
6603 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6604
6605 return err;
6606}
6607
6608
Johannes Bergaff89a92009-07-01 21:26:51 +02006609#ifdef CONFIG_NL80211_TESTMODE
6610static struct genl_multicast_group nl80211_testmode_mcgrp = {
6611 .name = "testmode",
6612};
6613
6614static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6615{
Johannes Berg4c476992010-10-04 21:36:35 +02006616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006617 struct wireless_dev *wdev =
6618 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006619 int err;
6620
David Spinadelfc73f112013-07-31 18:04:15 +03006621 if (!rdev->ops->testmode_cmd)
6622 return -EOPNOTSUPP;
6623
6624 if (IS_ERR(wdev)) {
6625 err = PTR_ERR(wdev);
6626 if (err != -EINVAL)
6627 return err;
6628 wdev = NULL;
6629 } else if (wdev->wiphy != &rdev->wiphy) {
6630 return -EINVAL;
6631 }
6632
Johannes Bergaff89a92009-07-01 21:26:51 +02006633 if (!info->attrs[NL80211_ATTR_TESTDATA])
6634 return -EINVAL;
6635
David Spinadelfc73f112013-07-31 18:04:15 +03006636 rdev->testmode_info = info;
6637 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006638 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6639 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
David Spinadelfc73f112013-07-31 18:04:15 +03006640 rdev->testmode_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006641
Johannes Bergaff89a92009-07-01 21:26:51 +02006642 return err;
6643}
6644
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006645static int nl80211_testmode_dump(struct sk_buff *skb,
6646 struct netlink_callback *cb)
6647{
Johannes Berg00918d32011-12-13 17:22:05 +01006648 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006649 int err;
6650 long phy_idx;
6651 void *data = NULL;
6652 int data_len = 0;
6653
Johannes Berg5fe231e2013-05-08 21:45:15 +02006654 rtnl_lock();
6655
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006656 if (cb->args[0]) {
6657 /*
6658 * 0 is a valid index, but not valid for args[0],
6659 * so we need to offset by 1.
6660 */
6661 phy_idx = cb->args[0] - 1;
6662 } else {
6663 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6664 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6665 nl80211_policy);
6666 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006667 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006668
Johannes Berg2bd7e352012-06-15 14:23:16 +02006669 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6670 nl80211_fam.attrbuf);
6671 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006672 err = PTR_ERR(rdev);
6673 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006674 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006675 phy_idx = rdev->wiphy_idx;
6676 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006677
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006678 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6679 cb->args[1] =
6680 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6681 }
6682
6683 if (cb->args[1]) {
6684 data = nla_data((void *)cb->args[1]);
6685 data_len = nla_len((void *)cb->args[1]);
6686 }
6687
Johannes Berg00918d32011-12-13 17:22:05 +01006688 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6689 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006690 err = -ENOENT;
6691 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006692 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006693
Johannes Berg00918d32011-12-13 17:22:05 +01006694 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006695 err = -EOPNOTSUPP;
6696 goto out_err;
6697 }
6698
6699 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006700 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006701 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6702 NL80211_CMD_TESTMODE);
6703 struct nlattr *tmdata;
6704
Dan Carpentercb35fba2013-08-14 14:50:01 +03006705 if (!hdr)
6706 break;
6707
David S. Miller9360ffd2012-03-29 04:41:26 -04006708 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006709 genlmsg_cancel(skb, hdr);
6710 break;
6711 }
6712
6713 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6714 if (!tmdata) {
6715 genlmsg_cancel(skb, hdr);
6716 break;
6717 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006718 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006719 nla_nest_end(skb, tmdata);
6720
6721 if (err == -ENOBUFS || err == -ENOENT) {
6722 genlmsg_cancel(skb, hdr);
6723 break;
6724 } else if (err) {
6725 genlmsg_cancel(skb, hdr);
6726 goto out_err;
6727 }
6728
6729 genlmsg_end(skb, hdr);
6730 }
6731
6732 err = skb->len;
6733 /* see above */
6734 cb->args[0] = phy_idx + 1;
6735 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006736 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006737 return err;
6738}
6739
Johannes Bergaff89a92009-07-01 21:26:51 +02006740static struct sk_buff *
6741__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006742 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006743{
6744 struct sk_buff *skb;
6745 void *hdr;
6746 struct nlattr *data;
6747
6748 skb = nlmsg_new(approxlen + 100, gfp);
6749 if (!skb)
6750 return NULL;
6751
Eric W. Biederman15e47302012-09-07 20:12:54 +00006752 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006753 if (!hdr) {
6754 kfree_skb(skb);
6755 return NULL;
6756 }
6757
David S. Miller9360ffd2012-03-29 04:41:26 -04006758 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6759 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006760 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6761
6762 ((void **)skb->cb)[0] = rdev;
6763 ((void **)skb->cb)[1] = hdr;
6764 ((void **)skb->cb)[2] = data;
6765
6766 return skb;
6767
6768 nla_put_failure:
6769 kfree_skb(skb);
6770 return NULL;
6771}
6772
6773struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6774 int approxlen)
6775{
6776 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6777
6778 if (WARN_ON(!rdev->testmode_info))
6779 return NULL;
6780
6781 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006782 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006783 rdev->testmode_info->snd_seq,
6784 GFP_KERNEL);
6785}
6786EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6787
6788int cfg80211_testmode_reply(struct sk_buff *skb)
6789{
6790 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6791 void *hdr = ((void **)skb->cb)[1];
6792 struct nlattr *data = ((void **)skb->cb)[2];
6793
6794 if (WARN_ON(!rdev->testmode_info)) {
6795 kfree_skb(skb);
6796 return -EINVAL;
6797 }
6798
6799 nla_nest_end(skb, data);
6800 genlmsg_end(skb, hdr);
6801 return genlmsg_reply(skb, rdev->testmode_info);
6802}
6803EXPORT_SYMBOL(cfg80211_testmode_reply);
6804
6805struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6806 int approxlen, gfp_t gfp)
6807{
6808 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6809
6810 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6811}
6812EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6813
6814void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6815{
Michal Kaziora0ec5702013-06-25 09:17:17 +02006816 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006817 void *hdr = ((void **)skb->cb)[1];
6818 struct nlattr *data = ((void **)skb->cb)[2];
6819
6820 nla_nest_end(skb, data);
6821 genlmsg_end(skb, hdr);
Michal Kaziora0ec5702013-06-25 09:17:17 +02006822 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
6823 nl80211_testmode_mcgrp.id, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006824}
6825EXPORT_SYMBOL(cfg80211_testmode_event);
6826#endif
6827
Samuel Ortizb23aa672009-07-01 21:26:54 +02006828static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6829{
Johannes Berg4c476992010-10-04 21:36:35 +02006830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6831 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006832 struct cfg80211_connect_params connect;
6833 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006834 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006835 int err;
6836
6837 memset(&connect, 0, sizeof(connect));
6838
6839 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6840 return -EINVAL;
6841
6842 if (!info->attrs[NL80211_ATTR_SSID] ||
6843 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6844 return -EINVAL;
6845
6846 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6847 connect.auth_type =
6848 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006849 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6850 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006851 return -EINVAL;
6852 } else
6853 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6854
6855 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6856
Johannes Bergc0692b82010-08-27 14:26:53 +03006857 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006858 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006859 if (err)
6860 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006861
Johannes Berg074ac8d2010-09-16 14:58:22 +02006862 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006863 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6864 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006865
Johannes Berg79c97e92009-07-07 03:56:12 +02006866 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006867
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306868 connect.bg_scan_period = -1;
6869 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6870 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6871 connect.bg_scan_period =
6872 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6873 }
6874
Samuel Ortizb23aa672009-07-01 21:26:54 +02006875 if (info->attrs[NL80211_ATTR_MAC])
6876 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6877 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6878 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6879
6880 if (info->attrs[NL80211_ATTR_IE]) {
6881 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6882 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6883 }
6884
Jouni Malinencee00a92013-01-15 17:15:57 +02006885 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6886 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6887 if (connect.mfp != NL80211_MFP_REQUIRED &&
6888 connect.mfp != NL80211_MFP_NO)
6889 return -EINVAL;
6890 } else {
6891 connect.mfp = NL80211_MFP_NO;
6892 }
6893
Samuel Ortizb23aa672009-07-01 21:26:54 +02006894 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6895 connect.channel =
6896 ieee80211_get_channel(wiphy,
6897 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6898 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006899 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6900 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006901 }
6902
Johannes Bergfffd0932009-07-08 14:22:54 +02006903 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6904 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306905 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006906 if (IS_ERR(connkeys))
6907 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006908 }
6909
Ben Greear7e7c8922011-11-18 11:31:59 -08006910 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6911 connect.flags |= ASSOC_REQ_DISABLE_HT;
6912
6913 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6914 memcpy(&connect.ht_capa_mask,
6915 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6916 sizeof(connect.ht_capa_mask));
6917
6918 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006919 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6920 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006921 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006922 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006923 memcpy(&connect.ht_capa,
6924 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6925 sizeof(connect.ht_capa));
6926 }
6927
Johannes Bergee2aca32013-02-21 17:36:01 +01006928 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6929 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6930
6931 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6932 memcpy(&connect.vht_capa_mask,
6933 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6934 sizeof(connect.vht_capa_mask));
6935
6936 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6937 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6938 kfree(connkeys);
6939 return -EINVAL;
6940 }
6941 memcpy(&connect.vht_capa,
6942 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6943 sizeof(connect.vht_capa));
6944 }
6945
Johannes Berg83739b02013-05-15 17:44:01 +02006946 wdev_lock(dev->ieee80211_ptr);
6947 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6948 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006949 if (err)
6950 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006951 return err;
6952}
6953
6954static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6955{
Johannes Berg4c476992010-10-04 21:36:35 +02006956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6957 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006958 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006959 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006960
6961 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6962 reason = WLAN_REASON_DEAUTH_LEAVING;
6963 else
6964 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6965
6966 if (reason == 0)
6967 return -EINVAL;
6968
Johannes Berg074ac8d2010-09-16 14:58:22 +02006969 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006970 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6971 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006972
Johannes Berg83739b02013-05-15 17:44:01 +02006973 wdev_lock(dev->ieee80211_ptr);
6974 ret = cfg80211_disconnect(rdev, dev, reason, true);
6975 wdev_unlock(dev->ieee80211_ptr);
6976 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006977}
6978
Johannes Berg463d0182009-07-14 00:33:35 +02006979static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6980{
Johannes Berg4c476992010-10-04 21:36:35 +02006981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006982 struct net *net;
6983 int err;
6984 u32 pid;
6985
6986 if (!info->attrs[NL80211_ATTR_PID])
6987 return -EINVAL;
6988
6989 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6990
Johannes Berg463d0182009-07-14 00:33:35 +02006991 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006992 if (IS_ERR(net))
6993 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006994
6995 err = 0;
6996
6997 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006998 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6999 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007000
Johannes Berg463d0182009-07-14 00:33:35 +02007001 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007002 return err;
7003}
7004
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007005static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7006{
Johannes Berg4c476992010-10-04 21:36:35 +02007007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007008 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7009 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007010 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007011 struct cfg80211_pmksa pmksa;
7012
7013 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7014
7015 if (!info->attrs[NL80211_ATTR_MAC])
7016 return -EINVAL;
7017
7018 if (!info->attrs[NL80211_ATTR_PMKID])
7019 return -EINVAL;
7020
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007021 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7022 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7023
Johannes Berg074ac8d2010-09-16 14:58:22 +02007024 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007025 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7026 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007027
7028 switch (info->genlhdr->cmd) {
7029 case NL80211_CMD_SET_PMKSA:
7030 rdev_ops = rdev->ops->set_pmksa;
7031 break;
7032 case NL80211_CMD_DEL_PMKSA:
7033 rdev_ops = rdev->ops->del_pmksa;
7034 break;
7035 default:
7036 WARN_ON(1);
7037 break;
7038 }
7039
Johannes Berg4c476992010-10-04 21:36:35 +02007040 if (!rdev_ops)
7041 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007042
Johannes Berg4c476992010-10-04 21:36:35 +02007043 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007044}
7045
7046static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7047{
Johannes Berg4c476992010-10-04 21:36:35 +02007048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7049 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007050
Johannes Berg074ac8d2010-09-16 14:58:22 +02007051 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007052 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7053 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007054
Johannes Berg4c476992010-10-04 21:36:35 +02007055 if (!rdev->ops->flush_pmksa)
7056 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007057
Hila Gonene35e4d22012-06-27 17:19:42 +03007058 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007059}
7060
Arik Nemtsov109086c2011-09-28 14:12:50 +03007061static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7062{
7063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7064 struct net_device *dev = info->user_ptr[1];
7065 u8 action_code, dialog_token;
7066 u16 status_code;
7067 u8 *peer;
7068
7069 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7070 !rdev->ops->tdls_mgmt)
7071 return -EOPNOTSUPP;
7072
7073 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7074 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7075 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7076 !info->attrs[NL80211_ATTR_IE] ||
7077 !info->attrs[NL80211_ATTR_MAC])
7078 return -EINVAL;
7079
7080 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7081 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7082 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7083 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7084
Hila Gonene35e4d22012-06-27 17:19:42 +03007085 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7086 dialog_token, status_code,
7087 nla_data(info->attrs[NL80211_ATTR_IE]),
7088 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007089}
7090
7091static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7092{
7093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7094 struct net_device *dev = info->user_ptr[1];
7095 enum nl80211_tdls_operation operation;
7096 u8 *peer;
7097
7098 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7099 !rdev->ops->tdls_oper)
7100 return -EOPNOTSUPP;
7101
7102 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7103 !info->attrs[NL80211_ATTR_MAC])
7104 return -EINVAL;
7105
7106 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7107 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7108
Hila Gonene35e4d22012-06-27 17:19:42 +03007109 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007110}
7111
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007112static int nl80211_remain_on_channel(struct sk_buff *skb,
7113 struct genl_info *info)
7114{
Johannes Berg4c476992010-10-04 21:36:35 +02007115 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007116 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007117 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007118 struct sk_buff *msg;
7119 void *hdr;
7120 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007121 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007122 int err;
7123
7124 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7125 !info->attrs[NL80211_ATTR_DURATION])
7126 return -EINVAL;
7127
7128 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7129
Johannes Berg7c4ef712011-11-18 15:33:48 +01007130 if (!rdev->ops->remain_on_channel ||
7131 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007132 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007133
Johannes Bergebf348f2012-06-01 12:50:54 +02007134 /*
7135 * We should be on that channel for at least a minimum amount of
7136 * time (10ms) but no longer than the driver supports.
7137 */
7138 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7139 duration > rdev->wiphy.max_remain_on_channel_duration)
7140 return -EINVAL;
7141
Johannes Berg683b6d32012-11-08 21:25:48 +01007142 err = nl80211_parse_chandef(rdev, info, &chandef);
7143 if (err)
7144 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007145
7146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007147 if (!msg)
7148 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007149
Eric W. Biederman15e47302012-09-07 20:12:54 +00007150 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007151 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007152 if (!hdr) {
7153 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007154 goto free_msg;
7155 }
7156
Johannes Berg683b6d32012-11-08 21:25:48 +01007157 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7158 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007159
7160 if (err)
7161 goto free_msg;
7162
David S. Miller9360ffd2012-03-29 04:41:26 -04007163 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7164 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007165
7166 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007167
7168 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007169
7170 nla_put_failure:
7171 err = -ENOBUFS;
7172 free_msg:
7173 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007174 return err;
7175}
7176
7177static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7178 struct genl_info *info)
7179{
Johannes Berg4c476992010-10-04 21:36:35 +02007180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007181 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007182 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007183
7184 if (!info->attrs[NL80211_ATTR_COOKIE])
7185 return -EINVAL;
7186
Johannes Berg4c476992010-10-04 21:36:35 +02007187 if (!rdev->ops->cancel_remain_on_channel)
7188 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007189
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007190 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7191
Hila Gonene35e4d22012-06-27 17:19:42 +03007192 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007193}
7194
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007195static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7196 u8 *rates, u8 rates_len)
7197{
7198 u8 i;
7199 u32 mask = 0;
7200
7201 for (i = 0; i < rates_len; i++) {
7202 int rate = (rates[i] & 0x7f) * 5;
7203 int ridx;
7204 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7205 struct ieee80211_rate *srate =
7206 &sband->bitrates[ridx];
7207 if (rate == srate->bitrate) {
7208 mask |= 1 << ridx;
7209 break;
7210 }
7211 }
7212 if (ridx == sband->n_bitrates)
7213 return 0; /* rate not found */
7214 }
7215
7216 return mask;
7217}
7218
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007219static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7220 u8 *rates, u8 rates_len,
7221 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7222{
7223 u8 i;
7224
7225 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7226
7227 for (i = 0; i < rates_len; i++) {
7228 int ridx, rbit;
7229
7230 ridx = rates[i] / 8;
7231 rbit = BIT(rates[i] % 8);
7232
7233 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007234 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007235 return false;
7236
7237 /* check availability */
7238 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7239 mcs[ridx] |= rbit;
7240 else
7241 return false;
7242 }
7243
7244 return true;
7245}
7246
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007247static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007248 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7249 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007250 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7251 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007252};
7253
7254static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7255 struct genl_info *info)
7256{
7257 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007258 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007259 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007260 int rem, i;
7261 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007262 struct nlattr *tx_rates;
7263 struct ieee80211_supported_band *sband;
7264
7265 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7266 return -EINVAL;
7267
Johannes Berg4c476992010-10-04 21:36:35 +02007268 if (!rdev->ops->set_bitrate_mask)
7269 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007270
7271 memset(&mask, 0, sizeof(mask));
7272 /* Default to all rates enabled */
7273 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7274 sband = rdev->wiphy.bands[i];
7275 mask.control[i].legacy =
7276 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007277 if (sband)
7278 memcpy(mask.control[i].mcs,
7279 sband->ht_cap.mcs.rx_mask,
7280 sizeof(mask.control[i].mcs));
7281 else
7282 memset(mask.control[i].mcs, 0,
7283 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007284 }
7285
7286 /*
7287 * The nested attribute uses enum nl80211_band as the index. This maps
7288 * directly to the enum ieee80211_band values used in cfg80211.
7289 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007290 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007291 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7292 {
7293 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007294 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7295 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007296 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007297 if (sband == NULL)
7298 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007299 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7300 nla_len(tx_rates), nl80211_txattr_policy);
7301 if (tb[NL80211_TXRATE_LEGACY]) {
7302 mask.control[band].legacy = rateset_to_mask(
7303 sband,
7304 nla_data(tb[NL80211_TXRATE_LEGACY]),
7305 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307306 if ((mask.control[band].legacy == 0) &&
7307 nla_len(tb[NL80211_TXRATE_LEGACY]))
7308 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007309 }
7310 if (tb[NL80211_TXRATE_MCS]) {
7311 if (!ht_rateset_to_mask(
7312 sband,
7313 nla_data(tb[NL80211_TXRATE_MCS]),
7314 nla_len(tb[NL80211_TXRATE_MCS]),
7315 mask.control[band].mcs))
7316 return -EINVAL;
7317 }
7318
7319 if (mask.control[band].legacy == 0) {
7320 /* don't allow empty legacy rates if HT
7321 * is not even supported. */
7322 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7323 return -EINVAL;
7324
7325 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7326 if (mask.control[band].mcs[i])
7327 break;
7328
7329 /* legacy and mcs rates may not be both empty */
7330 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007331 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007332 }
7333 }
7334
Hila Gonene35e4d22012-06-27 17:19:42 +03007335 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007336}
7337
Johannes Berg2e161f72010-08-12 15:38:38 +02007338static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007339{
Johannes Berg4c476992010-10-04 21:36:35 +02007340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007341 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007342 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007343
7344 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7345 return -EINVAL;
7346
Johannes Berg2e161f72010-08-12 15:38:38 +02007347 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7348 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007349
Johannes Berg71bbc992012-06-15 15:30:18 +02007350 switch (wdev->iftype) {
7351 case NL80211_IFTYPE_STATION:
7352 case NL80211_IFTYPE_ADHOC:
7353 case NL80211_IFTYPE_P2P_CLIENT:
7354 case NL80211_IFTYPE_AP:
7355 case NL80211_IFTYPE_AP_VLAN:
7356 case NL80211_IFTYPE_MESH_POINT:
7357 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007358 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007359 break;
7360 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007361 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007362 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007363
7364 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007365 if (!rdev->ops->mgmt_tx)
7366 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007367
Eric W. Biederman15e47302012-09-07 20:12:54 +00007368 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007369 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7370 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007371}
7372
Johannes Berg2e161f72010-08-12 15:38:38 +02007373static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007374{
Johannes Berg4c476992010-10-04 21:36:35 +02007375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007376 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007377 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007378 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007379 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007380 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007381 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007382 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007383 bool offchan, no_cck, dont_wait_for_ack;
7384
7385 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007386
Johannes Berg683b6d32012-11-08 21:25:48 +01007387 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007388 return -EINVAL;
7389
Johannes Berg4c476992010-10-04 21:36:35 +02007390 if (!rdev->ops->mgmt_tx)
7391 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007392
Johannes Berg71bbc992012-06-15 15:30:18 +02007393 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007394 case NL80211_IFTYPE_P2P_DEVICE:
7395 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7396 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007397 case NL80211_IFTYPE_STATION:
7398 case NL80211_IFTYPE_ADHOC:
7399 case NL80211_IFTYPE_P2P_CLIENT:
7400 case NL80211_IFTYPE_AP:
7401 case NL80211_IFTYPE_AP_VLAN:
7402 case NL80211_IFTYPE_MESH_POINT:
7403 case NL80211_IFTYPE_P2P_GO:
7404 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
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007409 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007410 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007411 return -EINVAL;
7412 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007413
7414 /*
7415 * We should wait on the channel for at least a minimum amount
7416 * of time (10ms) but no longer than the driver supports.
7417 */
7418 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7419 wait > rdev->wiphy.max_remain_on_channel_duration)
7420 return -EINVAL;
7421
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007422 }
7423
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007424 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7425
Johannes Berg7c4ef712011-11-18 15:33:48 +01007426 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7427 return -EINVAL;
7428
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307429 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7430
Antonio Quartulliea141b752013-06-11 14:20:03 +02007431 /* get the channel if any has been specified, otherwise pass NULL to
7432 * the driver. The latter will use the current one
7433 */
7434 chandef.chan = NULL;
7435 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7436 err = nl80211_parse_chandef(rdev, info, &chandef);
7437 if (err)
7438 return err;
7439 }
7440
7441 if (!chandef.chan && offchan)
7442 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007443
Johannes Berge247bd902011-11-04 11:18:21 +01007444 if (!dont_wait_for_ack) {
7445 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7446 if (!msg)
7447 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007448
Eric W. Biederman15e47302012-09-07 20:12:54 +00007449 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007450 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007451 if (!hdr) {
7452 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007453 goto free_msg;
7454 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007455 }
Johannes Berge247bd902011-11-04 11:18:21 +01007456
Johannes Berg683b6d32012-11-08 21:25:48 +01007457 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007458 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7459 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007460 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007461 if (err)
7462 goto free_msg;
7463
Johannes Berge247bd902011-11-04 11:18:21 +01007464 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007465 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7466 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007467
Johannes Berge247bd902011-11-04 11:18:21 +01007468 genlmsg_end(msg, hdr);
7469 return genlmsg_reply(msg, info);
7470 }
7471
7472 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007473
7474 nla_put_failure:
7475 err = -ENOBUFS;
7476 free_msg:
7477 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007478 return err;
7479}
7480
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007481static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7482{
7483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007484 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007485 u64 cookie;
7486
7487 if (!info->attrs[NL80211_ATTR_COOKIE])
7488 return -EINVAL;
7489
7490 if (!rdev->ops->mgmt_tx_cancel_wait)
7491 return -EOPNOTSUPP;
7492
Johannes Berg71bbc992012-06-15 15:30:18 +02007493 switch (wdev->iftype) {
7494 case NL80211_IFTYPE_STATION:
7495 case NL80211_IFTYPE_ADHOC:
7496 case NL80211_IFTYPE_P2P_CLIENT:
7497 case NL80211_IFTYPE_AP:
7498 case NL80211_IFTYPE_AP_VLAN:
7499 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007500 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007501 break;
7502 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007503 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007504 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007505
7506 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7507
Hila Gonene35e4d22012-06-27 17:19:42 +03007508 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007509}
7510
Kalle Valoffb9eb32010-02-17 17:58:10 +02007511static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7512{
Johannes Berg4c476992010-10-04 21:36:35 +02007513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007514 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007515 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007516 u8 ps_state;
7517 bool state;
7518 int err;
7519
Johannes Berg4c476992010-10-04 21:36:35 +02007520 if (!info->attrs[NL80211_ATTR_PS_STATE])
7521 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007522
7523 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7524
Johannes Berg4c476992010-10-04 21:36:35 +02007525 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7526 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007527
7528 wdev = dev->ieee80211_ptr;
7529
Johannes Berg4c476992010-10-04 21:36:35 +02007530 if (!rdev->ops->set_power_mgmt)
7531 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007532
7533 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7534
7535 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007536 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007537
Hila Gonene35e4d22012-06-27 17:19:42 +03007538 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007539 if (!err)
7540 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007541 return err;
7542}
7543
7544static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7545{
Johannes Berg4c476992010-10-04 21:36:35 +02007546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007547 enum nl80211_ps_state ps_state;
7548 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007549 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007550 struct sk_buff *msg;
7551 void *hdr;
7552 int err;
7553
Kalle Valoffb9eb32010-02-17 17:58:10 +02007554 wdev = dev->ieee80211_ptr;
7555
Johannes Berg4c476992010-10-04 21:36:35 +02007556 if (!rdev->ops->set_power_mgmt)
7557 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007558
7559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007560 if (!msg)
7561 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007562
Eric W. Biederman15e47302012-09-07 20:12:54 +00007563 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007564 NL80211_CMD_GET_POWER_SAVE);
7565 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007566 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007567 goto free_msg;
7568 }
7569
7570 if (wdev->ps)
7571 ps_state = NL80211_PS_ENABLED;
7572 else
7573 ps_state = NL80211_PS_DISABLED;
7574
David S. Miller9360ffd2012-03-29 04:41:26 -04007575 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7576 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007577
7578 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007579 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007580
Johannes Berg4c476992010-10-04 21:36:35 +02007581 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007582 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007583 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007584 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007585 return err;
7586}
7587
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007588static struct nla_policy
7589nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7590 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7591 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7592 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007593 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7594 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7595 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007596};
7597
Thomas Pedersen84f10702012-07-12 16:17:33 -07007598static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007599 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007600{
7601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007602 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007603 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007604
Johannes Bergd9d8b012012-11-26 12:51:52 +01007605 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007606 return -EINVAL;
7607
Thomas Pedersen84f10702012-07-12 16:17:33 -07007608 if (!rdev->ops->set_cqm_txe_config)
7609 return -EOPNOTSUPP;
7610
7611 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7612 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7613 return -EOPNOTSUPP;
7614
Hila Gonene35e4d22012-06-27 17:19:42 +03007615 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007616}
7617
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007618static int nl80211_set_cqm_rssi(struct genl_info *info,
7619 s32 threshold, u32 hysteresis)
7620{
Johannes Berg4c476992010-10-04 21:36:35 +02007621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007622 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007623 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007624
7625 if (threshold > 0)
7626 return -EINVAL;
7627
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007628 /* disabling - hysteresis should also be zero then */
7629 if (threshold == 0)
7630 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007631
Johannes Berg4c476992010-10-04 21:36:35 +02007632 if (!rdev->ops->set_cqm_rssi_config)
7633 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007634
Johannes Berg074ac8d2010-09-16 14:58:22 +02007635 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007636 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7637 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007638
Hila Gonene35e4d22012-06-27 17:19:42 +03007639 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007640}
7641
7642static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7643{
7644 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7645 struct nlattr *cqm;
7646 int err;
7647
7648 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007649 if (!cqm)
7650 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007651
7652 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7653 nl80211_attr_cqm_policy);
7654 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007655 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007656
7657 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7658 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007659 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7660 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007661
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007662 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7663 }
7664
7665 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7666 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7667 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7668 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7669 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7670 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7671
7672 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7673 }
7674
7675 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007676}
7677
Johannes Berg29cbe682010-12-03 09:20:44 +01007678static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7679{
7680 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7681 struct net_device *dev = info->user_ptr[1];
7682 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007683 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007684 int err;
7685
7686 /* start with default */
7687 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007688 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007689
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007690 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007691 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007692 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007693 if (err)
7694 return err;
7695 }
7696
7697 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7698 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7699 return -EINVAL;
7700
Javier Cardonac80d5452010-12-16 17:37:49 -08007701 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7702 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7703
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007704 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7705 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7706 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7707 return -EINVAL;
7708
Marco Porsch9bdbf042013-01-07 16:04:51 +01007709 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7710 setup.beacon_interval =
7711 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7712 if (setup.beacon_interval < 10 ||
7713 setup.beacon_interval > 10000)
7714 return -EINVAL;
7715 }
7716
7717 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7718 setup.dtim_period =
7719 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7720 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7721 return -EINVAL;
7722 }
7723
Javier Cardonac80d5452010-12-16 17:37:49 -08007724 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7725 /* parse additional setup parameters if given */
7726 err = nl80211_parse_mesh_setup(info, &setup);
7727 if (err)
7728 return err;
7729 }
7730
Thomas Pedersend37bb182013-03-04 13:06:13 -08007731 if (setup.user_mpm)
7732 cfg.auto_open_plinks = false;
7733
Johannes Bergcc1d2802012-05-16 23:50:20 +02007734 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007735 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7736 if (err)
7737 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007738 } else {
7739 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007740 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007741 }
7742
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007743 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7744 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7745 int n_rates =
7746 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7747 struct ieee80211_supported_band *sband;
7748
7749 if (!setup.chandef.chan)
7750 return -EINVAL;
7751
7752 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7753
7754 err = ieee80211_get_ratemask(sband, rates, n_rates,
7755 &setup.basic_rates);
7756 if (err)
7757 return err;
7758 }
7759
Javier Cardonac80d5452010-12-16 17:37:49 -08007760 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007761}
7762
7763static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7764{
7765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7766 struct net_device *dev = info->user_ptr[1];
7767
7768 return cfg80211_leave_mesh(rdev, dev);
7769}
7770
Johannes Bergdfb89c52012-06-27 09:23:48 +02007771#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007772static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7773 struct cfg80211_registered_device *rdev)
7774{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007775 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007776 struct nlattr *nl_pats, *nl_pat;
7777 int i, pat_len;
7778
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007779 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007780 return 0;
7781
7782 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7783 if (!nl_pats)
7784 return -ENOBUFS;
7785
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007786 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007787 nl_pat = nla_nest_start(msg, i + 1);
7788 if (!nl_pat)
7789 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007790 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007791 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007792 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007793 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7794 wowlan->patterns[i].pattern) ||
7795 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007796 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007797 return -ENOBUFS;
7798 nla_nest_end(msg, nl_pat);
7799 }
7800 nla_nest_end(msg, nl_pats);
7801
7802 return 0;
7803}
7804
Johannes Berg2a0e0472013-01-23 22:57:40 +01007805static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7806 struct cfg80211_wowlan_tcp *tcp)
7807{
7808 struct nlattr *nl_tcp;
7809
7810 if (!tcp)
7811 return 0;
7812
7813 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7814 if (!nl_tcp)
7815 return -ENOBUFS;
7816
7817 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7818 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7819 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7820 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7821 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7822 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7823 tcp->payload_len, tcp->payload) ||
7824 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7825 tcp->data_interval) ||
7826 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7827 tcp->wake_len, tcp->wake_data) ||
7828 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7829 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7830 return -ENOBUFS;
7831
7832 if (tcp->payload_seq.len &&
7833 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7834 sizeof(tcp->payload_seq), &tcp->payload_seq))
7835 return -ENOBUFS;
7836
7837 if (tcp->payload_tok.len &&
7838 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7839 sizeof(tcp->payload_tok) + tcp->tokens_size,
7840 &tcp->payload_tok))
7841 return -ENOBUFS;
7842
Johannes Berge248ad32013-05-16 10:24:28 +02007843 nla_nest_end(msg, nl_tcp);
7844
Johannes Berg2a0e0472013-01-23 22:57:40 +01007845 return 0;
7846}
7847
Johannes Bergff1b6e62011-05-04 15:37:28 +02007848static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7849{
7850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7851 struct sk_buff *msg;
7852 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007853 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007854
Johannes Berg964dc9e2013-06-03 17:25:34 +02007855 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007856 return -EOPNOTSUPP;
7857
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007858 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007859 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007860 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7861 rdev->wiphy.wowlan_config->tcp->payload_len +
7862 rdev->wiphy.wowlan_config->tcp->wake_len +
7863 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007864 }
7865
7866 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007867 if (!msg)
7868 return -ENOMEM;
7869
Eric W. Biederman15e47302012-09-07 20:12:54 +00007870 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007871 NL80211_CMD_GET_WOWLAN);
7872 if (!hdr)
7873 goto nla_put_failure;
7874
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007875 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007876 struct nlattr *nl_wowlan;
7877
7878 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7879 if (!nl_wowlan)
7880 goto nla_put_failure;
7881
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007882 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007883 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007884 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007885 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007886 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007887 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007888 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007889 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007890 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007891 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007892 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007893 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007894 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007895 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7896 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007897
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007898 if (nl80211_send_wowlan_patterns(msg, rdev))
7899 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007900
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007901 if (nl80211_send_wowlan_tcp(msg,
7902 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007903 goto nla_put_failure;
7904
Johannes Bergff1b6e62011-05-04 15:37:28 +02007905 nla_nest_end(msg, nl_wowlan);
7906 }
7907
7908 genlmsg_end(msg, hdr);
7909 return genlmsg_reply(msg, info);
7910
7911nla_put_failure:
7912 nlmsg_free(msg);
7913 return -ENOBUFS;
7914}
7915
Johannes Berg2a0e0472013-01-23 22:57:40 +01007916static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7917 struct nlattr *attr,
7918 struct cfg80211_wowlan *trig)
7919{
7920 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7921 struct cfg80211_wowlan_tcp *cfg;
7922 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7923 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7924 u32 size;
7925 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7926 int err, port;
7927
Johannes Berg964dc9e2013-06-03 17:25:34 +02007928 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007929 return -EINVAL;
7930
7931 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7932 nla_data(attr), nla_len(attr),
7933 nl80211_wowlan_tcp_policy);
7934 if (err)
7935 return err;
7936
7937 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7938 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7939 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7940 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7941 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7942 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7943 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7944 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7945 return -EINVAL;
7946
7947 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007948 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007949 return -EINVAL;
7950
7951 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007952 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007953 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007954 return -EINVAL;
7955
7956 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007957 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007958 return -EINVAL;
7959
7960 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7961 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7962 return -EINVAL;
7963
7964 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7965 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7966
7967 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7968 tokens_size = tokln - sizeof(*tok);
7969
7970 if (!tok->len || tokens_size % tok->len)
7971 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007972 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007973 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007974 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007975 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007976 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007977 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007978 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007979 return -EINVAL;
7980 if (tok->offset + tok->len > data_size)
7981 return -EINVAL;
7982 }
7983
7984 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7985 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007986 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007987 return -EINVAL;
7988 if (seq->len == 0 || seq->len > 4)
7989 return -EINVAL;
7990 if (seq->len + seq->offset > data_size)
7991 return -EINVAL;
7992 }
7993
7994 size = sizeof(*cfg);
7995 size += data_size;
7996 size += wake_size + wake_mask_size;
7997 size += tokens_size;
7998
7999 cfg = kzalloc(size, GFP_KERNEL);
8000 if (!cfg)
8001 return -ENOMEM;
8002 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8003 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8004 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8005 ETH_ALEN);
8006 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8007 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8008 else
8009 port = 0;
8010#ifdef CONFIG_INET
8011 /* allocate a socket and port for it and use it */
8012 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8013 IPPROTO_TCP, &cfg->sock, 1);
8014 if (err) {
8015 kfree(cfg);
8016 return err;
8017 }
8018 if (inet_csk_get_port(cfg->sock->sk, port)) {
8019 sock_release(cfg->sock);
8020 kfree(cfg);
8021 return -EADDRINUSE;
8022 }
8023 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8024#else
8025 if (!port) {
8026 kfree(cfg);
8027 return -EINVAL;
8028 }
8029 cfg->src_port = port;
8030#endif
8031
8032 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8033 cfg->payload_len = data_size;
8034 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8035 memcpy((void *)cfg->payload,
8036 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8037 data_size);
8038 if (seq)
8039 cfg->payload_seq = *seq;
8040 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8041 cfg->wake_len = wake_size;
8042 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8043 memcpy((void *)cfg->wake_data,
8044 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8045 wake_size);
8046 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8047 data_size + wake_size;
8048 memcpy((void *)cfg->wake_mask,
8049 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8050 wake_mask_size);
8051 if (tok) {
8052 cfg->tokens_size = tokens_size;
8053 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8054 }
8055
8056 trig->tcp = cfg;
8057
8058 return 0;
8059}
8060
Johannes Bergff1b6e62011-05-04 15:37:28 +02008061static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8062{
8063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8064 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008065 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008066 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008067 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008068 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008069 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008070
Johannes Berg964dc9e2013-06-03 17:25:34 +02008071 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008072 return -EOPNOTSUPP;
8073
Johannes Bergae33bd82012-07-12 16:25:02 +02008074 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8075 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008076 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008077 goto set_wakeup;
8078 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008079
8080 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8081 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8082 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8083 nl80211_wowlan_policy);
8084 if (err)
8085 return err;
8086
8087 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8088 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8089 return -EINVAL;
8090 new_triggers.any = true;
8091 }
8092
8093 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8094 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8095 return -EINVAL;
8096 new_triggers.disconnect = true;
8097 }
8098
8099 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8100 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8101 return -EINVAL;
8102 new_triggers.magic_pkt = true;
8103 }
8104
Johannes Berg77dbbb12011-07-13 10:48:55 +02008105 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8106 return -EINVAL;
8107
8108 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8109 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8110 return -EINVAL;
8111 new_triggers.gtk_rekey_failure = true;
8112 }
8113
8114 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8115 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8116 return -EINVAL;
8117 new_triggers.eap_identity_req = true;
8118 }
8119
8120 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8121 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8122 return -EINVAL;
8123 new_triggers.four_way_handshake = true;
8124 }
8125
8126 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8127 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8128 return -EINVAL;
8129 new_triggers.rfkill_release = true;
8130 }
8131
Johannes Bergff1b6e62011-05-04 15:37:28 +02008132 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8133 struct nlattr *pat;
8134 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008135 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008136 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008137
8138 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8139 rem)
8140 n_patterns++;
8141 if (n_patterns > wowlan->n_patterns)
8142 return -EINVAL;
8143
8144 new_triggers.patterns = kcalloc(n_patterns,
8145 sizeof(new_triggers.patterns[0]),
8146 GFP_KERNEL);
8147 if (!new_triggers.patterns)
8148 return -ENOMEM;
8149
8150 new_triggers.n_patterns = n_patterns;
8151 i = 0;
8152
8153 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8154 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008155 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8156 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008157 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008158 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8159 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008160 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008161 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008162 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008163 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008164 goto error;
8165 if (pat_len > wowlan->pattern_max_len ||
8166 pat_len < wowlan->pattern_min_len)
8167 goto error;
8168
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008169 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008170 pkt_offset = 0;
8171 else
8172 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008173 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008174 if (pkt_offset > wowlan->max_pkt_offset)
8175 goto error;
8176 new_triggers.patterns[i].pkt_offset = pkt_offset;
8177
Johannes Bergff1b6e62011-05-04 15:37:28 +02008178 new_triggers.patterns[i].mask =
8179 kmalloc(mask_len + pat_len, GFP_KERNEL);
8180 if (!new_triggers.patterns[i].mask) {
8181 err = -ENOMEM;
8182 goto error;
8183 }
8184 new_triggers.patterns[i].pattern =
8185 new_triggers.patterns[i].mask + mask_len;
8186 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008187 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008188 mask_len);
8189 new_triggers.patterns[i].pattern_len = pat_len;
8190 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008191 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008192 pat_len);
8193 i++;
8194 }
8195 }
8196
Johannes Berg2a0e0472013-01-23 22:57:40 +01008197 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8198 err = nl80211_parse_wowlan_tcp(
8199 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8200 &new_triggers);
8201 if (err)
8202 goto error;
8203 }
8204
Johannes Bergae33bd82012-07-12 16:25:02 +02008205 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8206 if (!ntrig) {
8207 err = -ENOMEM;
8208 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008209 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008210 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008211 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008212
Johannes Bergae33bd82012-07-12 16:25:02 +02008213 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008214 if (rdev->ops->set_wakeup &&
8215 prev_enabled != !!rdev->wiphy.wowlan_config)
8216 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008217
Johannes Bergff1b6e62011-05-04 15:37:28 +02008218 return 0;
8219 error:
8220 for (i = 0; i < new_triggers.n_patterns; i++)
8221 kfree(new_triggers.patterns[i].mask);
8222 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008223 if (new_triggers.tcp && new_triggers.tcp->sock)
8224 sock_release(new_triggers.tcp->sock);
8225 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008226 return err;
8227}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008228#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008229
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008230static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8231 struct cfg80211_registered_device *rdev)
8232{
8233 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8234 int i, j, pat_len;
8235 struct cfg80211_coalesce_rules *rule;
8236
8237 if (!rdev->coalesce->n_rules)
8238 return 0;
8239
8240 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8241 if (!nl_rules)
8242 return -ENOBUFS;
8243
8244 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8245 nl_rule = nla_nest_start(msg, i + 1);
8246 if (!nl_rule)
8247 return -ENOBUFS;
8248
8249 rule = &rdev->coalesce->rules[i];
8250 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8251 rule->delay))
8252 return -ENOBUFS;
8253
8254 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8255 rule->condition))
8256 return -ENOBUFS;
8257
8258 nl_pats = nla_nest_start(msg,
8259 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8260 if (!nl_pats)
8261 return -ENOBUFS;
8262
8263 for (j = 0; j < rule->n_patterns; j++) {
8264 nl_pat = nla_nest_start(msg, j + 1);
8265 if (!nl_pat)
8266 return -ENOBUFS;
8267 pat_len = rule->patterns[j].pattern_len;
8268 if (nla_put(msg, NL80211_PKTPAT_MASK,
8269 DIV_ROUND_UP(pat_len, 8),
8270 rule->patterns[j].mask) ||
8271 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8272 rule->patterns[j].pattern) ||
8273 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8274 rule->patterns[j].pkt_offset))
8275 return -ENOBUFS;
8276 nla_nest_end(msg, nl_pat);
8277 }
8278 nla_nest_end(msg, nl_pats);
8279 nla_nest_end(msg, nl_rule);
8280 }
8281 nla_nest_end(msg, nl_rules);
8282
8283 return 0;
8284}
8285
8286static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8287{
8288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8289 struct sk_buff *msg;
8290 void *hdr;
8291
8292 if (!rdev->wiphy.coalesce)
8293 return -EOPNOTSUPP;
8294
8295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8296 if (!msg)
8297 return -ENOMEM;
8298
8299 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8300 NL80211_CMD_GET_COALESCE);
8301 if (!hdr)
8302 goto nla_put_failure;
8303
8304 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8305 goto nla_put_failure;
8306
8307 genlmsg_end(msg, hdr);
8308 return genlmsg_reply(msg, info);
8309
8310nla_put_failure:
8311 nlmsg_free(msg);
8312 return -ENOBUFS;
8313}
8314
8315void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8316{
8317 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8318 int i, j;
8319 struct cfg80211_coalesce_rules *rule;
8320
8321 if (!coalesce)
8322 return;
8323
8324 for (i = 0; i < coalesce->n_rules; i++) {
8325 rule = &coalesce->rules[i];
8326 for (j = 0; j < rule->n_patterns; j++)
8327 kfree(rule->patterns[j].mask);
8328 kfree(rule->patterns);
8329 }
8330 kfree(coalesce->rules);
8331 kfree(coalesce);
8332 rdev->coalesce = NULL;
8333}
8334
8335static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8336 struct nlattr *rule,
8337 struct cfg80211_coalesce_rules *new_rule)
8338{
8339 int err, i;
8340 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8341 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8342 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8343 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8344
8345 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8346 nla_len(rule), nl80211_coalesce_policy);
8347 if (err)
8348 return err;
8349
8350 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8351 new_rule->delay =
8352 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8353 if (new_rule->delay > coalesce->max_delay)
8354 return -EINVAL;
8355
8356 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8357 new_rule->condition =
8358 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8359 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8360 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8361 return -EINVAL;
8362
8363 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8364 return -EINVAL;
8365
8366 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8367 rem)
8368 n_patterns++;
8369 if (n_patterns > coalesce->n_patterns)
8370 return -EINVAL;
8371
8372 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8373 GFP_KERNEL);
8374 if (!new_rule->patterns)
8375 return -ENOMEM;
8376
8377 new_rule->n_patterns = n_patterns;
8378 i = 0;
8379
8380 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8381 rem) {
8382 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8383 nla_len(pat), NULL);
8384 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8385 !pat_tb[NL80211_PKTPAT_PATTERN])
8386 return -EINVAL;
8387 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8388 mask_len = DIV_ROUND_UP(pat_len, 8);
8389 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8390 return -EINVAL;
8391 if (pat_len > coalesce->pattern_max_len ||
8392 pat_len < coalesce->pattern_min_len)
8393 return -EINVAL;
8394
8395 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8396 pkt_offset = 0;
8397 else
8398 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8399 if (pkt_offset > coalesce->max_pkt_offset)
8400 return -EINVAL;
8401 new_rule->patterns[i].pkt_offset = pkt_offset;
8402
8403 new_rule->patterns[i].mask =
8404 kmalloc(mask_len + pat_len, GFP_KERNEL);
8405 if (!new_rule->patterns[i].mask)
8406 return -ENOMEM;
8407 new_rule->patterns[i].pattern =
8408 new_rule->patterns[i].mask + mask_len;
8409 memcpy(new_rule->patterns[i].mask,
8410 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8411 new_rule->patterns[i].pattern_len = pat_len;
8412 memcpy(new_rule->patterns[i].pattern,
8413 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8414 i++;
8415 }
8416
8417 return 0;
8418}
8419
8420static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8421{
8422 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8423 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8424 struct cfg80211_coalesce new_coalesce = {};
8425 struct cfg80211_coalesce *n_coalesce;
8426 int err, rem_rule, n_rules = 0, i, j;
8427 struct nlattr *rule;
8428 struct cfg80211_coalesce_rules *tmp_rule;
8429
8430 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8431 return -EOPNOTSUPP;
8432
8433 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8434 cfg80211_rdev_free_coalesce(rdev);
8435 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8436 return 0;
8437 }
8438
8439 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8440 rem_rule)
8441 n_rules++;
8442 if (n_rules > coalesce->n_rules)
8443 return -EINVAL;
8444
8445 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8446 GFP_KERNEL);
8447 if (!new_coalesce.rules)
8448 return -ENOMEM;
8449
8450 new_coalesce.n_rules = n_rules;
8451 i = 0;
8452
8453 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8454 rem_rule) {
8455 err = nl80211_parse_coalesce_rule(rdev, rule,
8456 &new_coalesce.rules[i]);
8457 if (err)
8458 goto error;
8459
8460 i++;
8461 }
8462
8463 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8464 if (err)
8465 goto error;
8466
8467 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8468 if (!n_coalesce) {
8469 err = -ENOMEM;
8470 goto error;
8471 }
8472 cfg80211_rdev_free_coalesce(rdev);
8473 rdev->coalesce = n_coalesce;
8474
8475 return 0;
8476error:
8477 for (i = 0; i < new_coalesce.n_rules; i++) {
8478 tmp_rule = &new_coalesce.rules[i];
8479 for (j = 0; j < tmp_rule->n_patterns; j++)
8480 kfree(tmp_rule->patterns[j].mask);
8481 kfree(tmp_rule->patterns);
8482 }
8483 kfree(new_coalesce.rules);
8484
8485 return err;
8486}
8487
Johannes Berge5497d72011-07-05 16:35:40 +02008488static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8489{
8490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8491 struct net_device *dev = info->user_ptr[1];
8492 struct wireless_dev *wdev = dev->ieee80211_ptr;
8493 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8494 struct cfg80211_gtk_rekey_data rekey_data;
8495 int err;
8496
8497 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8498 return -EINVAL;
8499
8500 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8501 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8502 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8503 nl80211_rekey_policy);
8504 if (err)
8505 return err;
8506
8507 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8508 return -ERANGE;
8509 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8510 return -ERANGE;
8511 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8512 return -ERANGE;
8513
8514 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8515 NL80211_KEK_LEN);
8516 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8517 NL80211_KCK_LEN);
8518 memcpy(rekey_data.replay_ctr,
8519 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8520 NL80211_REPLAY_CTR_LEN);
8521
8522 wdev_lock(wdev);
8523 if (!wdev->current_bss) {
8524 err = -ENOTCONN;
8525 goto out;
8526 }
8527
8528 if (!rdev->ops->set_rekey_data) {
8529 err = -EOPNOTSUPP;
8530 goto out;
8531 }
8532
Hila Gonene35e4d22012-06-27 17:19:42 +03008533 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008534 out:
8535 wdev_unlock(wdev);
8536 return err;
8537}
8538
Johannes Berg28946da2011-11-04 11:18:12 +01008539static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8540 struct genl_info *info)
8541{
8542 struct net_device *dev = info->user_ptr[1];
8543 struct wireless_dev *wdev = dev->ieee80211_ptr;
8544
8545 if (wdev->iftype != NL80211_IFTYPE_AP &&
8546 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8547 return -EINVAL;
8548
Eric W. Biederman15e47302012-09-07 20:12:54 +00008549 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008550 return -EBUSY;
8551
Eric W. Biederman15e47302012-09-07 20:12:54 +00008552 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008553 return 0;
8554}
8555
Johannes Berg7f6cf312011-11-04 11:18:15 +01008556static int nl80211_probe_client(struct sk_buff *skb,
8557 struct genl_info *info)
8558{
8559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8560 struct net_device *dev = info->user_ptr[1];
8561 struct wireless_dev *wdev = dev->ieee80211_ptr;
8562 struct sk_buff *msg;
8563 void *hdr;
8564 const u8 *addr;
8565 u64 cookie;
8566 int err;
8567
8568 if (wdev->iftype != NL80211_IFTYPE_AP &&
8569 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8570 return -EOPNOTSUPP;
8571
8572 if (!info->attrs[NL80211_ATTR_MAC])
8573 return -EINVAL;
8574
8575 if (!rdev->ops->probe_client)
8576 return -EOPNOTSUPP;
8577
8578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8579 if (!msg)
8580 return -ENOMEM;
8581
Eric W. Biederman15e47302012-09-07 20:12:54 +00008582 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008583 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008584 if (!hdr) {
8585 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008586 goto free_msg;
8587 }
8588
8589 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8590
Hila Gonene35e4d22012-06-27 17:19:42 +03008591 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008592 if (err)
8593 goto free_msg;
8594
David S. Miller9360ffd2012-03-29 04:41:26 -04008595 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8596 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008597
8598 genlmsg_end(msg, hdr);
8599
8600 return genlmsg_reply(msg, info);
8601
8602 nla_put_failure:
8603 err = -ENOBUFS;
8604 free_msg:
8605 nlmsg_free(msg);
8606 return err;
8607}
8608
Johannes Berg5e7602302011-11-04 11:18:17 +01008609static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8610{
8611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008612 struct cfg80211_beacon_registration *reg, *nreg;
8613 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008614
8615 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8616 return -EOPNOTSUPP;
8617
Ben Greear37c73b52012-10-26 14:49:25 -07008618 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8619 if (!nreg)
8620 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008621
Ben Greear37c73b52012-10-26 14:49:25 -07008622 /* First, check if already registered. */
8623 spin_lock_bh(&rdev->beacon_registrations_lock);
8624 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8625 if (reg->nlportid == info->snd_portid) {
8626 rv = -EALREADY;
8627 goto out_err;
8628 }
8629 }
8630 /* Add it to the list */
8631 nreg->nlportid = info->snd_portid;
8632 list_add(&nreg->list, &rdev->beacon_registrations);
8633
8634 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008635
8636 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008637out_err:
8638 spin_unlock_bh(&rdev->beacon_registrations_lock);
8639 kfree(nreg);
8640 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008641}
8642
Johannes Berg98104fde2012-06-16 00:19:54 +02008643static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8644{
8645 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8646 struct wireless_dev *wdev = info->user_ptr[1];
8647 int err;
8648
8649 if (!rdev->ops->start_p2p_device)
8650 return -EOPNOTSUPP;
8651
8652 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8653 return -EOPNOTSUPP;
8654
8655 if (wdev->p2p_started)
8656 return 0;
8657
Johannes Berg98104fde2012-06-16 00:19:54 +02008658 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008659 if (err)
8660 return err;
8661
Johannes Bergeeb126e2012-10-23 15:16:50 +02008662 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008663 if (err)
8664 return err;
8665
8666 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008667 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008668
8669 return 0;
8670}
8671
8672static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8673{
8674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8675 struct wireless_dev *wdev = info->user_ptr[1];
8676
8677 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8678 return -EOPNOTSUPP;
8679
8680 if (!rdev->ops->stop_p2p_device)
8681 return -EOPNOTSUPP;
8682
Johannes Bergf9f47522013-03-19 15:04:07 +01008683 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008684
8685 return 0;
8686}
8687
Johannes Berg3713b4e2013-02-14 16:19:38 +01008688static int nl80211_get_protocol_features(struct sk_buff *skb,
8689 struct genl_info *info)
8690{
8691 void *hdr;
8692 struct sk_buff *msg;
8693
8694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8695 if (!msg)
8696 return -ENOMEM;
8697
8698 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8699 NL80211_CMD_GET_PROTOCOL_FEATURES);
8700 if (!hdr)
8701 goto nla_put_failure;
8702
8703 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8704 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8705 goto nla_put_failure;
8706
8707 genlmsg_end(msg, hdr);
8708 return genlmsg_reply(msg, info);
8709
8710 nla_put_failure:
8711 kfree_skb(msg);
8712 return -ENOBUFS;
8713}
8714
Jouni Malinen355199e2013-02-27 17:14:27 +02008715static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8716{
8717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8718 struct cfg80211_update_ft_ies_params ft_params;
8719 struct net_device *dev = info->user_ptr[1];
8720
8721 if (!rdev->ops->update_ft_ies)
8722 return -EOPNOTSUPP;
8723
8724 if (!info->attrs[NL80211_ATTR_MDID] ||
8725 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8726 return -EINVAL;
8727
8728 memset(&ft_params, 0, sizeof(ft_params));
8729 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8730 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8731 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8732
8733 return rdev_update_ft_ies(rdev, dev, &ft_params);
8734}
8735
Arend van Spriel5de17982013-04-18 15:49:00 +02008736static int nl80211_crit_protocol_start(struct sk_buff *skb,
8737 struct genl_info *info)
8738{
8739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8740 struct wireless_dev *wdev = info->user_ptr[1];
8741 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8742 u16 duration;
8743 int ret;
8744
8745 if (!rdev->ops->crit_proto_start)
8746 return -EOPNOTSUPP;
8747
8748 if (WARN_ON(!rdev->ops->crit_proto_stop))
8749 return -EINVAL;
8750
8751 if (rdev->crit_proto_nlportid)
8752 return -EBUSY;
8753
8754 /* determine protocol if provided */
8755 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8756 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8757
8758 if (proto >= NUM_NL80211_CRIT_PROTO)
8759 return -EINVAL;
8760
8761 /* timeout must be provided */
8762 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8763 return -EINVAL;
8764
8765 duration =
8766 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8767
8768 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8769 return -ERANGE;
8770
8771 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8772 if (!ret)
8773 rdev->crit_proto_nlportid = info->snd_portid;
8774
8775 return ret;
8776}
8777
8778static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8779 struct genl_info *info)
8780{
8781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8782 struct wireless_dev *wdev = info->user_ptr[1];
8783
8784 if (!rdev->ops->crit_proto_stop)
8785 return -EOPNOTSUPP;
8786
8787 if (rdev->crit_proto_nlportid) {
8788 rdev->crit_proto_nlportid = 0;
8789 rdev_crit_proto_stop(rdev, wdev);
8790 }
8791 return 0;
8792}
8793
Johannes Berg4c476992010-10-04 21:36:35 +02008794#define NL80211_FLAG_NEED_WIPHY 0x01
8795#define NL80211_FLAG_NEED_NETDEV 0x02
8796#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008797#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8798#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8799 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008800#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008801/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008802#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8803 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008804
8805static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8806 struct genl_info *info)
8807{
8808 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008809 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008810 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008811 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8812
8813 if (rtnl)
8814 rtnl_lock();
8815
8816 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008817 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008818 if (IS_ERR(rdev)) {
8819 if (rtnl)
8820 rtnl_unlock();
8821 return PTR_ERR(rdev);
8822 }
8823 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008824 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8825 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008826 ASSERT_RTNL();
8827
Johannes Berg89a54e42012-06-15 14:33:17 +02008828 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8829 info->attrs);
8830 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008831 if (rtnl)
8832 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008833 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008834 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008835
Johannes Berg89a54e42012-06-15 14:33:17 +02008836 dev = wdev->netdev;
8837 rdev = wiphy_to_dev(wdev->wiphy);
8838
Johannes Berg1bf614e2012-06-15 15:23:36 +02008839 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8840 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008841 if (rtnl)
8842 rtnl_unlock();
8843 return -EINVAL;
8844 }
8845
8846 info->user_ptr[1] = dev;
8847 } else {
8848 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008849 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008850
Johannes Berg1bf614e2012-06-15 15:23:36 +02008851 if (dev) {
8852 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8853 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008854 if (rtnl)
8855 rtnl_unlock();
8856 return -ENETDOWN;
8857 }
8858
8859 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008860 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8861 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008862 if (rtnl)
8863 rtnl_unlock();
8864 return -ENETDOWN;
8865 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008866 }
8867
Johannes Berg4c476992010-10-04 21:36:35 +02008868 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008869 }
8870
8871 return 0;
8872}
8873
8874static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8875 struct genl_info *info)
8876{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008877 if (info->user_ptr[1]) {
8878 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8879 struct wireless_dev *wdev = info->user_ptr[1];
8880
8881 if (wdev->netdev)
8882 dev_put(wdev->netdev);
8883 } else {
8884 dev_put(info->user_ptr[1]);
8885 }
8886 }
Johannes Berg4c476992010-10-04 21:36:35 +02008887 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8888 rtnl_unlock();
8889}
8890
Johannes Berg55682962007-09-20 13:09:35 -04008891static struct genl_ops nl80211_ops[] = {
8892 {
8893 .cmd = NL80211_CMD_GET_WIPHY,
8894 .doit = nl80211_get_wiphy,
8895 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008896 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008897 .policy = nl80211_policy,
8898 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008899 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8900 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008901 },
8902 {
8903 .cmd = NL80211_CMD_SET_WIPHY,
8904 .doit = nl80211_set_wiphy,
8905 .policy = nl80211_policy,
8906 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008907 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008908 },
8909 {
8910 .cmd = NL80211_CMD_GET_INTERFACE,
8911 .doit = nl80211_get_interface,
8912 .dumpit = nl80211_dump_interface,
8913 .policy = nl80211_policy,
8914 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008915 .internal_flags = NL80211_FLAG_NEED_WDEV |
8916 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008917 },
8918 {
8919 .cmd = NL80211_CMD_SET_INTERFACE,
8920 .doit = nl80211_set_interface,
8921 .policy = nl80211_policy,
8922 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008923 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8924 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008925 },
8926 {
8927 .cmd = NL80211_CMD_NEW_INTERFACE,
8928 .doit = nl80211_new_interface,
8929 .policy = nl80211_policy,
8930 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008931 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8932 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008933 },
8934 {
8935 .cmd = NL80211_CMD_DEL_INTERFACE,
8936 .doit = nl80211_del_interface,
8937 .policy = nl80211_policy,
8938 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008939 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008940 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008941 },
Johannes Berg41ade002007-12-19 02:03:29 +01008942 {
8943 .cmd = NL80211_CMD_GET_KEY,
8944 .doit = nl80211_get_key,
8945 .policy = nl80211_policy,
8946 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008947 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008948 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008949 },
8950 {
8951 .cmd = NL80211_CMD_SET_KEY,
8952 .doit = nl80211_set_key,
8953 .policy = nl80211_policy,
8954 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008955 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008956 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008957 },
8958 {
8959 .cmd = NL80211_CMD_NEW_KEY,
8960 .doit = nl80211_new_key,
8961 .policy = nl80211_policy,
8962 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008964 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008965 },
8966 {
8967 .cmd = NL80211_CMD_DEL_KEY,
8968 .doit = nl80211_del_key,
8969 .policy = nl80211_policy,
8970 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008971 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008972 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008973 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008974 {
8975 .cmd = NL80211_CMD_SET_BEACON,
8976 .policy = nl80211_policy,
8977 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008978 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008979 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008980 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008981 },
8982 {
Johannes Berg88600202012-02-13 15:17:18 +01008983 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008984 .policy = nl80211_policy,
8985 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008986 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008987 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008988 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008989 },
8990 {
Johannes Berg88600202012-02-13 15:17:18 +01008991 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008992 .policy = nl80211_policy,
8993 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008994 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008995 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008996 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008997 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008998 {
8999 .cmd = NL80211_CMD_GET_STATION,
9000 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009001 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009002 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009003 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9004 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009005 },
9006 {
9007 .cmd = NL80211_CMD_SET_STATION,
9008 .doit = nl80211_set_station,
9009 .policy = nl80211_policy,
9010 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009012 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009013 },
9014 {
9015 .cmd = NL80211_CMD_NEW_STATION,
9016 .doit = nl80211_new_station,
9017 .policy = nl80211_policy,
9018 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009020 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009021 },
9022 {
9023 .cmd = NL80211_CMD_DEL_STATION,
9024 .doit = nl80211_del_station,
9025 .policy = nl80211_policy,
9026 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009028 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009029 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009030 {
9031 .cmd = NL80211_CMD_GET_MPATH,
9032 .doit = nl80211_get_mpath,
9033 .dumpit = nl80211_dump_mpath,
9034 .policy = nl80211_policy,
9035 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009036 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009037 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009038 },
9039 {
9040 .cmd = NL80211_CMD_SET_MPATH,
9041 .doit = nl80211_set_mpath,
9042 .policy = nl80211_policy,
9043 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009044 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009045 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009046 },
9047 {
9048 .cmd = NL80211_CMD_NEW_MPATH,
9049 .doit = nl80211_new_mpath,
9050 .policy = nl80211_policy,
9051 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009052 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009053 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009054 },
9055 {
9056 .cmd = NL80211_CMD_DEL_MPATH,
9057 .doit = nl80211_del_mpath,
9058 .policy = nl80211_policy,
9059 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009061 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009062 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009063 {
9064 .cmd = NL80211_CMD_SET_BSS,
9065 .doit = nl80211_set_bss,
9066 .policy = nl80211_policy,
9067 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009068 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009069 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009070 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009071 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009072 .cmd = NL80211_CMD_GET_REG,
9073 .doit = nl80211_get_reg,
9074 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009075 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009076 /* can be retrieved by unprivileged users */
9077 },
9078 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009079 .cmd = NL80211_CMD_SET_REG,
9080 .doit = nl80211_set_reg,
9081 .policy = nl80211_policy,
9082 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009083 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009084 },
9085 {
9086 .cmd = NL80211_CMD_REQ_SET_REG,
9087 .doit = nl80211_req_set_reg,
9088 .policy = nl80211_policy,
9089 .flags = GENL_ADMIN_PERM,
9090 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009091 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009092 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9093 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009094 .policy = nl80211_policy,
9095 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009097 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009098 },
9099 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009100 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9101 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009102 .policy = nl80211_policy,
9103 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009104 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009105 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009106 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009107 {
Johannes Berg2a519312009-02-10 21:25:55 +01009108 .cmd = NL80211_CMD_TRIGGER_SCAN,
9109 .doit = nl80211_trigger_scan,
9110 .policy = nl80211_policy,
9111 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009112 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009113 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009114 },
9115 {
9116 .cmd = NL80211_CMD_GET_SCAN,
9117 .policy = nl80211_policy,
9118 .dumpit = nl80211_dump_scan,
9119 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009120 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009121 .cmd = NL80211_CMD_START_SCHED_SCAN,
9122 .doit = nl80211_start_sched_scan,
9123 .policy = nl80211_policy,
9124 .flags = GENL_ADMIN_PERM,
9125 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9126 NL80211_FLAG_NEED_RTNL,
9127 },
9128 {
9129 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9130 .doit = nl80211_stop_sched_scan,
9131 .policy = nl80211_policy,
9132 .flags = GENL_ADMIN_PERM,
9133 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9134 NL80211_FLAG_NEED_RTNL,
9135 },
9136 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009137 .cmd = NL80211_CMD_AUTHENTICATE,
9138 .doit = nl80211_authenticate,
9139 .policy = nl80211_policy,
9140 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009141 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009142 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009143 },
9144 {
9145 .cmd = NL80211_CMD_ASSOCIATE,
9146 .doit = nl80211_associate,
9147 .policy = nl80211_policy,
9148 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009149 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009150 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009151 },
9152 {
9153 .cmd = NL80211_CMD_DEAUTHENTICATE,
9154 .doit = nl80211_deauthenticate,
9155 .policy = nl80211_policy,
9156 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009157 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009158 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009159 },
9160 {
9161 .cmd = NL80211_CMD_DISASSOCIATE,
9162 .doit = nl80211_disassociate,
9163 .policy = nl80211_policy,
9164 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009165 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009166 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009167 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009168 {
9169 .cmd = NL80211_CMD_JOIN_IBSS,
9170 .doit = nl80211_join_ibss,
9171 .policy = nl80211_policy,
9172 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009173 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009174 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009175 },
9176 {
9177 .cmd = NL80211_CMD_LEAVE_IBSS,
9178 .doit = nl80211_leave_ibss,
9179 .policy = nl80211_policy,
9180 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009181 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009182 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009183 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009184#ifdef CONFIG_NL80211_TESTMODE
9185 {
9186 .cmd = NL80211_CMD_TESTMODE,
9187 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009188 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009189 .policy = nl80211_policy,
9190 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009191 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9192 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009193 },
9194#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009195 {
9196 .cmd = NL80211_CMD_CONNECT,
9197 .doit = nl80211_connect,
9198 .policy = nl80211_policy,
9199 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009201 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009202 },
9203 {
9204 .cmd = NL80211_CMD_DISCONNECT,
9205 .doit = nl80211_disconnect,
9206 .policy = nl80211_policy,
9207 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009208 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009209 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009210 },
Johannes Berg463d0182009-07-14 00:33:35 +02009211 {
9212 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9213 .doit = nl80211_wiphy_netns,
9214 .policy = nl80211_policy,
9215 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009216 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9217 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009218 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009219 {
9220 .cmd = NL80211_CMD_GET_SURVEY,
9221 .policy = nl80211_policy,
9222 .dumpit = nl80211_dump_survey,
9223 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009224 {
9225 .cmd = NL80211_CMD_SET_PMKSA,
9226 .doit = nl80211_setdel_pmksa,
9227 .policy = nl80211_policy,
9228 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009230 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009231 },
9232 {
9233 .cmd = NL80211_CMD_DEL_PMKSA,
9234 .doit = nl80211_setdel_pmksa,
9235 .policy = nl80211_policy,
9236 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009238 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009239 },
9240 {
9241 .cmd = NL80211_CMD_FLUSH_PMKSA,
9242 .doit = nl80211_flush_pmksa,
9243 .policy = nl80211_policy,
9244 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009246 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009247 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009248 {
9249 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9250 .doit = nl80211_remain_on_channel,
9251 .policy = nl80211_policy,
9252 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009253 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009254 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009255 },
9256 {
9257 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9258 .doit = nl80211_cancel_remain_on_channel,
9259 .policy = nl80211_policy,
9260 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009261 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009262 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009263 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009264 {
9265 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9266 .doit = nl80211_set_tx_bitrate_mask,
9267 .policy = nl80211_policy,
9268 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009269 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9270 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009271 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009272 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009273 .cmd = NL80211_CMD_REGISTER_FRAME,
9274 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009275 .policy = nl80211_policy,
9276 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009277 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009278 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009279 },
9280 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009281 .cmd = NL80211_CMD_FRAME,
9282 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009283 .policy = nl80211_policy,
9284 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009285 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009286 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009287 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009288 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009289 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9290 .doit = nl80211_tx_mgmt_cancel_wait,
9291 .policy = nl80211_policy,
9292 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009293 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009294 NL80211_FLAG_NEED_RTNL,
9295 },
9296 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009297 .cmd = NL80211_CMD_SET_POWER_SAVE,
9298 .doit = nl80211_set_power_save,
9299 .policy = nl80211_policy,
9300 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009301 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9302 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009303 },
9304 {
9305 .cmd = NL80211_CMD_GET_POWER_SAVE,
9306 .doit = nl80211_get_power_save,
9307 .policy = nl80211_policy,
9308 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009309 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9310 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009311 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009312 {
9313 .cmd = NL80211_CMD_SET_CQM,
9314 .doit = nl80211_set_cqm,
9315 .policy = nl80211_policy,
9316 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009317 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9318 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009319 },
Johannes Bergf444de02010-05-05 15:25:02 +02009320 {
9321 .cmd = NL80211_CMD_SET_CHANNEL,
9322 .doit = nl80211_set_channel,
9323 .policy = nl80211_policy,
9324 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009325 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9326 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009327 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009328 {
9329 .cmd = NL80211_CMD_SET_WDS_PEER,
9330 .doit = nl80211_set_wds_peer,
9331 .policy = nl80211_policy,
9332 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009333 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9334 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009335 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009336 {
9337 .cmd = NL80211_CMD_JOIN_MESH,
9338 .doit = nl80211_join_mesh,
9339 .policy = nl80211_policy,
9340 .flags = GENL_ADMIN_PERM,
9341 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9342 NL80211_FLAG_NEED_RTNL,
9343 },
9344 {
9345 .cmd = NL80211_CMD_LEAVE_MESH,
9346 .doit = nl80211_leave_mesh,
9347 .policy = nl80211_policy,
9348 .flags = GENL_ADMIN_PERM,
9349 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9350 NL80211_FLAG_NEED_RTNL,
9351 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009352#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009353 {
9354 .cmd = NL80211_CMD_GET_WOWLAN,
9355 .doit = nl80211_get_wowlan,
9356 .policy = nl80211_policy,
9357 /* can be retrieved by unprivileged users */
9358 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9359 NL80211_FLAG_NEED_RTNL,
9360 },
9361 {
9362 .cmd = NL80211_CMD_SET_WOWLAN,
9363 .doit = nl80211_set_wowlan,
9364 .policy = nl80211_policy,
9365 .flags = GENL_ADMIN_PERM,
9366 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9367 NL80211_FLAG_NEED_RTNL,
9368 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009369#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009370 {
9371 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9372 .doit = nl80211_set_rekey_data,
9373 .policy = nl80211_policy,
9374 .flags = GENL_ADMIN_PERM,
9375 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9376 NL80211_FLAG_NEED_RTNL,
9377 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009378 {
9379 .cmd = NL80211_CMD_TDLS_MGMT,
9380 .doit = nl80211_tdls_mgmt,
9381 .policy = nl80211_policy,
9382 .flags = GENL_ADMIN_PERM,
9383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9384 NL80211_FLAG_NEED_RTNL,
9385 },
9386 {
9387 .cmd = NL80211_CMD_TDLS_OPER,
9388 .doit = nl80211_tdls_oper,
9389 .policy = nl80211_policy,
9390 .flags = GENL_ADMIN_PERM,
9391 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9392 NL80211_FLAG_NEED_RTNL,
9393 },
Johannes Berg28946da2011-11-04 11:18:12 +01009394 {
9395 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9396 .doit = nl80211_register_unexpected_frame,
9397 .policy = nl80211_policy,
9398 .flags = GENL_ADMIN_PERM,
9399 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9400 NL80211_FLAG_NEED_RTNL,
9401 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009402 {
9403 .cmd = NL80211_CMD_PROBE_CLIENT,
9404 .doit = nl80211_probe_client,
9405 .policy = nl80211_policy,
9406 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009407 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009408 NL80211_FLAG_NEED_RTNL,
9409 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009410 {
9411 .cmd = NL80211_CMD_REGISTER_BEACONS,
9412 .doit = nl80211_register_beacons,
9413 .policy = nl80211_policy,
9414 .flags = GENL_ADMIN_PERM,
9415 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9416 NL80211_FLAG_NEED_RTNL,
9417 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009418 {
9419 .cmd = NL80211_CMD_SET_NOACK_MAP,
9420 .doit = nl80211_set_noack_map,
9421 .policy = nl80211_policy,
9422 .flags = GENL_ADMIN_PERM,
9423 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9424 NL80211_FLAG_NEED_RTNL,
9425 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009426 {
9427 .cmd = NL80211_CMD_START_P2P_DEVICE,
9428 .doit = nl80211_start_p2p_device,
9429 .policy = nl80211_policy,
9430 .flags = GENL_ADMIN_PERM,
9431 .internal_flags = NL80211_FLAG_NEED_WDEV |
9432 NL80211_FLAG_NEED_RTNL,
9433 },
9434 {
9435 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9436 .doit = nl80211_stop_p2p_device,
9437 .policy = nl80211_policy,
9438 .flags = GENL_ADMIN_PERM,
9439 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9440 NL80211_FLAG_NEED_RTNL,
9441 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009442 {
9443 .cmd = NL80211_CMD_SET_MCAST_RATE,
9444 .doit = nl80211_set_mcast_rate,
9445 .policy = nl80211_policy,
9446 .flags = GENL_ADMIN_PERM,
9447 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9448 NL80211_FLAG_NEED_RTNL,
9449 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309450 {
9451 .cmd = NL80211_CMD_SET_MAC_ACL,
9452 .doit = nl80211_set_mac_acl,
9453 .policy = nl80211_policy,
9454 .flags = GENL_ADMIN_PERM,
9455 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9456 NL80211_FLAG_NEED_RTNL,
9457 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009458 {
9459 .cmd = NL80211_CMD_RADAR_DETECT,
9460 .doit = nl80211_start_radar_detection,
9461 .policy = nl80211_policy,
9462 .flags = GENL_ADMIN_PERM,
9463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9464 NL80211_FLAG_NEED_RTNL,
9465 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009466 {
9467 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9468 .doit = nl80211_get_protocol_features,
9469 .policy = nl80211_policy,
9470 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009471 {
9472 .cmd = NL80211_CMD_UPDATE_FT_IES,
9473 .doit = nl80211_update_ft_ies,
9474 .policy = nl80211_policy,
9475 .flags = GENL_ADMIN_PERM,
9476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9477 NL80211_FLAG_NEED_RTNL,
9478 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009479 {
9480 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9481 .doit = nl80211_crit_protocol_start,
9482 .policy = nl80211_policy,
9483 .flags = GENL_ADMIN_PERM,
9484 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9485 NL80211_FLAG_NEED_RTNL,
9486 },
9487 {
9488 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9489 .doit = nl80211_crit_protocol_stop,
9490 .policy = nl80211_policy,
9491 .flags = GENL_ADMIN_PERM,
9492 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9493 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009494 },
9495 {
9496 .cmd = NL80211_CMD_GET_COALESCE,
9497 .doit = nl80211_get_coalesce,
9498 .policy = nl80211_policy,
9499 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9500 NL80211_FLAG_NEED_RTNL,
9501 },
9502 {
9503 .cmd = NL80211_CMD_SET_COALESCE,
9504 .doit = nl80211_set_coalesce,
9505 .policy = nl80211_policy,
9506 .flags = GENL_ADMIN_PERM,
9507 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9508 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009509 },
9510 {
9511 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9512 .doit = nl80211_channel_switch,
9513 .policy = nl80211_policy,
9514 .flags = GENL_ADMIN_PERM,
9515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9516 NL80211_FLAG_NEED_RTNL,
9517 },
Johannes Berg55682962007-09-20 13:09:35 -04009518};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009519
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009520static struct genl_multicast_group nl80211_mlme_mcgrp = {
9521 .name = "mlme",
9522};
Johannes Berg55682962007-09-20 13:09:35 -04009523
9524/* multicast groups */
9525static struct genl_multicast_group nl80211_config_mcgrp = {
9526 .name = "config",
9527};
Johannes Berg2a519312009-02-10 21:25:55 +01009528static struct genl_multicast_group nl80211_scan_mcgrp = {
9529 .name = "scan",
9530};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009531static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9532 .name = "regulatory",
9533};
Johannes Berg55682962007-09-20 13:09:35 -04009534
9535/* notification functions */
9536
9537void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9538{
9539 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009540 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009541
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009542 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009543 if (!msg)
9544 return;
9545
Johannes Berg86e8cf92013-06-19 10:57:22 +02009546 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009547 nlmsg_free(msg);
9548 return;
9549 }
9550
Johannes Berg463d0182009-07-14 00:33:35 +02009551 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9552 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009553}
9554
Johannes Berg362a4152009-05-24 16:43:15 +02009555static int nl80211_add_scan_req(struct sk_buff *msg,
9556 struct cfg80211_registered_device *rdev)
9557{
9558 struct cfg80211_scan_request *req = rdev->scan_req;
9559 struct nlattr *nest;
9560 int i;
9561
9562 if (WARN_ON(!req))
9563 return 0;
9564
9565 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9566 if (!nest)
9567 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009568 for (i = 0; i < req->n_ssids; i++) {
9569 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9570 goto nla_put_failure;
9571 }
Johannes Berg362a4152009-05-24 16:43:15 +02009572 nla_nest_end(msg, nest);
9573
9574 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9575 if (!nest)
9576 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009577 for (i = 0; i < req->n_channels; i++) {
9578 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9579 goto nla_put_failure;
9580 }
Johannes Berg362a4152009-05-24 16:43:15 +02009581 nla_nest_end(msg, nest);
9582
David S. Miller9360ffd2012-03-29 04:41:26 -04009583 if (req->ie &&
9584 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9585 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009586
Sam Lefflered4737712012-10-11 21:03:31 -07009587 if (req->flags)
9588 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9589
Johannes Berg362a4152009-05-24 16:43:15 +02009590 return 0;
9591 nla_put_failure:
9592 return -ENOBUFS;
9593}
9594
Johannes Berga538e2d2009-06-16 19:56:42 +02009595static int nl80211_send_scan_msg(struct sk_buff *msg,
9596 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009597 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009598 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009599 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009600{
9601 void *hdr;
9602
Eric W. Biederman15e47302012-09-07 20:12:54 +00009603 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009604 if (!hdr)
9605 return -1;
9606
David S. Miller9360ffd2012-03-29 04:41:26 -04009607 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009608 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9609 wdev->netdev->ifindex)) ||
9610 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009611 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009612
Johannes Berg362a4152009-05-24 16:43:15 +02009613 /* ignore errors and send incomplete event anyway */
9614 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009615
9616 return genlmsg_end(msg, hdr);
9617
9618 nla_put_failure:
9619 genlmsg_cancel(msg, hdr);
9620 return -EMSGSIZE;
9621}
9622
Luciano Coelho807f8a82011-05-11 17:09:35 +03009623static int
9624nl80211_send_sched_scan_msg(struct sk_buff *msg,
9625 struct cfg80211_registered_device *rdev,
9626 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009627 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009628{
9629 void *hdr;
9630
Eric W. Biederman15e47302012-09-07 20:12:54 +00009631 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009632 if (!hdr)
9633 return -1;
9634
David S. Miller9360ffd2012-03-29 04:41:26 -04009635 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9636 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9637 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009638
9639 return genlmsg_end(msg, hdr);
9640
9641 nla_put_failure:
9642 genlmsg_cancel(msg, hdr);
9643 return -EMSGSIZE;
9644}
9645
Johannes Berga538e2d2009-06-16 19:56:42 +02009646void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009647 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009648{
9649 struct sk_buff *msg;
9650
Thomas Graf58050fc2012-06-28 03:57:45 +00009651 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009652 if (!msg)
9653 return;
9654
Johannes Bergfd014282012-06-18 19:17:03 +02009655 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009656 NL80211_CMD_TRIGGER_SCAN) < 0) {
9657 nlmsg_free(msg);
9658 return;
9659 }
9660
Johannes Berg463d0182009-07-14 00:33:35 +02009661 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9662 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009663}
9664
Johannes Berg2a519312009-02-10 21:25:55 +01009665void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009666 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009667{
9668 struct sk_buff *msg;
9669
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009670 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009671 if (!msg)
9672 return;
9673
Johannes Bergfd014282012-06-18 19:17:03 +02009674 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009675 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009676 nlmsg_free(msg);
9677 return;
9678 }
9679
Johannes Berg463d0182009-07-14 00:33:35 +02009680 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9681 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009682}
9683
9684void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009685 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009686{
9687 struct sk_buff *msg;
9688
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009689 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009690 if (!msg)
9691 return;
9692
Johannes Bergfd014282012-06-18 19:17:03 +02009693 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009694 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009695 nlmsg_free(msg);
9696 return;
9697 }
9698
Johannes Berg463d0182009-07-14 00:33:35 +02009699 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9700 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009701}
9702
Luciano Coelho807f8a82011-05-11 17:09:35 +03009703void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9704 struct net_device *netdev)
9705{
9706 struct sk_buff *msg;
9707
9708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9709 if (!msg)
9710 return;
9711
9712 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9713 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9714 nlmsg_free(msg);
9715 return;
9716 }
9717
9718 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9719 nl80211_scan_mcgrp.id, GFP_KERNEL);
9720}
9721
9722void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9723 struct net_device *netdev, u32 cmd)
9724{
9725 struct sk_buff *msg;
9726
Thomas Graf58050fc2012-06-28 03:57:45 +00009727 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009728 if (!msg)
9729 return;
9730
9731 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9732 nlmsg_free(msg);
9733 return;
9734 }
9735
9736 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9737 nl80211_scan_mcgrp.id, GFP_KERNEL);
9738}
9739
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009740/*
9741 * This can happen on global regulatory changes or device specific settings
9742 * based on custom world regulatory domains.
9743 */
9744void nl80211_send_reg_change_event(struct regulatory_request *request)
9745{
9746 struct sk_buff *msg;
9747 void *hdr;
9748
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009749 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009750 if (!msg)
9751 return;
9752
9753 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9754 if (!hdr) {
9755 nlmsg_free(msg);
9756 return;
9757 }
9758
9759 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009760 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9761 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009762
David S. Miller9360ffd2012-03-29 04:41:26 -04009763 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9764 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9765 NL80211_REGDOM_TYPE_WORLD))
9766 goto nla_put_failure;
9767 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9768 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9769 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9770 goto nla_put_failure;
9771 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9772 request->intersect) {
9773 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9774 NL80211_REGDOM_TYPE_INTERSECTION))
9775 goto nla_put_failure;
9776 } else {
9777 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9778 NL80211_REGDOM_TYPE_COUNTRY) ||
9779 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9780 request->alpha2))
9781 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009782 }
9783
Johannes Bergf4173762012-12-03 18:23:37 +01009784 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009785 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9786 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009787
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009788 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009789
Johannes Bergbc43b282009-07-25 10:54:13 +02009790 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009791 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009792 GFP_ATOMIC);
9793 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009794
9795 return;
9796
9797nla_put_failure:
9798 genlmsg_cancel(msg, hdr);
9799 nlmsg_free(msg);
9800}
9801
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009802static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9803 struct net_device *netdev,
9804 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009805 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009806{
9807 struct sk_buff *msg;
9808 void *hdr;
9809
Johannes Berge6d6e342009-07-01 21:26:47 +02009810 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009811 if (!msg)
9812 return;
9813
9814 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9815 if (!hdr) {
9816 nlmsg_free(msg);
9817 return;
9818 }
9819
David S. Miller9360ffd2012-03-29 04:41:26 -04009820 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9821 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9822 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9823 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009824
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009825 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009826
Johannes Berg463d0182009-07-14 00:33:35 +02009827 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9828 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009829 return;
9830
9831 nla_put_failure:
9832 genlmsg_cancel(msg, hdr);
9833 nlmsg_free(msg);
9834}
9835
9836void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009837 struct net_device *netdev, const u8 *buf,
9838 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009839{
9840 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009841 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009842}
9843
9844void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9845 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009846 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009847{
Johannes Berge6d6e342009-07-01 21:26:47 +02009848 nl80211_send_mlme_event(rdev, netdev, buf, len,
9849 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009850}
9851
Jouni Malinen53b46b82009-03-27 20:53:56 +02009852void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009853 struct net_device *netdev, const u8 *buf,
9854 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009855{
9856 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009857 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009858}
9859
Jouni Malinen53b46b82009-03-27 20:53:56 +02009860void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9861 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009862 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009863{
9864 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009865 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009866}
9867
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009868void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9869 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009870{
Johannes Berg947add32013-02-22 22:05:20 +01009871 struct wireless_dev *wdev = dev->ieee80211_ptr;
9872 struct wiphy *wiphy = wdev->wiphy;
9873 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009874 const struct ieee80211_mgmt *mgmt = (void *)buf;
9875 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009876
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009877 if (WARN_ON(len < 2))
9878 return;
9879
9880 if (ieee80211_is_deauth(mgmt->frame_control))
9881 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9882 else
9883 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9884
9885 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9886 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009887}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009888EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009889
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009890static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9891 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009892 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009893{
9894 struct sk_buff *msg;
9895 void *hdr;
9896
Johannes Berge6d6e342009-07-01 21:26:47 +02009897 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009898 if (!msg)
9899 return;
9900
9901 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9902 if (!hdr) {
9903 nlmsg_free(msg);
9904 return;
9905 }
9906
David S. Miller9360ffd2012-03-29 04:41:26 -04009907 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9908 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9909 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9910 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9911 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009912
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009913 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009914
Johannes Berg463d0182009-07-14 00:33:35 +02009915 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9916 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009917 return;
9918
9919 nla_put_failure:
9920 genlmsg_cancel(msg, hdr);
9921 nlmsg_free(msg);
9922}
9923
9924void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009925 struct net_device *netdev, const u8 *addr,
9926 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009927{
9928 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009929 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009930}
9931
9932void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009933 struct net_device *netdev, const u8 *addr,
9934 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009935{
Johannes Berge6d6e342009-07-01 21:26:47 +02009936 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9937 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009938}
9939
Samuel Ortizb23aa672009-07-01 21:26:54 +02009940void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9941 struct net_device *netdev, const u8 *bssid,
9942 const u8 *req_ie, size_t req_ie_len,
9943 const u8 *resp_ie, size_t resp_ie_len,
9944 u16 status, gfp_t gfp)
9945{
9946 struct sk_buff *msg;
9947 void *hdr;
9948
Thomas Graf58050fc2012-06-28 03:57:45 +00009949 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009950 if (!msg)
9951 return;
9952
9953 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9954 if (!hdr) {
9955 nlmsg_free(msg);
9956 return;
9957 }
9958
David S. Miller9360ffd2012-03-29 04:41:26 -04009959 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9960 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9961 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9962 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9963 (req_ie &&
9964 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9965 (resp_ie &&
9966 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9967 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009968
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009969 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009970
Johannes Berg463d0182009-07-14 00:33:35 +02009971 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9972 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009973 return;
9974
9975 nla_put_failure:
9976 genlmsg_cancel(msg, hdr);
9977 nlmsg_free(msg);
9978
9979}
9980
9981void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9982 struct net_device *netdev, const u8 *bssid,
9983 const u8 *req_ie, size_t req_ie_len,
9984 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9985{
9986 struct sk_buff *msg;
9987 void *hdr;
9988
Thomas Graf58050fc2012-06-28 03:57:45 +00009989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009990 if (!msg)
9991 return;
9992
9993 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9994 if (!hdr) {
9995 nlmsg_free(msg);
9996 return;
9997 }
9998
David S. Miller9360ffd2012-03-29 04:41:26 -04009999 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10000 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10001 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10002 (req_ie &&
10003 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10004 (resp_ie &&
10005 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10006 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010007
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010008 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010009
Johannes Berg463d0182009-07-14 00:33:35 +020010010 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10011 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010012 return;
10013
10014 nla_put_failure:
10015 genlmsg_cancel(msg, hdr);
10016 nlmsg_free(msg);
10017
10018}
10019
10020void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10021 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010022 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010023{
10024 struct sk_buff *msg;
10025 void *hdr;
10026
Thomas Graf58050fc2012-06-28 03:57:45 +000010027 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010028 if (!msg)
10029 return;
10030
10031 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10032 if (!hdr) {
10033 nlmsg_free(msg);
10034 return;
10035 }
10036
David S. Miller9360ffd2012-03-29 04:41:26 -040010037 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10038 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10039 (from_ap && reason &&
10040 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10041 (from_ap &&
10042 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10043 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10044 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010045
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010046 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010047
Johannes Berg463d0182009-07-14 00:33:35 +020010048 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10049 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010050 return;
10051
10052 nla_put_failure:
10053 genlmsg_cancel(msg, hdr);
10054 nlmsg_free(msg);
10055
10056}
10057
Johannes Berg04a773a2009-04-19 21:24:32 +020010058void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10059 struct net_device *netdev, const u8 *bssid,
10060 gfp_t gfp)
10061{
10062 struct sk_buff *msg;
10063 void *hdr;
10064
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010066 if (!msg)
10067 return;
10068
10069 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10070 if (!hdr) {
10071 nlmsg_free(msg);
10072 return;
10073 }
10074
David S. Miller9360ffd2012-03-29 04:41:26 -040010075 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10076 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10077 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10078 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010079
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010080 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010081
Johannes Berg463d0182009-07-14 00:33:35 +020010082 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10083 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010084 return;
10085
10086 nla_put_failure:
10087 genlmsg_cancel(msg, hdr);
10088 nlmsg_free(msg);
10089}
10090
Johannes Berg947add32013-02-22 22:05:20 +010010091void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10092 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010093{
Johannes Berg947add32013-02-22 22:05:20 +010010094 struct wireless_dev *wdev = dev->ieee80211_ptr;
10095 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010096 struct sk_buff *msg;
10097 void *hdr;
10098
Johannes Berg947add32013-02-22 22:05:20 +010010099 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10100 return;
10101
10102 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10103
Javier Cardonac93b5e72011-04-07 15:08:34 -070010104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10105 if (!msg)
10106 return;
10107
10108 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10109 if (!hdr) {
10110 nlmsg_free(msg);
10111 return;
10112 }
10113
David S. Miller9360ffd2012-03-29 04:41:26 -040010114 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010115 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10116 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010117 (ie_len && ie &&
10118 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10119 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010120
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010121 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010122
10123 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10124 nl80211_mlme_mcgrp.id, gfp);
10125 return;
10126
10127 nla_put_failure:
10128 genlmsg_cancel(msg, hdr);
10129 nlmsg_free(msg);
10130}
Johannes Berg947add32013-02-22 22:05:20 +010010131EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010132
Jouni Malinena3b8b052009-03-27 21:59:49 +020010133void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10134 struct net_device *netdev, const u8 *addr,
10135 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010136 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010137{
10138 struct sk_buff *msg;
10139 void *hdr;
10140
Johannes Berge6d6e342009-07-01 21:26:47 +020010141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010142 if (!msg)
10143 return;
10144
10145 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10146 if (!hdr) {
10147 nlmsg_free(msg);
10148 return;
10149 }
10150
David S. Miller9360ffd2012-03-29 04:41:26 -040010151 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10152 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10153 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10154 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10155 (key_id != -1 &&
10156 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10157 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10158 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010159
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010160 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010161
Johannes Berg463d0182009-07-14 00:33:35 +020010162 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10163 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010164 return;
10165
10166 nla_put_failure:
10167 genlmsg_cancel(msg, hdr);
10168 nlmsg_free(msg);
10169}
10170
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010171void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10172 struct ieee80211_channel *channel_before,
10173 struct ieee80211_channel *channel_after)
10174{
10175 struct sk_buff *msg;
10176 void *hdr;
10177 struct nlattr *nl_freq;
10178
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010179 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010180 if (!msg)
10181 return;
10182
10183 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10184 if (!hdr) {
10185 nlmsg_free(msg);
10186 return;
10187 }
10188
10189 /*
10190 * Since we are applying the beacon hint to a wiphy we know its
10191 * wiphy_idx is valid
10192 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010193 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10194 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010195
10196 /* Before */
10197 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10198 if (!nl_freq)
10199 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010200 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010201 goto nla_put_failure;
10202 nla_nest_end(msg, nl_freq);
10203
10204 /* After */
10205 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10206 if (!nl_freq)
10207 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010208 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010209 goto nla_put_failure;
10210 nla_nest_end(msg, nl_freq);
10211
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010212 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010213
Johannes Berg463d0182009-07-14 00:33:35 +020010214 rcu_read_lock();
10215 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10216 GFP_ATOMIC);
10217 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010218
10219 return;
10220
10221nla_put_failure:
10222 genlmsg_cancel(msg, hdr);
10223 nlmsg_free(msg);
10224}
10225
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010226static void nl80211_send_remain_on_chan_event(
10227 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010228 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010229 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010230 unsigned int duration, gfp_t gfp)
10231{
10232 struct sk_buff *msg;
10233 void *hdr;
10234
10235 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10236 if (!msg)
10237 return;
10238
10239 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10240 if (!hdr) {
10241 nlmsg_free(msg);
10242 return;
10243 }
10244
David S. Miller9360ffd2012-03-29 04:41:26 -040010245 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010246 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10247 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010248 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010249 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010250 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10251 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010252 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10253 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010254
David S. Miller9360ffd2012-03-29 04:41:26 -040010255 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10256 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10257 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010258
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010259 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010260
10261 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10262 nl80211_mlme_mcgrp.id, gfp);
10263 return;
10264
10265 nla_put_failure:
10266 genlmsg_cancel(msg, hdr);
10267 nlmsg_free(msg);
10268}
10269
Johannes Berg947add32013-02-22 22:05:20 +010010270void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10271 struct ieee80211_channel *chan,
10272 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010273{
Johannes Berg947add32013-02-22 22:05:20 +010010274 struct wiphy *wiphy = wdev->wiphy;
10275 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10276
10277 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010278 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010279 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010280 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010281}
Johannes Berg947add32013-02-22 22:05:20 +010010282EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010283
Johannes Berg947add32013-02-22 22:05:20 +010010284void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10285 struct ieee80211_channel *chan,
10286 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010287{
Johannes Berg947add32013-02-22 22:05:20 +010010288 struct wiphy *wiphy = wdev->wiphy;
10289 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10290
10291 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010292 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010293 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010294}
Johannes Berg947add32013-02-22 22:05:20 +010010295EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010296
Johannes Berg947add32013-02-22 22:05:20 +010010297void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10298 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010299{
Johannes Berg947add32013-02-22 22:05:20 +010010300 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10301 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010302 struct sk_buff *msg;
10303
Johannes Berg947add32013-02-22 22:05:20 +010010304 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10305
Thomas Graf58050fc2012-06-28 03:57:45 +000010306 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010307 if (!msg)
10308 return;
10309
John W. Linville66266b32012-03-15 13:25:41 -040010310 if (nl80211_send_station(msg, 0, 0, 0,
10311 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010312 nlmsg_free(msg);
10313 return;
10314 }
10315
10316 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10317 nl80211_mlme_mcgrp.id, gfp);
10318}
Johannes Berg947add32013-02-22 22:05:20 +010010319EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010320
Johannes Berg947add32013-02-22 22:05:20 +010010321void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010322{
Johannes Berg947add32013-02-22 22:05:20 +010010323 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10324 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010325 struct sk_buff *msg;
10326 void *hdr;
10327
Johannes Berg947add32013-02-22 22:05:20 +010010328 trace_cfg80211_del_sta(dev, mac_addr);
10329
Thomas Graf58050fc2012-06-28 03:57:45 +000010330 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010331 if (!msg)
10332 return;
10333
10334 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10335 if (!hdr) {
10336 nlmsg_free(msg);
10337 return;
10338 }
10339
David S. Miller9360ffd2012-03-29 04:41:26 -040010340 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10341 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10342 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010343
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010344 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010345
10346 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10347 nl80211_mlme_mcgrp.id, gfp);
10348 return;
10349
10350 nla_put_failure:
10351 genlmsg_cancel(msg, hdr);
10352 nlmsg_free(msg);
10353}
Johannes Berg947add32013-02-22 22:05:20 +010010354EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010355
Johannes Berg947add32013-02-22 22:05:20 +010010356void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10357 enum nl80211_connect_failed_reason reason,
10358 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010359{
Johannes Berg947add32013-02-22 22:05:20 +010010360 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10361 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010362 struct sk_buff *msg;
10363 void *hdr;
10364
10365 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10366 if (!msg)
10367 return;
10368
10369 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10370 if (!hdr) {
10371 nlmsg_free(msg);
10372 return;
10373 }
10374
10375 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10376 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10377 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10378 goto nla_put_failure;
10379
10380 genlmsg_end(msg, hdr);
10381
10382 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10383 nl80211_mlme_mcgrp.id, gfp);
10384 return;
10385
10386 nla_put_failure:
10387 genlmsg_cancel(msg, hdr);
10388 nlmsg_free(msg);
10389}
Johannes Berg947add32013-02-22 22:05:20 +010010390EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010391
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010392static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10393 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010394{
10395 struct wireless_dev *wdev = dev->ieee80211_ptr;
10396 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10397 struct sk_buff *msg;
10398 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010399 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010400
Eric W. Biederman15e47302012-09-07 20:12:54 +000010401 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010402 return false;
10403
10404 msg = nlmsg_new(100, gfp);
10405 if (!msg)
10406 return true;
10407
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010408 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010409 if (!hdr) {
10410 nlmsg_free(msg);
10411 return true;
10412 }
10413
David S. Miller9360ffd2012-03-29 04:41:26 -040010414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10415 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10416 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10417 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010418
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010419 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010420 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010421 return true;
10422
10423 nla_put_failure:
10424 genlmsg_cancel(msg, hdr);
10425 nlmsg_free(msg);
10426 return true;
10427}
10428
Johannes Berg947add32013-02-22 22:05:20 +010010429bool cfg80211_rx_spurious_frame(struct net_device *dev,
10430 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010431{
Johannes Berg947add32013-02-22 22:05:20 +010010432 struct wireless_dev *wdev = dev->ieee80211_ptr;
10433 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010434
Johannes Berg947add32013-02-22 22:05:20 +010010435 trace_cfg80211_rx_spurious_frame(dev, addr);
10436
10437 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10438 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10439 trace_cfg80211_return_bool(false);
10440 return false;
10441 }
10442 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10443 addr, gfp);
10444 trace_cfg80211_return_bool(ret);
10445 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010446}
Johannes Berg947add32013-02-22 22:05:20 +010010447EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10448
10449bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10450 const u8 *addr, gfp_t gfp)
10451{
10452 struct wireless_dev *wdev = dev->ieee80211_ptr;
10453 bool ret;
10454
10455 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10456
10457 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10458 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10459 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10460 trace_cfg80211_return_bool(false);
10461 return false;
10462 }
10463 ret = __nl80211_unexpected_frame(dev,
10464 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10465 addr, gfp);
10466 trace_cfg80211_return_bool(ret);
10467 return ret;
10468}
10469EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010470
Johannes Berg2e161f72010-08-12 15:38:38 +020010471int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010472 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010473 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010474 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010475{
Johannes Berg71bbc992012-06-15 15:30:18 +020010476 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010477 struct sk_buff *msg;
10478 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010479
10480 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10481 if (!msg)
10482 return -ENOMEM;
10483
Johannes Berg2e161f72010-08-12 15:38:38 +020010484 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010485 if (!hdr) {
10486 nlmsg_free(msg);
10487 return -ENOMEM;
10488 }
10489
David S. Miller9360ffd2012-03-29 04:41:26 -040010490 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010491 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10492 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010493 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010494 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10495 (sig_dbm &&
10496 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010497 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10498 (flags &&
10499 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010500 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010501
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010502 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010503
Eric W. Biederman15e47302012-09-07 20:12:54 +000010504 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010505
10506 nla_put_failure:
10507 genlmsg_cancel(msg, hdr);
10508 nlmsg_free(msg);
10509 return -ENOBUFS;
10510}
10511
Johannes Berg947add32013-02-22 22:05:20 +010010512void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10513 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010514{
Johannes Berg947add32013-02-22 22:05:20 +010010515 struct wiphy *wiphy = wdev->wiphy;
10516 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010517 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010518 struct sk_buff *msg;
10519 void *hdr;
10520
Johannes Berg947add32013-02-22 22:05:20 +010010521 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10522
Jouni Malinen026331c2010-02-15 12:53:10 +020010523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10524 if (!msg)
10525 return;
10526
Johannes Berg2e161f72010-08-12 15:38:38 +020010527 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010528 if (!hdr) {
10529 nlmsg_free(msg);
10530 return;
10531 }
10532
David S. Miller9360ffd2012-03-29 04:41:26 -040010533 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010534 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10535 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010536 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010537 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10538 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10539 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10540 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010541
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010542 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010543
Michal Kaziora0ec5702013-06-25 09:17:17 +020010544 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10545 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010546 return;
10547
10548 nla_put_failure:
10549 genlmsg_cancel(msg, hdr);
10550 nlmsg_free(msg);
10551}
Johannes Berg947add32013-02-22 22:05:20 +010010552EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010553
Johannes Berg947add32013-02-22 22:05:20 +010010554void cfg80211_cqm_rssi_notify(struct net_device *dev,
10555 enum nl80211_cqm_rssi_threshold_event rssi_event,
10556 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010557{
Johannes Berg947add32013-02-22 22:05:20 +010010558 struct wireless_dev *wdev = dev->ieee80211_ptr;
10559 struct wiphy *wiphy = wdev->wiphy;
10560 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010561 struct sk_buff *msg;
10562 struct nlattr *pinfoattr;
10563 void *hdr;
10564
Johannes Berg947add32013-02-22 22:05:20 +010010565 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10566
Thomas Graf58050fc2012-06-28 03:57:45 +000010567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010568 if (!msg)
10569 return;
10570
10571 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10572 if (!hdr) {
10573 nlmsg_free(msg);
10574 return;
10575 }
10576
David S. Miller9360ffd2012-03-29 04:41:26 -040010577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010578 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010579 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010580
10581 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10582 if (!pinfoattr)
10583 goto nla_put_failure;
10584
David S. Miller9360ffd2012-03-29 04:41:26 -040010585 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10586 rssi_event))
10587 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010588
10589 nla_nest_end(msg, pinfoattr);
10590
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010591 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010592
10593 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10594 nl80211_mlme_mcgrp.id, gfp);
10595 return;
10596
10597 nla_put_failure:
10598 genlmsg_cancel(msg, hdr);
10599 nlmsg_free(msg);
10600}
Johannes Berg947add32013-02-22 22:05:20 +010010601EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010602
Johannes Berg947add32013-02-22 22:05:20 +010010603static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10604 struct net_device *netdev, const u8 *bssid,
10605 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010606{
10607 struct sk_buff *msg;
10608 struct nlattr *rekey_attr;
10609 void *hdr;
10610
Thomas Graf58050fc2012-06-28 03:57:45 +000010611 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010612 if (!msg)
10613 return;
10614
10615 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10616 if (!hdr) {
10617 nlmsg_free(msg);
10618 return;
10619 }
10620
David S. Miller9360ffd2012-03-29 04:41:26 -040010621 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10622 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10623 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10624 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010625
10626 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10627 if (!rekey_attr)
10628 goto nla_put_failure;
10629
David S. Miller9360ffd2012-03-29 04:41:26 -040010630 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10631 NL80211_REPLAY_CTR_LEN, replay_ctr))
10632 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010633
10634 nla_nest_end(msg, rekey_attr);
10635
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010636 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +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}
10646
Johannes Berg947add32013-02-22 22:05:20 +010010647void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10648 const u8 *replay_ctr, gfp_t gfp)
10649{
10650 struct wireless_dev *wdev = dev->ieee80211_ptr;
10651 struct wiphy *wiphy = wdev->wiphy;
10652 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10653
10654 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10655 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10656}
10657EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10658
10659static void
10660nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10661 struct net_device *netdev, int index,
10662 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010663{
10664 struct sk_buff *msg;
10665 struct nlattr *attr;
10666 void *hdr;
10667
Thomas Graf58050fc2012-06-28 03:57:45 +000010668 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010669 if (!msg)
10670 return;
10671
10672 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10673 if (!hdr) {
10674 nlmsg_free(msg);
10675 return;
10676 }
10677
David S. Miller9360ffd2012-03-29 04:41:26 -040010678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10679 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10680 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010681
10682 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10683 if (!attr)
10684 goto nla_put_failure;
10685
David S. Miller9360ffd2012-03-29 04:41:26 -040010686 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10687 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10688 (preauth &&
10689 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10690 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010691
10692 nla_nest_end(msg, attr);
10693
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010694 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010695
10696 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10697 nl80211_mlme_mcgrp.id, gfp);
10698 return;
10699
10700 nla_put_failure:
10701 genlmsg_cancel(msg, hdr);
10702 nlmsg_free(msg);
10703}
10704
Johannes Berg947add32013-02-22 22:05:20 +010010705void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10706 const u8 *bssid, bool preauth, gfp_t gfp)
10707{
10708 struct wireless_dev *wdev = dev->ieee80211_ptr;
10709 struct wiphy *wiphy = wdev->wiphy;
10710 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10711
10712 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10713 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10714}
10715EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10716
10717static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10718 struct net_device *netdev,
10719 struct cfg80211_chan_def *chandef,
10720 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010721{
10722 struct sk_buff *msg;
10723 void *hdr;
10724
Thomas Graf58050fc2012-06-28 03:57:45 +000010725 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010726 if (!msg)
10727 return;
10728
10729 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10730 if (!hdr) {
10731 nlmsg_free(msg);
10732 return;
10733 }
10734
Johannes Berg683b6d32012-11-08 21:25:48 +010010735 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10736 goto nla_put_failure;
10737
10738 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010739 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010740
10741 genlmsg_end(msg, hdr);
10742
10743 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10744 nl80211_mlme_mcgrp.id, gfp);
10745 return;
10746
10747 nla_put_failure:
10748 genlmsg_cancel(msg, hdr);
10749 nlmsg_free(msg);
10750}
10751
Johannes Berg947add32013-02-22 22:05:20 +010010752void cfg80211_ch_switch_notify(struct net_device *dev,
10753 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010754{
Johannes Berg947add32013-02-22 22:05:20 +010010755 struct wireless_dev *wdev = dev->ieee80211_ptr;
10756 struct wiphy *wiphy = wdev->wiphy;
10757 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10758
10759 trace_cfg80211_ch_switch_notify(dev, chandef);
10760
10761 wdev_lock(wdev);
10762
10763 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020010764 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10765 wdev->iftype != NL80211_IFTYPE_ADHOC))
Johannes Berg947add32013-02-22 22:05:20 +010010766 goto out;
10767
10768 wdev->channel = chandef->chan;
10769 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10770out:
10771 wdev_unlock(wdev);
10772 return;
10773}
10774EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10775
10776void cfg80211_cqm_txe_notify(struct net_device *dev,
10777 const u8 *peer, u32 num_packets,
10778 u32 rate, u32 intvl, gfp_t gfp)
10779{
10780 struct wireless_dev *wdev = dev->ieee80211_ptr;
10781 struct wiphy *wiphy = wdev->wiphy;
10782 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010783 struct sk_buff *msg;
10784 struct nlattr *pinfoattr;
10785 void *hdr;
10786
10787 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10788 if (!msg)
10789 return;
10790
10791 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10792 if (!hdr) {
10793 nlmsg_free(msg);
10794 return;
10795 }
10796
10797 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010798 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010799 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10800 goto nla_put_failure;
10801
10802 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10803 if (!pinfoattr)
10804 goto nla_put_failure;
10805
10806 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10807 goto nla_put_failure;
10808
10809 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10810 goto nla_put_failure;
10811
10812 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10813 goto nla_put_failure;
10814
10815 nla_nest_end(msg, pinfoattr);
10816
10817 genlmsg_end(msg, hdr);
10818
10819 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10820 nl80211_mlme_mcgrp.id, gfp);
10821 return;
10822
10823 nla_put_failure:
10824 genlmsg_cancel(msg, hdr);
10825 nlmsg_free(msg);
10826}
Johannes Berg947add32013-02-22 22:05:20 +010010827EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010828
10829void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010830nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10831 struct cfg80211_chan_def *chandef,
10832 enum nl80211_radar_event event,
10833 struct net_device *netdev, gfp_t gfp)
10834{
10835 struct sk_buff *msg;
10836 void *hdr;
10837
10838 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10839 if (!msg)
10840 return;
10841
10842 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10843 if (!hdr) {
10844 nlmsg_free(msg);
10845 return;
10846 }
10847
10848 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10849 goto nla_put_failure;
10850
10851 /* NOP and radar events don't need a netdev parameter */
10852 if (netdev) {
10853 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10854
10855 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10856 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10857 goto nla_put_failure;
10858 }
10859
10860 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10861 goto nla_put_failure;
10862
10863 if (nl80211_send_chandef(msg, chandef))
10864 goto nla_put_failure;
10865
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010866 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010867
10868 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10869 nl80211_mlme_mcgrp.id, gfp);
10870 return;
10871
10872 nla_put_failure:
10873 genlmsg_cancel(msg, hdr);
10874 nlmsg_free(msg);
10875}
10876
Johannes Berg947add32013-02-22 22:05:20 +010010877void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10878 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010879{
Johannes Berg947add32013-02-22 22:05:20 +010010880 struct wireless_dev *wdev = dev->ieee80211_ptr;
10881 struct wiphy *wiphy = wdev->wiphy;
10882 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010883 struct sk_buff *msg;
10884 struct nlattr *pinfoattr;
10885 void *hdr;
10886
Johannes Berg947add32013-02-22 22:05:20 +010010887 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10888
Thomas Graf58050fc2012-06-28 03:57:45 +000010889 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010890 if (!msg)
10891 return;
10892
10893 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10894 if (!hdr) {
10895 nlmsg_free(msg);
10896 return;
10897 }
10898
David S. Miller9360ffd2012-03-29 04:41:26 -040010899 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010900 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010901 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10902 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010903
10904 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10905 if (!pinfoattr)
10906 goto nla_put_failure;
10907
David S. Miller9360ffd2012-03-29 04:41:26 -040010908 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10909 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010910
10911 nla_nest_end(msg, pinfoattr);
10912
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010913 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010914
10915 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10916 nl80211_mlme_mcgrp.id, gfp);
10917 return;
10918
10919 nla_put_failure:
10920 genlmsg_cancel(msg, hdr);
10921 nlmsg_free(msg);
10922}
Johannes Berg947add32013-02-22 22:05:20 +010010923EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010924
Johannes Berg7f6cf312011-11-04 11:18:15 +010010925void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10926 u64 cookie, bool acked, gfp_t gfp)
10927{
10928 struct wireless_dev *wdev = dev->ieee80211_ptr;
10929 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10930 struct sk_buff *msg;
10931 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010932
Beni Lev4ee3e062012-08-27 12:49:39 +030010933 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10934
Thomas Graf58050fc2012-06-28 03:57:45 +000010935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010936
Johannes Berg7f6cf312011-11-04 11:18:15 +010010937 if (!msg)
10938 return;
10939
10940 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10941 if (!hdr) {
10942 nlmsg_free(msg);
10943 return;
10944 }
10945
David S. Miller9360ffd2012-03-29 04:41:26 -040010946 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10947 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10948 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10949 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10950 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10951 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010952
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010953 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010954
10955 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10956 nl80211_mlme_mcgrp.id, gfp);
10957 return;
10958
10959 nla_put_failure:
10960 genlmsg_cancel(msg, hdr);
10961 nlmsg_free(msg);
10962}
10963EXPORT_SYMBOL(cfg80211_probe_status);
10964
Johannes Berg5e7602302011-11-04 11:18:17 +010010965void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10966 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010967 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010968{
10969 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10970 struct sk_buff *msg;
10971 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010972 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010973
Beni Lev4ee3e062012-08-27 12:49:39 +030010974 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10975
Ben Greear37c73b52012-10-26 14:49:25 -070010976 spin_lock_bh(&rdev->beacon_registrations_lock);
10977 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10978 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10979 if (!msg) {
10980 spin_unlock_bh(&rdev->beacon_registrations_lock);
10981 return;
10982 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010983
Ben Greear37c73b52012-10-26 14:49:25 -070010984 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10985 if (!hdr)
10986 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010987
Ben Greear37c73b52012-10-26 14:49:25 -070010988 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10989 (freq &&
10990 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10991 (sig_dbm &&
10992 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10993 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10994 goto nla_put_failure;
10995
10996 genlmsg_end(msg, hdr);
10997
10998 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010999 }
Ben Greear37c73b52012-10-26 14:49:25 -070011000 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011001 return;
11002
11003 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011004 spin_unlock_bh(&rdev->beacon_registrations_lock);
11005 if (hdr)
11006 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011007 nlmsg_free(msg);
11008}
11009EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11010
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011011#ifdef CONFIG_PM
11012void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11013 struct cfg80211_wowlan_wakeup *wakeup,
11014 gfp_t gfp)
11015{
11016 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11017 struct sk_buff *msg;
11018 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011019 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011020
11021 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11022
11023 if (wakeup)
11024 size += wakeup->packet_present_len;
11025
11026 msg = nlmsg_new(size, gfp);
11027 if (!msg)
11028 return;
11029
11030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11031 if (!hdr)
11032 goto free_msg;
11033
11034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11035 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11036 goto free_msg;
11037
11038 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11039 wdev->netdev->ifindex))
11040 goto free_msg;
11041
11042 if (wakeup) {
11043 struct nlattr *reasons;
11044
11045 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
11046
11047 if (wakeup->disconnect &&
11048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11049 goto free_msg;
11050 if (wakeup->magic_pkt &&
11051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11052 goto free_msg;
11053 if (wakeup->gtk_rekey_failure &&
11054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11055 goto free_msg;
11056 if (wakeup->eap_identity_req &&
11057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11058 goto free_msg;
11059 if (wakeup->four_way_handshake &&
11060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11061 goto free_msg;
11062 if (wakeup->rfkill_release &&
11063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11064 goto free_msg;
11065
11066 if (wakeup->pattern_idx >= 0 &&
11067 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11068 wakeup->pattern_idx))
11069 goto free_msg;
11070
Johannes Berg2a0e0472013-01-23 22:57:40 +010011071 if (wakeup->tcp_match)
11072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
11073
11074 if (wakeup->tcp_connlost)
11075 nla_put_flag(msg,
11076 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
11077
11078 if (wakeup->tcp_nomoretokens)
11079 nla_put_flag(msg,
11080 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
11081
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011082 if (wakeup->packet) {
11083 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11084 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11085
11086 if (!wakeup->packet_80211) {
11087 pkt_attr =
11088 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11089 len_attr =
11090 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11091 }
11092
11093 if (wakeup->packet_len &&
11094 nla_put_u32(msg, len_attr, wakeup->packet_len))
11095 goto free_msg;
11096
11097 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11098 wakeup->packet))
11099 goto free_msg;
11100 }
11101
11102 nla_nest_end(msg, reasons);
11103 }
11104
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011105 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011106
11107 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11108 nl80211_mlme_mcgrp.id, gfp);
11109 return;
11110
11111 free_msg:
11112 nlmsg_free(msg);
11113}
11114EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11115#endif
11116
Jouni Malinen3475b092012-11-16 22:49:57 +020011117void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11118 enum nl80211_tdls_operation oper,
11119 u16 reason_code, gfp_t gfp)
11120{
11121 struct wireless_dev *wdev = dev->ieee80211_ptr;
11122 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11123 struct sk_buff *msg;
11124 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011125
11126 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11127 reason_code);
11128
11129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11130 if (!msg)
11131 return;
11132
11133 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11134 if (!hdr) {
11135 nlmsg_free(msg);
11136 return;
11137 }
11138
11139 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11140 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11141 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11142 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11143 (reason_code > 0 &&
11144 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11145 goto nla_put_failure;
11146
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011147 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011148
11149 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11150 nl80211_mlme_mcgrp.id, gfp);
11151 return;
11152
11153 nla_put_failure:
11154 genlmsg_cancel(msg, hdr);
11155 nlmsg_free(msg);
11156}
11157EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11158
Jouni Malinen026331c2010-02-15 12:53:10 +020011159static int nl80211_netlink_notify(struct notifier_block * nb,
11160 unsigned long state,
11161 void *_notify)
11162{
11163 struct netlink_notify *notify = _notify;
11164 struct cfg80211_registered_device *rdev;
11165 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011166 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011167
11168 if (state != NETLINK_URELEASE)
11169 return NOTIFY_DONE;
11170
11171 rcu_read_lock();
11172
Johannes Berg5e7602302011-11-04 11:18:17 +010011173 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011174 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011175 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011176
11177 spin_lock_bh(&rdev->beacon_registrations_lock);
11178 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11179 list) {
11180 if (reg->nlportid == notify->portid) {
11181 list_del(&reg->list);
11182 kfree(reg);
11183 break;
11184 }
11185 }
11186 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011187 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011188
11189 rcu_read_unlock();
11190
11191 return NOTIFY_DONE;
11192}
11193
11194static struct notifier_block nl80211_netlink_notifier = {
11195 .notifier_call = nl80211_netlink_notify,
11196};
11197
Jouni Malinen355199e2013-02-27 17:14:27 +020011198void cfg80211_ft_event(struct net_device *netdev,
11199 struct cfg80211_ft_event_params *ft_event)
11200{
11201 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11202 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11203 struct sk_buff *msg;
11204 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011205
11206 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11207
11208 if (!ft_event->target_ap)
11209 return;
11210
11211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11212 if (!msg)
11213 return;
11214
11215 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11216 if (!hdr) {
11217 nlmsg_free(msg);
11218 return;
11219 }
11220
11221 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11222 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11223 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11224 if (ft_event->ies)
11225 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11226 if (ft_event->ric_ies)
11227 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11228 ft_event->ric_ies);
11229
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011230 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011231
11232 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11233 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11234}
11235EXPORT_SYMBOL(cfg80211_ft_event);
11236
Arend van Spriel5de17982013-04-18 15:49:00 +020011237void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11238{
11239 struct cfg80211_registered_device *rdev;
11240 struct sk_buff *msg;
11241 void *hdr;
11242 u32 nlportid;
11243
11244 rdev = wiphy_to_dev(wdev->wiphy);
11245 if (!rdev->crit_proto_nlportid)
11246 return;
11247
11248 nlportid = rdev->crit_proto_nlportid;
11249 rdev->crit_proto_nlportid = 0;
11250
11251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11252 if (!msg)
11253 return;
11254
11255 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11256 if (!hdr)
11257 goto nla_put_failure;
11258
11259 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11260 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11261 goto nla_put_failure;
11262
11263 genlmsg_end(msg, hdr);
11264
11265 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11266 return;
11267
11268 nla_put_failure:
11269 if (hdr)
11270 genlmsg_cancel(msg, hdr);
11271 nlmsg_free(msg);
11272
11273}
11274EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11275
Johannes Berg55682962007-09-20 13:09:35 -040011276/* initialisation/exit functions */
11277
11278int nl80211_init(void)
11279{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011280 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011281
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011282 err = genl_register_family_with_ops(&nl80211_fam,
11283 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011284 if (err)
11285 return err;
11286
Johannes Berg55682962007-09-20 13:09:35 -040011287 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11288 if (err)
11289 goto err_out;
11290
Johannes Berg2a519312009-02-10 21:25:55 +010011291 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11292 if (err)
11293 goto err_out;
11294
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011295 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11296 if (err)
11297 goto err_out;
11298
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011299 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11300 if (err)
11301 goto err_out;
11302
Johannes Bergaff89a92009-07-01 21:26:51 +020011303#ifdef CONFIG_NL80211_TESTMODE
11304 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11305 if (err)
11306 goto err_out;
11307#endif
11308
Jouni Malinen026331c2010-02-15 12:53:10 +020011309 err = netlink_register_notifier(&nl80211_netlink_notifier);
11310 if (err)
11311 goto err_out;
11312
Johannes Berg55682962007-09-20 13:09:35 -040011313 return 0;
11314 err_out:
11315 genl_unregister_family(&nl80211_fam);
11316 return err;
11317}
11318
11319void nl80211_exit(void)
11320{
Jouni Malinen026331c2010-02-15 12:53:10 +020011321 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011322 genl_unregister_family(&nl80211_fam);
11323}