blob: a044762f5ea3af305a68cd3c61fbbfbd3f31d7cf [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Johannes Berge5497d72011-07-05 16:35:40 +0200406/* policy for GTK rekey offload attributes */
407static const struct nla_policy
408nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
409 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
410 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
411 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
412};
413
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300414static const struct nla_policy
415nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300417 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300419};
420
Johannes Berg97990a02013-04-19 01:02:55 +0200421static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
422 struct netlink_callback *cb,
423 struct cfg80211_registered_device **rdev,
424 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100425{
Johannes Berg67748892010-10-04 21:14:06 +0200426 int err;
427
Johannes Berg67748892010-10-04 21:14:06 +0200428 rtnl_lock();
429
Johannes Berg97990a02013-04-19 01:02:55 +0200430 if (!cb->args[0]) {
431 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
432 nl80211_fam.attrbuf, nl80211_fam.maxattr,
433 nl80211_policy);
434 if (err)
435 goto out_unlock;
436
437 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
438 nl80211_fam.attrbuf);
439 if (IS_ERR(*wdev)) {
440 err = PTR_ERR(*wdev);
441 goto out_unlock;
442 }
443 *rdev = wiphy_to_dev((*wdev)->wiphy);
444 cb->args[0] = (*rdev)->wiphy_idx;
445 cb->args[1] = (*wdev)->identifier;
446 } else {
447 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
448 struct wireless_dev *tmp;
449
450 if (!wiphy) {
451 err = -ENODEV;
452 goto out_unlock;
453 }
454 *rdev = wiphy_to_dev(wiphy);
455 *wdev = NULL;
456
Johannes Berg97990a02013-04-19 01:02:55 +0200457 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
458 if (tmp->identifier == cb->args[1]) {
459 *wdev = tmp;
460 break;
461 }
462 }
Johannes Berg97990a02013-04-19 01:02:55 +0200463
464 if (!*wdev) {
465 err = -ENODEV;
466 goto out_unlock;
467 }
Johannes Berg67748892010-10-04 21:14:06 +0200468 }
469
Johannes Berg67748892010-10-04 21:14:06 +0200470 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200471 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200472 rtnl_unlock();
473 return err;
474}
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200477{
Johannes Berg67748892010-10-04 21:14:06 +0200478 rtnl_unlock();
479}
480
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100481/* IE validation */
482static bool is_valid_ie_attr(const struct nlattr *attr)
483{
484 const u8 *pos;
485 int len;
486
487 if (!attr)
488 return true;
489
490 pos = nla_data(attr);
491 len = nla_len(attr);
492
493 while (len) {
494 u8 elemlen;
495
496 if (len < 2)
497 return false;
498 len -= 2;
499
500 elemlen = pos[1];
501 if (elemlen > len)
502 return false;
503
504 len -= elemlen;
505 pos += 2 + elemlen;
506 }
507
508 return true;
509}
510
Johannes Berg55682962007-09-20 13:09:35 -0400511/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000512static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400513 int flags, u8 cmd)
514{
515 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000516 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400517}
518
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400519static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100520 struct ieee80211_channel *chan,
521 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400522{
David S. Miller9360ffd2012-03-29 04:41:26 -0400523 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
524 chan->center_freq))
525 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400526
David S. Miller9360ffd2012-03-29 04:41:26 -0400527 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
528 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
529 goto nla_put_failure;
530 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
531 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
532 goto nla_put_failure;
533 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
534 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
535 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100536 if (chan->flags & IEEE80211_CHAN_RADAR) {
537 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
538 goto nla_put_failure;
539 if (large) {
540 u32 time;
541
542 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
543
544 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
545 chan->dfs_state))
546 goto nla_put_failure;
547 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
548 time))
549 goto nla_put_failure;
550 }
551 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400552
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100553 if (large) {
554 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
555 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
556 goto nla_put_failure;
557 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
558 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
559 goto nla_put_failure;
560 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
561 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
562 goto nla_put_failure;
563 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
564 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
565 goto nla_put_failure;
566 }
567
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
569 DBM_TO_MBM(chan->max_power)))
570 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571
572 return 0;
573
574 nla_put_failure:
575 return -ENOBUFS;
576}
577
Johannes Berg55682962007-09-20 13:09:35 -0400578/* netlink command implementations */
579
Johannes Bergb9454e82009-07-08 13:29:08 +0200580struct key_parse {
581 struct key_params p;
582 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200583 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200584 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100585 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200586};
587
588static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
589{
590 struct nlattr *tb[NL80211_KEY_MAX + 1];
591 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
592 nl80211_key_policy);
593 if (err)
594 return err;
595
596 k->def = !!tb[NL80211_KEY_DEFAULT];
597 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
598
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100599 if (k->def) {
600 k->def_uni = true;
601 k->def_multi = true;
602 }
603 if (k->defmgmt)
604 k->def_multi = true;
605
Johannes Bergb9454e82009-07-08 13:29:08 +0200606 if (tb[NL80211_KEY_IDX])
607 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
608
609 if (tb[NL80211_KEY_DATA]) {
610 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
611 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
612 }
613
614 if (tb[NL80211_KEY_SEQ]) {
615 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
616 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
617 }
618
619 if (tb[NL80211_KEY_CIPHER])
620 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
621
Johannes Berge31b8212010-10-05 19:39:30 +0200622 if (tb[NL80211_KEY_TYPE]) {
623 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
624 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
625 return -EINVAL;
626 }
627
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100628 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
629 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100630 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
631 tb[NL80211_KEY_DEFAULT_TYPES],
632 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100633 if (err)
634 return err;
635
636 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
637 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
638 }
639
Johannes Bergb9454e82009-07-08 13:29:08 +0200640 return 0;
641}
642
643static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
644{
645 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
646 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
647 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
648 }
649
650 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
651 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
652 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
653 }
654
655 if (info->attrs[NL80211_ATTR_KEY_IDX])
656 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
657
658 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
659 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
660
661 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
662 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
663
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 if (k->def) {
665 k->def_uni = true;
666 k->def_multi = true;
667 }
668 if (k->defmgmt)
669 k->def_multi = true;
670
Johannes Berge31b8212010-10-05 19:39:30 +0200671 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
672 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
673 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
674 return -EINVAL;
675 }
676
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
678 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
679 int err = nla_parse_nested(
680 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
681 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
682 nl80211_key_default_policy);
683 if (err)
684 return err;
685
686 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
687 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
688 }
689
Johannes Bergb9454e82009-07-08 13:29:08 +0200690 return 0;
691}
692
693static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
694{
695 int err;
696
697 memset(k, 0, sizeof(*k));
698 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200699 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200700
701 if (info->attrs[NL80211_ATTR_KEY])
702 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
703 else
704 err = nl80211_parse_key_old(info, k);
705
706 if (err)
707 return err;
708
709 if (k->def && k->defmgmt)
710 return -EINVAL;
711
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (k->defmgmt) {
713 if (k->def_uni || !k->def_multi)
714 return -EINVAL;
715 }
716
Johannes Bergb9454e82009-07-08 13:29:08 +0200717 if (k->idx != -1) {
718 if (k->defmgmt) {
719 if (k->idx < 4 || k->idx > 5)
720 return -EINVAL;
721 } else if (k->def) {
722 if (k->idx < 0 || k->idx > 3)
723 return -EINVAL;
724 } else {
725 if (k->idx < 0 || k->idx > 5)
726 return -EINVAL;
727 }
728 }
729
730 return 0;
731}
732
Johannes Bergfffd0932009-07-08 14:22:54 +0200733static struct cfg80211_cached_keys *
734nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530735 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200736{
737 struct key_parse parse;
738 struct nlattr *key;
739 struct cfg80211_cached_keys *result;
740 int rem, err, def = 0;
741
742 result = kzalloc(sizeof(*result), GFP_KERNEL);
743 if (!result)
744 return ERR_PTR(-ENOMEM);
745
746 result->def = -1;
747 result->defmgmt = -1;
748
749 nla_for_each_nested(key, keys, rem) {
750 memset(&parse, 0, sizeof(parse));
751 parse.idx = -1;
752
753 err = nl80211_parse_key_new(key, &parse);
754 if (err)
755 goto error;
756 err = -EINVAL;
757 if (!parse.p.key)
758 goto error;
759 if (parse.idx < 0 || parse.idx > 4)
760 goto error;
761 if (parse.def) {
762 if (def)
763 goto error;
764 def = 1;
765 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100766 if (!parse.def_uni || !parse.def_multi)
767 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200768 } else if (parse.defmgmt)
769 goto error;
770 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200771 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200772 if (err)
773 goto error;
774 result->params[parse.idx].cipher = parse.p.cipher;
775 result->params[parse.idx].key_len = parse.p.key_len;
776 result->params[parse.idx].key = result->data[parse.idx];
777 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530778
779 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
780 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
781 if (no_ht)
782 *no_ht = true;
783 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200784 }
785
786 return result;
787 error:
788 kfree(result);
789 return ERR_PTR(err);
790}
791
792static int nl80211_key_allowed(struct wireless_dev *wdev)
793{
794 ASSERT_WDEV_LOCK(wdev);
795
Johannes Bergfffd0932009-07-08 14:22:54 +0200796 switch (wdev->iftype) {
797 case NL80211_IFTYPE_AP:
798 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200799 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700800 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200801 break;
802 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200803 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200804 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200805 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200806 return -ENOLINK;
807 break;
808 default:
809 return -EINVAL;
810 }
811
812 return 0;
813}
814
Johannes Berg7527a782011-05-13 10:58:57 +0200815static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
816{
817 struct nlattr *nl_modes = nla_nest_start(msg, attr);
818 int i;
819
820 if (!nl_modes)
821 goto nla_put_failure;
822
823 i = 0;
824 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400825 if ((ifmodes & 1) && nla_put_flag(msg, i))
826 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200827 ifmodes >>= 1;
828 i++;
829 }
830
831 nla_nest_end(msg, nl_modes);
832 return 0;
833
834nla_put_failure:
835 return -ENOBUFS;
836}
837
838static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100839 struct sk_buff *msg,
840 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200841{
842 struct nlattr *nl_combis;
843 int i, j;
844
845 nl_combis = nla_nest_start(msg,
846 NL80211_ATTR_INTERFACE_COMBINATIONS);
847 if (!nl_combis)
848 goto nla_put_failure;
849
850 for (i = 0; i < wiphy->n_iface_combinations; i++) {
851 const struct ieee80211_iface_combination *c;
852 struct nlattr *nl_combi, *nl_limits;
853
854 c = &wiphy->iface_combinations[i];
855
856 nl_combi = nla_nest_start(msg, i + 1);
857 if (!nl_combi)
858 goto nla_put_failure;
859
860 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
861 if (!nl_limits)
862 goto nla_put_failure;
863
864 for (j = 0; j < c->n_limits; j++) {
865 struct nlattr *nl_limit;
866
867 nl_limit = nla_nest_start(msg, j + 1);
868 if (!nl_limit)
869 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400870 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
871 c->limits[j].max))
872 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200873 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
874 c->limits[j].types))
875 goto nla_put_failure;
876 nla_nest_end(msg, nl_limit);
877 }
878
879 nla_nest_end(msg, nl_limits);
880
David S. Miller9360ffd2012-03-29 04:41:26 -0400881 if (c->beacon_int_infra_match &&
882 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
883 goto nla_put_failure;
884 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
885 c->num_different_channels) ||
886 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
887 c->max_interfaces))
888 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100889 if (large &&
890 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
891 c->radar_detect_widths))
892 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200893
894 nla_nest_end(msg, nl_combi);
895 }
896
897 nla_nest_end(msg, nl_combis);
898
899 return 0;
900nla_put_failure:
901 return -ENOBUFS;
902}
903
Johannes Berg3713b4e2013-02-14 16:19:38 +0100904#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100905static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
906 struct sk_buff *msg)
907{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200908 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100909 struct nlattr *nl_tcp;
910
911 if (!tcp)
912 return 0;
913
914 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
915 if (!nl_tcp)
916 return -ENOBUFS;
917
918 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
919 tcp->data_payload_max))
920 return -ENOBUFS;
921
922 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
923 tcp->data_payload_max))
924 return -ENOBUFS;
925
926 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
927 return -ENOBUFS;
928
929 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
930 sizeof(*tcp->tok), tcp->tok))
931 return -ENOBUFS;
932
933 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
934 tcp->data_interval_max))
935 return -ENOBUFS;
936
937 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
938 tcp->wake_payload_max))
939 return -ENOBUFS;
940
941 nla_nest_end(msg, nl_tcp);
942 return 0;
943}
944
Johannes Berg3713b4e2013-02-14 16:19:38 +0100945static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100946 struct cfg80211_registered_device *dev,
947 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100948{
949 struct nlattr *nl_wowlan;
950
Johannes Berg964dc9e2013-06-03 17:25:34 +0200951 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100952 return 0;
953
954 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
955 if (!nl_wowlan)
956 return -ENOBUFS;
957
Johannes Berg964dc9e2013-06-03 17:25:34 +0200958 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100959 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200960 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100961 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200962 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100963 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200964 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100965 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
974 return -ENOBUFS;
975
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700977 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 .max_patterns = dev->wiphy.wowlan->n_patterns,
979 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
980 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
981 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100982 };
983
984 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
985 sizeof(pat), &pat))
986 return -ENOBUFS;
987 }
988
Johannes Bergb56cf722013-02-20 01:02:38 +0100989 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
990 return -ENOBUFS;
991
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992 nla_nest_end(msg, nl_wowlan);
993
994 return 0;
995}
996#endif
997
998static int nl80211_send_band_rateinfo(struct sk_buff *msg,
999 struct ieee80211_supported_band *sband)
1000{
1001 struct nlattr *nl_rates, *nl_rate;
1002 struct ieee80211_rate *rate;
1003 int i;
1004
1005 /* add HT info */
1006 if (sband->ht_cap.ht_supported &&
1007 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1008 sizeof(sband->ht_cap.mcs),
1009 &sband->ht_cap.mcs) ||
1010 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1011 sband->ht_cap.cap) ||
1012 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1013 sband->ht_cap.ampdu_factor) ||
1014 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1015 sband->ht_cap.ampdu_density)))
1016 return -ENOBUFS;
1017
1018 /* add VHT info */
1019 if (sband->vht_cap.vht_supported &&
1020 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1021 sizeof(sband->vht_cap.vht_mcs),
1022 &sband->vht_cap.vht_mcs) ||
1023 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1024 sband->vht_cap.cap)))
1025 return -ENOBUFS;
1026
1027 /* add bitrates */
1028 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1029 if (!nl_rates)
1030 return -ENOBUFS;
1031
1032 for (i = 0; i < sband->n_bitrates; i++) {
1033 nl_rate = nla_nest_start(msg, i);
1034 if (!nl_rate)
1035 return -ENOBUFS;
1036
1037 rate = &sband->bitrates[i];
1038 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1039 rate->bitrate))
1040 return -ENOBUFS;
1041 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1042 nla_put_flag(msg,
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_rate);
1047 }
1048
1049 nla_nest_end(msg, nl_rates);
1050
1051 return 0;
1052}
1053
1054static int
1055nl80211_send_mgmt_stypes(struct sk_buff *msg,
1056 const struct ieee80211_txrx_stypes *mgmt_stypes)
1057{
1058 u16 stypes;
1059 struct nlattr *nl_ftypes, *nl_ifs;
1060 enum nl80211_iftype ift;
1061 int i;
1062
1063 if (!mgmt_stypes)
1064 return 0;
1065
1066 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1067 if (!nl_ifs)
1068 return -ENOBUFS;
1069
1070 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1071 nl_ftypes = nla_nest_start(msg, ift);
1072 if (!nl_ftypes)
1073 return -ENOBUFS;
1074 i = 0;
1075 stypes = mgmt_stypes[ift].tx;
1076 while (stypes) {
1077 if ((stypes & 1) &&
1078 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1079 (i << 4) | IEEE80211_FTYPE_MGMT))
1080 return -ENOBUFS;
1081 stypes >>= 1;
1082 i++;
1083 }
1084 nla_nest_end(msg, nl_ftypes);
1085 }
1086
1087 nla_nest_end(msg, nl_ifs);
1088
1089 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1090 if (!nl_ifs)
1091 return -ENOBUFS;
1092
1093 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1094 nl_ftypes = nla_nest_start(msg, ift);
1095 if (!nl_ftypes)
1096 return -ENOBUFS;
1097 i = 0;
1098 stypes = mgmt_stypes[ift].rx;
1099 while (stypes) {
1100 if ((stypes & 1) &&
1101 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1102 (i << 4) | IEEE80211_FTYPE_MGMT))
1103 return -ENOBUFS;
1104 stypes >>= 1;
1105 i++;
1106 }
1107 nla_nest_end(msg, nl_ftypes);
1108 }
1109 nla_nest_end(msg, nl_ifs);
1110
1111 return 0;
1112}
1113
Johannes Berg86e8cf92013-06-19 10:57:22 +02001114struct nl80211_dump_wiphy_state {
1115 s64 filter_wiphy;
1116 long start;
1117 long split_start, band_start, chan_start;
1118 bool split;
1119};
1120
Johannes Berg3713b4e2013-02-14 16:19:38 +01001121static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1122 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001123 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001124{
1125 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001126 struct nlattr *nl_bands, *nl_band;
1127 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001128 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001129 enum ieee80211_band band;
1130 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001131 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001132 const struct ieee80211_txrx_stypes *mgmt_stypes =
1133 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001134 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001135
Eric W. Biederman15e47302012-09-07 20:12:54 +00001136 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001137 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001138 return -ENOBUFS;
1139
Johannes Berg86e8cf92013-06-19 10:57:22 +02001140 if (WARN_ON(!state))
1141 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001142
David S. Miller9360ffd2012-03-29 04:41:26 -04001143 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001144 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1145 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001146 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001147 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001148 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001149
Johannes Berg86e8cf92013-06-19 10:57:22 +02001150 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001151 case 0:
1152 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1153 dev->wiphy.retry_short) ||
1154 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1155 dev->wiphy.retry_long) ||
1156 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1157 dev->wiphy.frag_threshold) ||
1158 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1159 dev->wiphy.rts_threshold) ||
1160 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1161 dev->wiphy.coverage_class) ||
1162 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1163 dev->wiphy.max_scan_ssids) ||
1164 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1165 dev->wiphy.max_sched_scan_ssids) ||
1166 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1167 dev->wiphy.max_scan_ie_len) ||
1168 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1169 dev->wiphy.max_sched_scan_ie_len) ||
1170 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1171 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001172 goto nla_put_failure;
1173
Johannes Berg3713b4e2013-02-14 16:19:38 +01001174 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1175 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1176 goto nla_put_failure;
1177 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1178 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1179 goto nla_put_failure;
1180 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1181 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1182 goto nla_put_failure;
1183 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1184 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1185 goto nla_put_failure;
1186 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1187 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1188 goto nla_put_failure;
1189 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1190 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001191 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001192 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1193 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1194 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001195
Johannes Berg86e8cf92013-06-19 10:57:22 +02001196 state->split_start++;
1197 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001198 break;
1199 case 1:
1200 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1201 sizeof(u32) * dev->wiphy.n_cipher_suites,
1202 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001203 goto nla_put_failure;
1204
Johannes Berg3713b4e2013-02-14 16:19:38 +01001205 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1206 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001207 goto nla_put_failure;
1208
Johannes Berg3713b4e2013-02-14 16:19:38 +01001209 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1210 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1211 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001212
Johannes Berg3713b4e2013-02-14 16:19:38 +01001213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1214 dev->wiphy.available_antennas_tx) ||
1215 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1216 dev->wiphy.available_antennas_rx))
1217 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001218
Johannes Berg3713b4e2013-02-14 16:19:38 +01001219 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1220 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1221 dev->wiphy.probe_resp_offload))
1222 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001223
Johannes Berg3713b4e2013-02-14 16:19:38 +01001224 if ((dev->wiphy.available_antennas_tx ||
1225 dev->wiphy.available_antennas_rx) &&
1226 dev->ops->get_antenna) {
1227 u32 tx_ant = 0, rx_ant = 0;
1228 int res;
1229 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1230 if (!res) {
1231 if (nla_put_u32(msg,
1232 NL80211_ATTR_WIPHY_ANTENNA_TX,
1233 tx_ant) ||
1234 nla_put_u32(msg,
1235 NL80211_ATTR_WIPHY_ANTENNA_RX,
1236 rx_ant))
1237 goto nla_put_failure;
1238 }
Johannes Bergee688b002008-01-24 19:38:39 +01001239 }
1240
Johannes Berg86e8cf92013-06-19 10:57:22 +02001241 state->split_start++;
1242 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001243 break;
1244 case 2:
1245 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1246 dev->wiphy.interface_modes))
1247 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001248 state->split_start++;
1249 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001250 break;
1251 case 3:
1252 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1253 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001254 goto nla_put_failure;
1255
Johannes Berg86e8cf92013-06-19 10:57:22 +02001256 for (band = state->band_start;
1257 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001258 struct ieee80211_supported_band *sband;
1259
1260 sband = dev->wiphy.bands[band];
1261
1262 if (!sband)
1263 continue;
1264
1265 nl_band = nla_nest_start(msg, band);
1266 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001267 goto nla_put_failure;
1268
Johannes Berg86e8cf92013-06-19 10:57:22 +02001269 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 case 0:
1271 if (nl80211_send_band_rateinfo(msg, sband))
1272 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001273 state->chan_start++;
1274 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 break;
1276 default:
1277 /* add frequencies */
1278 nl_freqs = nla_nest_start(
1279 msg, NL80211_BAND_ATTR_FREQS);
1280 if (!nl_freqs)
1281 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001282
Johannes Berg86e8cf92013-06-19 10:57:22 +02001283 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 i < sband->n_channels;
1285 i++) {
1286 nl_freq = nla_nest_start(msg, i);
1287 if (!nl_freq)
1288 goto nla_put_failure;
1289
1290 chan = &sband->channels[i];
1291
Johannes Berg86e8cf92013-06-19 10:57:22 +02001292 if (nl80211_msg_put_channel(
1293 msg, chan,
1294 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 goto nla_put_failure;
1296
1297 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001298 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 break;
1300 }
1301 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001302 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001304 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_nest_end(msg, nl_freqs);
1306 }
1307
1308 nla_nest_end(msg, nl_band);
1309
Johannes Berg86e8cf92013-06-19 10:57:22 +02001310 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001312 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 band--;
1314 break;
1315 }
Johannes Bergee688b002008-01-24 19:38:39 +01001316 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001318
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001320 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001322 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001323
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001325 if (state->band_start == 0 && state->chan_start == 0)
1326 state->split_start++;
1327 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 break;
1329 case 4:
1330 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1331 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001332 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333
1334 i = 0;
1335#define CMD(op, n) \
1336 do { \
1337 if (dev->ops->op) { \
1338 i++; \
1339 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1340 goto nla_put_failure; \
1341 } \
1342 } while (0)
1343
1344 CMD(add_virtual_intf, NEW_INTERFACE);
1345 CMD(change_virtual_intf, SET_INTERFACE);
1346 CMD(add_key, NEW_KEY);
1347 CMD(start_ap, START_AP);
1348 CMD(add_station, NEW_STATION);
1349 CMD(add_mpath, NEW_MPATH);
1350 CMD(update_mesh_config, SET_MESH_CONFIG);
1351 CMD(change_bss, SET_BSS);
1352 CMD(auth, AUTHENTICATE);
1353 CMD(assoc, ASSOCIATE);
1354 CMD(deauth, DEAUTHENTICATE);
1355 CMD(disassoc, DISASSOCIATE);
1356 CMD(join_ibss, JOIN_IBSS);
1357 CMD(join_mesh, JOIN_MESH);
1358 CMD(set_pmksa, SET_PMKSA);
1359 CMD(del_pmksa, DEL_PMKSA);
1360 CMD(flush_pmksa, FLUSH_PMKSA);
1361 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1362 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1363 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1364 CMD(mgmt_tx, FRAME);
1365 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1366 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1367 i++;
1368 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1369 goto nla_put_failure;
1370 }
1371 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1372 dev->ops->join_mesh) {
1373 i++;
1374 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1375 goto nla_put_failure;
1376 }
1377 CMD(set_wds_peer, SET_WDS_PEER);
1378 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1379 CMD(tdls_mgmt, TDLS_MGMT);
1380 CMD(tdls_oper, TDLS_OPER);
1381 }
1382 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1383 CMD(sched_scan_start, START_SCHED_SCAN);
1384 CMD(probe_client, PROBE_CLIENT);
1385 CMD(set_noack_map, SET_NOACK_MAP);
1386 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1387 i++;
1388 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1389 goto nla_put_failure;
1390 }
1391 CMD(start_p2p_device, START_P2P_DEVICE);
1392 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001393 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001394 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1395 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1396 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001397
Kalle Valo4745fc02011-11-17 19:06:10 +02001398#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001400#endif
1401
Johannes Berg8fdc6212009-03-14 09:34:01 +01001402#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001403
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 if (dev->ops->connect || dev->ops->auth) {
1405 i++;
1406 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001407 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001408 }
1409
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 if (dev->ops->disconnect || dev->ops->deauth) {
1411 i++;
1412 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1413 goto nla_put_failure;
1414 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001415
Johannes Berg3713b4e2013-02-14 16:19:38 +01001416 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 state->split_start++;
1418 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 break;
1420 case 5:
1421 if (dev->ops->remain_on_channel &&
1422 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1423 nla_put_u32(msg,
1424 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1425 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001426 goto nla_put_failure;
1427
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1429 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1430 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001431
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1433 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001434 state->split_start++;
1435 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 break;
1437 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001438#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001439 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001441 state->split_start++;
1442 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 break;
1444#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001445 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446#endif
1447 case 7:
1448 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1449 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001450 goto nla_put_failure;
1451
Johannes Berg86e8cf92013-06-19 10:57:22 +02001452 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1453 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001455
Johannes Berg86e8cf92013-06-19 10:57:22 +02001456 state->split_start++;
1457 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 break;
1459 case 8:
1460 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1461 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1462 dev->wiphy.ap_sme_capa))
1463 goto nla_put_failure;
1464
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001465 features = dev->wiphy.features;
1466 /*
1467 * We can only add the per-channel limit information if the
1468 * dump is split, otherwise it makes it too big. Therefore
1469 * only advertise it in that case.
1470 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001471 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001472 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1473 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001474 goto nla_put_failure;
1475
1476 if (dev->wiphy.ht_capa_mod_mask &&
1477 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1478 sizeof(*dev->wiphy.ht_capa_mod_mask),
1479 dev->wiphy.ht_capa_mod_mask))
1480 goto nla_put_failure;
1481
1482 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1483 dev->wiphy.max_acl_mac_addrs &&
1484 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1485 dev->wiphy.max_acl_mac_addrs))
1486 goto nla_put_failure;
1487
1488 /*
1489 * Any information below this point is only available to
1490 * applications that can deal with it being split. This
1491 * helps ensure that newly added capabilities don't break
1492 * older tools by overrunning their buffers.
1493 *
1494 * We still increment split_start so that in the split
1495 * case we'll continue with more data in the next round,
1496 * but break unconditionally so unsplit data stops here.
1497 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001498 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 break;
1500 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001501 if (dev->wiphy.extended_capabilities &&
1502 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1503 dev->wiphy.extended_capabilities_len,
1504 dev->wiphy.extended_capabilities) ||
1505 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1506 dev->wiphy.extended_capabilities_len,
1507 dev->wiphy.extended_capabilities_mask)))
1508 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509
Johannes Bergee2aca32013-02-21 17:36:01 +01001510 if (dev->wiphy.vht_capa_mod_mask &&
1511 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1512 sizeof(*dev->wiphy.vht_capa_mod_mask),
1513 dev->wiphy.vht_capa_mod_mask))
1514 goto nla_put_failure;
1515
Johannes Berg3713b4e2013-02-14 16:19:38 +01001516 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001519 }
Johannes Berg55682962007-09-20 13:09:35 -04001520 return genlmsg_end(msg, hdr);
1521
1522 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001523 genlmsg_cancel(msg, hdr);
1524 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001525}
1526
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1528 struct netlink_callback *cb,
1529 struct nl80211_dump_wiphy_state *state)
1530{
1531 struct nlattr **tb = nl80211_fam.attrbuf;
1532 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1533 tb, nl80211_fam.maxattr, nl80211_policy);
1534 /* ignore parse errors for backward compatibility */
1535 if (ret)
1536 return 0;
1537
1538 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1539 if (tb[NL80211_ATTR_WIPHY])
1540 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1541 if (tb[NL80211_ATTR_WDEV])
1542 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1543 if (tb[NL80211_ATTR_IFINDEX]) {
1544 struct net_device *netdev;
1545 struct cfg80211_registered_device *rdev;
1546 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1547
1548 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1549 if (!netdev)
1550 return -ENODEV;
1551 if (netdev->ieee80211_ptr) {
1552 rdev = wiphy_to_dev(
1553 netdev->ieee80211_ptr->wiphy);
1554 state->filter_wiphy = rdev->wiphy_idx;
1555 }
1556 dev_put(netdev);
1557 }
1558
1559 return 0;
1560}
1561
Johannes Berg55682962007-09-20 13:09:35 -04001562static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1563{
Johannes Berg645e77d2013-03-01 14:03:49 +01001564 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001565 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001566 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001567
Johannes Berg5fe231e2013-05-08 21:45:15 +02001568 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001569 if (!state) {
1570 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001571 if (!state) {
1572 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001573 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001575 state->filter_wiphy = -1;
1576 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1577 if (ret) {
1578 kfree(state);
1579 rtnl_unlock();
1580 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001582 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 }
1584
Johannes Berg79c97e92009-07-07 03:56:12 +02001585 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001586 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1587 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001588 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001589 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001590 if (state->filter_wiphy != -1 &&
1591 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 continue;
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1594 do {
1595 ret = nl80211_send_wiphy(dev, skb,
1596 NETLINK_CB(cb->skb).portid,
1597 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001598 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 if (ret < 0) {
1600 /*
1601 * If sending the wiphy data didn't fit (ENOBUFS
1602 * or EMSGSIZE returned), this SKB is still
1603 * empty (so it's not too big because another
1604 * wiphy dataset is already in the skb) and
1605 * we've not tried to adjust the dump allocation
1606 * yet ... then adjust the alloc size to be
1607 * bigger, and return 1 but with the empty skb.
1608 * This results in an empty message being RX'ed
1609 * in userspace, but that is ignored.
1610 *
1611 * We can then retry with the larger buffer.
1612 */
1613 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1614 !skb->len &&
1615 cb->min_dump_alloc < 4096) {
1616 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001617 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 return 1;
1619 }
1620 idx--;
1621 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001622 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 break;
Johannes Berg55682962007-09-20 13:09:35 -04001625 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001626 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001627
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001629
1630 return skb->len;
1631}
1632
Johannes Berg86e8cf92013-06-19 10:57:22 +02001633static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1634{
1635 kfree((void *)cb->args[0]);
1636 return 0;
1637}
1638
Johannes Berg55682962007-09-20 13:09:35 -04001639static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1640{
1641 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001642 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001643 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001644
Johannes Berg645e77d2013-03-01 14:03:49 +01001645 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001646 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001647 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001648
Johannes Berg3713b4e2013-02-14 16:19:38 +01001649 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001650 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001651 nlmsg_free(msg);
1652 return -ENOBUFS;
1653 }
Johannes Berg55682962007-09-20 13:09:35 -04001654
Johannes Berg134e6372009-07-10 09:51:34 +00001655 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001656}
1657
Jouni Malinen31888482008-10-30 16:59:24 +02001658static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1659 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1660 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1661 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1662 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1663 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1664};
1665
1666static int parse_txq_params(struct nlattr *tb[],
1667 struct ieee80211_txq_params *txq_params)
1668{
Johannes Berga3304b02012-03-28 11:04:24 +02001669 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001670 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1671 !tb[NL80211_TXQ_ATTR_AIFS])
1672 return -EINVAL;
1673
Johannes Berga3304b02012-03-28 11:04:24 +02001674 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001675 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1676 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1677 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1678 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1679
Johannes Berga3304b02012-03-28 11:04:24 +02001680 if (txq_params->ac >= NL80211_NUM_ACS)
1681 return -EINVAL;
1682
Jouni Malinen31888482008-10-30 16:59:24 +02001683 return 0;
1684}
1685
Johannes Bergf444de02010-05-05 15:25:02 +02001686static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1687{
1688 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001689 * You can only set the channel explicitly for WDS interfaces,
1690 * all others have their channel managed via their respective
1691 * "establish a connection" command (connect, join, ...)
1692 *
1693 * For AP/GO and mesh mode, the channel can be set with the
1694 * channel userspace API, but is only stored and passed to the
1695 * low-level driver when the AP starts or the mesh is joined.
1696 * This is for backward compatibility, userspace can also give
1697 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001698 *
1699 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001700 * whatever else is going on, so they have their own special
1701 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001702 */
1703 return !wdev ||
1704 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001705 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001706 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1707 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001708}
1709
Johannes Berg683b6d32012-11-08 21:25:48 +01001710static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1711 struct genl_info *info,
1712 struct cfg80211_chan_def *chandef)
1713{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301714 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001715
1716 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1717 return -EINVAL;
1718
1719 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1720
1721 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001722 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1723 chandef->center_freq1 = control_freq;
1724 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001725
1726 /* Primary channel not allowed */
1727 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1728 return -EINVAL;
1729
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001730 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1731 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001732
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001733 chantype = nla_get_u32(
1734 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1735
1736 switch (chantype) {
1737 case NL80211_CHAN_NO_HT:
1738 case NL80211_CHAN_HT20:
1739 case NL80211_CHAN_HT40PLUS:
1740 case NL80211_CHAN_HT40MINUS:
1741 cfg80211_chandef_create(chandef, chandef->chan,
1742 chantype);
1743 break;
1744 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001745 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001746 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001747 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1748 chandef->width =
1749 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1750 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1751 chandef->center_freq1 =
1752 nla_get_u32(
1753 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1754 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1755 chandef->center_freq2 =
1756 nla_get_u32(
1757 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1758 }
1759
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001760 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001761 return -EINVAL;
1762
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001763 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1764 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001765 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001766
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001767 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1768 chandef->width == NL80211_CHAN_WIDTH_10) &&
1769 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1770 return -EINVAL;
1771
Johannes Berg683b6d32012-11-08 21:25:48 +01001772 return 0;
1773}
1774
Johannes Bergf444de02010-05-05 15:25:02 +02001775static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1776 struct wireless_dev *wdev,
1777 struct genl_info *info)
1778{
Johannes Berg683b6d32012-11-08 21:25:48 +01001779 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001780 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001781 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1782
1783 if (wdev)
1784 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001785
Johannes Bergf444de02010-05-05 15:25:02 +02001786 if (!nl80211_can_set_dev_channel(wdev))
1787 return -EOPNOTSUPP;
1788
Johannes Berg683b6d32012-11-08 21:25:48 +01001789 result = nl80211_parse_chandef(rdev, info, &chandef);
1790 if (result)
1791 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001792
Johannes Berge8c9bd52012-06-06 08:18:22 +02001793 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001794 case NL80211_IFTYPE_AP:
1795 case NL80211_IFTYPE_P2P_GO:
1796 if (wdev->beacon_interval) {
1797 result = -EBUSY;
1798 break;
1799 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001800 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001801 result = -EINVAL;
1802 break;
1803 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001804 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001805 result = 0;
1806 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001807 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001808 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001809 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001810 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001811 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001812 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001813 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001814 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001815 }
Johannes Bergf444de02010-05-05 15:25:02 +02001816
1817 return result;
1818}
1819
1820static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1821{
Johannes Berg4c476992010-10-04 21:36:35 +02001822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1823 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001824
Johannes Berg4c476992010-10-04 21:36:35 +02001825 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001826}
1827
Bill Jordane8347eb2010-10-01 13:54:28 -04001828static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1829{
Johannes Berg43b19952010-10-07 13:10:30 +02001830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1831 struct net_device *dev = info->user_ptr[1];
1832 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001833 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001834
1835 if (!info->attrs[NL80211_ATTR_MAC])
1836 return -EINVAL;
1837
Johannes Berg43b19952010-10-07 13:10:30 +02001838 if (netif_running(dev))
1839 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001840
Johannes Berg43b19952010-10-07 13:10:30 +02001841 if (!rdev->ops->set_wds_peer)
1842 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001843
Johannes Berg43b19952010-10-07 13:10:30 +02001844 if (wdev->iftype != NL80211_IFTYPE_WDS)
1845 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001846
1847 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001848 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001849}
1850
1851
Johannes Berg55682962007-09-20 13:09:35 -04001852static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1853{
1854 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001855 struct net_device *netdev = NULL;
1856 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001857 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001858 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001859 u32 changed;
1860 u8 retry_short = 0, retry_long = 0;
1861 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001862 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001863
Johannes Berg5fe231e2013-05-08 21:45:15 +02001864 ASSERT_RTNL();
1865
Johannes Bergf444de02010-05-05 15:25:02 +02001866 /*
1867 * Try to find the wiphy and netdev. Normally this
1868 * function shouldn't need the netdev, but this is
1869 * done for backward compatibility -- previously
1870 * setting the channel was done per wiphy, but now
1871 * it is per netdev. Previous userland like hostapd
1872 * also passed a netdev to set_wiphy, so that it is
1873 * possible to let that go to the right netdev!
1874 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001875
Johannes Bergf444de02010-05-05 15:25:02 +02001876 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1877 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1878
1879 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001880 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001881 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001882 else
Johannes Bergf444de02010-05-05 15:25:02 +02001883 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001884 }
1885
Johannes Bergf444de02010-05-05 15:25:02 +02001886 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001887 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1888 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001889 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001890 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001891 wdev = NULL;
1892 netdev = NULL;
1893 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001894 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001895 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001896
1897 /*
1898 * end workaround code, by now the rdev is available
1899 * and locked, and wdev may or may not be NULL.
1900 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001901
1902 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001903 result = cfg80211_dev_rename(
1904 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001905
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001906 if (result)
1907 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001908
Jouni Malinen31888482008-10-30 16:59:24 +02001909 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1910 struct ieee80211_txq_params txq_params;
1911 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1912
1913 if (!rdev->ops->set_txq_params) {
1914 result = -EOPNOTSUPP;
1915 goto bad_res;
1916 }
1917
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001918 if (!netdev) {
1919 result = -EINVAL;
1920 goto bad_res;
1921 }
1922
Johannes Berg133a3ff2011-11-03 14:50:13 +01001923 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1924 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1925 result = -EINVAL;
1926 goto bad_res;
1927 }
1928
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001929 if (!netif_running(netdev)) {
1930 result = -ENETDOWN;
1931 goto bad_res;
1932 }
1933
Jouni Malinen31888482008-10-30 16:59:24 +02001934 nla_for_each_nested(nl_txq_params,
1935 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1936 rem_txq_params) {
1937 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1938 nla_data(nl_txq_params),
1939 nla_len(nl_txq_params),
1940 txq_params_policy);
1941 result = parse_txq_params(tb, &txq_params);
1942 if (result)
1943 goto bad_res;
1944
Hila Gonene35e4d22012-06-27 17:19:42 +03001945 result = rdev_set_txq_params(rdev, netdev,
1946 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001947 if (result)
1948 goto bad_res;
1949 }
1950 }
1951
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001952 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001953 result = __nl80211_set_channel(rdev,
1954 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1955 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001956 if (result)
1957 goto bad_res;
1958 }
1959
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001960 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001961 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001962 enum nl80211_tx_power_setting type;
1963 int idx, mbm = 0;
1964
Johannes Bergc8442112012-10-24 10:17:18 +02001965 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
1966 txp_wdev = NULL;
1967
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001968 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02001969 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001970 goto bad_res;
1971 }
1972
1973 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
1974 type = nla_get_u32(info->attrs[idx]);
1975
1976 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
1977 (type != NL80211_TX_POWER_AUTOMATIC)) {
1978 result = -EINVAL;
1979 goto bad_res;
1980 }
1981
1982 if (type != NL80211_TX_POWER_AUTOMATIC) {
1983 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
1984 mbm = nla_get_u32(info->attrs[idx]);
1985 }
1986
Johannes Bergc8442112012-10-24 10:17:18 +02001987 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001988 if (result)
1989 goto bad_res;
1990 }
1991
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001992 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
1993 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
1994 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09001995 if ((!rdev->wiphy.available_antennas_tx &&
1996 !rdev->wiphy.available_antennas_rx) ||
1997 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09001998 result = -EOPNOTSUPP;
1999 goto bad_res;
2000 }
2001
2002 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2003 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2004
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002005 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002006 * available antenna masks, except for the "all" mask */
2007 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2008 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002009 result = -EINVAL;
2010 goto bad_res;
2011 }
2012
Bruno Randolf7f531e02010-12-16 11:30:22 +09002013 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2014 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002015
Hila Gonene35e4d22012-06-27 17:19:42 +03002016 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002017 if (result)
2018 goto bad_res;
2019 }
2020
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002021 changed = 0;
2022
2023 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2024 retry_short = nla_get_u8(
2025 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2026 if (retry_short == 0) {
2027 result = -EINVAL;
2028 goto bad_res;
2029 }
2030 changed |= WIPHY_PARAM_RETRY_SHORT;
2031 }
2032
2033 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2034 retry_long = nla_get_u8(
2035 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2036 if (retry_long == 0) {
2037 result = -EINVAL;
2038 goto bad_res;
2039 }
2040 changed |= WIPHY_PARAM_RETRY_LONG;
2041 }
2042
2043 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2044 frag_threshold = nla_get_u32(
2045 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2046 if (frag_threshold < 256) {
2047 result = -EINVAL;
2048 goto bad_res;
2049 }
2050 if (frag_threshold != (u32) -1) {
2051 /*
2052 * Fragments (apart from the last one) are required to
2053 * have even length. Make the fragmentation code
2054 * simpler by stripping LSB should someone try to use
2055 * odd threshold value.
2056 */
2057 frag_threshold &= ~0x1;
2058 }
2059 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2060 }
2061
2062 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2063 rts_threshold = nla_get_u32(
2064 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2065 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2066 }
2067
Lukáš Turek81077e82009-12-21 22:50:47 +01002068 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2069 coverage_class = nla_get_u8(
2070 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2071 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2072 }
2073
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002074 if (changed) {
2075 u8 old_retry_short, old_retry_long;
2076 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002077 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002078
2079 if (!rdev->ops->set_wiphy_params) {
2080 result = -EOPNOTSUPP;
2081 goto bad_res;
2082 }
2083
2084 old_retry_short = rdev->wiphy.retry_short;
2085 old_retry_long = rdev->wiphy.retry_long;
2086 old_frag_threshold = rdev->wiphy.frag_threshold;
2087 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002088 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002089
2090 if (changed & WIPHY_PARAM_RETRY_SHORT)
2091 rdev->wiphy.retry_short = retry_short;
2092 if (changed & WIPHY_PARAM_RETRY_LONG)
2093 rdev->wiphy.retry_long = retry_long;
2094 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2095 rdev->wiphy.frag_threshold = frag_threshold;
2096 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2097 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002098 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2099 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002100
Hila Gonene35e4d22012-06-27 17:19:42 +03002101 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002102 if (result) {
2103 rdev->wiphy.retry_short = old_retry_short;
2104 rdev->wiphy.retry_long = old_retry_long;
2105 rdev->wiphy.frag_threshold = old_frag_threshold;
2106 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002107 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002108 }
2109 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002110
Johannes Berg306d6112008-12-08 12:39:04 +01002111 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002112 if (netdev)
2113 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002114 return result;
2115}
2116
Johannes Berg71bbc992012-06-15 15:30:18 +02002117static inline u64 wdev_id(struct wireless_dev *wdev)
2118{
2119 return (u64)wdev->identifier |
2120 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2121}
Johannes Berg55682962007-09-20 13:09:35 -04002122
Johannes Berg683b6d32012-11-08 21:25:48 +01002123static int nl80211_send_chandef(struct sk_buff *msg,
2124 struct cfg80211_chan_def *chandef)
2125{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002126 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002127
Johannes Berg683b6d32012-11-08 21:25:48 +01002128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2129 chandef->chan->center_freq))
2130 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002131 switch (chandef->width) {
2132 case NL80211_CHAN_WIDTH_20_NOHT:
2133 case NL80211_CHAN_WIDTH_20:
2134 case NL80211_CHAN_WIDTH_40:
2135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2136 cfg80211_get_chandef_type(chandef)))
2137 return -ENOBUFS;
2138 break;
2139 default:
2140 break;
2141 }
2142 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2143 return -ENOBUFS;
2144 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2145 return -ENOBUFS;
2146 if (chandef->center_freq2 &&
2147 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002148 return -ENOBUFS;
2149 return 0;
2150}
2151
Eric W. Biederman15e47302012-09-07 20:12:54 +00002152static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002153 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002154 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002155{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002156 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002157 void *hdr;
2158
Eric W. Biederman15e47302012-09-07 20:12:54 +00002159 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002160 if (!hdr)
2161 return -1;
2162
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002163 if (dev &&
2164 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002165 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002166 goto nla_put_failure;
2167
2168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2169 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002170 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002172 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2173 rdev->devlist_generation ^
2174 (cfg80211_rdev_list_generation << 2)))
2175 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002176
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002177 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002178 int ret;
2179 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002180
Johannes Berg683b6d32012-11-08 21:25:48 +01002181 ret = rdev_get_channel(rdev, wdev, &chandef);
2182 if (ret == 0) {
2183 if (nl80211_send_chandef(msg, &chandef))
2184 goto nla_put_failure;
2185 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002186 }
2187
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002188 if (wdev->ssid_len) {
2189 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2190 goto nla_put_failure;
2191 }
2192
Johannes Berg55682962007-09-20 13:09:35 -04002193 return genlmsg_end(msg, hdr);
2194
2195 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002196 genlmsg_cancel(msg, hdr);
2197 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002198}
2199
2200static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2201{
2202 int wp_idx = 0;
2203 int if_idx = 0;
2204 int wp_start = cb->args[0];
2205 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002206 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002207 struct wireless_dev *wdev;
2208
Johannes Berg5fe231e2013-05-08 21:45:15 +02002209 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002210 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2211 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002212 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002213 if (wp_idx < wp_start) {
2214 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002215 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002216 }
Johannes Berg55682962007-09-20 13:09:35 -04002217 if_idx = 0;
2218
Johannes Berg89a54e42012-06-15 14:33:17 +02002219 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002220 if (if_idx < if_start) {
2221 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002222 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002223 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002224 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002225 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002226 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002227 goto out;
2228 }
2229 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002230 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002231
2232 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002233 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002234 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002235 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002236
2237 cb->args[0] = wp_idx;
2238 cb->args[1] = if_idx;
2239
2240 return skb->len;
2241}
2242
2243static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2244{
2245 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002246 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002247 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002248
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002250 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002251 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002252
Eric W. Biederman15e47302012-09-07 20:12:54 +00002253 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002254 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002255 nlmsg_free(msg);
2256 return -ENOBUFS;
2257 }
Johannes Berg55682962007-09-20 13:09:35 -04002258
Johannes Berg134e6372009-07-10 09:51:34 +00002259 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002260}
2261
Michael Wu66f7ac52008-01-31 19:48:22 +01002262static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2263 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2264 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2265 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2266 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2267 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002268 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002269};
2270
2271static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2272{
2273 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2274 int flag;
2275
2276 *mntrflags = 0;
2277
2278 if (!nla)
2279 return -EINVAL;
2280
2281 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2282 nla, mntr_flags_policy))
2283 return -EINVAL;
2284
2285 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2286 if (flags[flag])
2287 *mntrflags |= (1<<flag);
2288
2289 return 0;
2290}
2291
Johannes Berg9bc383d2009-11-19 11:55:19 +01002292static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002293 struct net_device *netdev, u8 use_4addr,
2294 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002295{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002296 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002297 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002298 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002299 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002300 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002301
2302 switch (iftype) {
2303 case NL80211_IFTYPE_AP_VLAN:
2304 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2305 return 0;
2306 break;
2307 case NL80211_IFTYPE_STATION:
2308 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2309 return 0;
2310 break;
2311 default:
2312 break;
2313 }
2314
2315 return -EOPNOTSUPP;
2316}
2317
Johannes Berg55682962007-09-20 13:09:35 -04002318static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2319{
Johannes Berg4c476992010-10-04 21:36:35 +02002320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002321 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002322 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002323 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002324 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002325 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002326 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002327
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002328 memset(&params, 0, sizeof(params));
2329
Johannes Berg04a773a2009-04-19 21:24:32 +02002330 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002331
Johannes Berg723b0382008-09-16 20:22:09 +02002332 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002333 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002334 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002335 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002336 if (ntype > NL80211_IFTYPE_MAX)
2337 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002338 }
2339
Johannes Berg92ffe052008-09-16 20:39:36 +02002340 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002341 struct wireless_dev *wdev = dev->ieee80211_ptr;
2342
Johannes Berg4c476992010-10-04 21:36:35 +02002343 if (ntype != NL80211_IFTYPE_MESH_POINT)
2344 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002345 if (netif_running(dev))
2346 return -EBUSY;
2347
2348 wdev_lock(wdev);
2349 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2350 IEEE80211_MAX_MESH_ID_LEN);
2351 wdev->mesh_id_up_len =
2352 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2353 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2354 wdev->mesh_id_up_len);
2355 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002356 }
2357
Felix Fietkau8b787642009-11-10 18:53:10 +01002358 if (info->attrs[NL80211_ATTR_4ADDR]) {
2359 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2360 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002361 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002362 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002363 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002364 } else {
2365 params.use_4addr = -1;
2366 }
2367
Johannes Berg92ffe052008-09-16 20:39:36 +02002368 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002369 if (ntype != NL80211_IFTYPE_MONITOR)
2370 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002371 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2372 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002373 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002374 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002375
2376 flags = &_flags;
2377 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002378 }
Johannes Berg3b858752009-03-12 09:55:09 +01002379
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002380 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2381 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2382 return -EOPNOTSUPP;
2383
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002384 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002385 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002386 else
2387 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002388
Johannes Berg9bc383d2009-11-19 11:55:19 +01002389 if (!err && params.use_4addr != -1)
2390 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2391
Johannes Berg55682962007-09-20 13:09:35 -04002392 return err;
2393}
2394
2395static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2396{
Johannes Berg4c476992010-10-04 21:36:35 +02002397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002398 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002399 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002400 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002401 int err;
2402 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002403 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002404
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002405 memset(&params, 0, sizeof(params));
2406
Johannes Berg55682962007-09-20 13:09:35 -04002407 if (!info->attrs[NL80211_ATTR_IFNAME])
2408 return -EINVAL;
2409
2410 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2411 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2412 if (type > NL80211_IFTYPE_MAX)
2413 return -EINVAL;
2414 }
2415
Johannes Berg79c97e92009-07-07 03:56:12 +02002416 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002417 !(rdev->wiphy.interface_modes & (1 << type)))
2418 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002419
Arend van Spriel1c18f142013-01-08 10:17:27 +01002420 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2421 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2422 ETH_ALEN);
2423 if (!is_valid_ether_addr(params.macaddr))
2424 return -EADDRNOTAVAIL;
2425 }
2426
Johannes Berg9bc383d2009-11-19 11:55:19 +01002427 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002428 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002429 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002430 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002431 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002432 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002433
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002434 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2435 if (!msg)
2436 return -ENOMEM;
2437
Michael Wu66f7ac52008-01-31 19:48:22 +01002438 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2439 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2440 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002441
2442 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2443 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2444 return -EOPNOTSUPP;
2445
Hila Gonene35e4d22012-06-27 17:19:42 +03002446 wdev = rdev_add_virtual_intf(rdev,
2447 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2448 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002449 if (IS_ERR(wdev)) {
2450 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002451 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002452 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002453
Johannes Berg98104fde2012-06-16 00:19:54 +02002454 switch (type) {
2455 case NL80211_IFTYPE_MESH_POINT:
2456 if (!info->attrs[NL80211_ATTR_MESH_ID])
2457 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002458 wdev_lock(wdev);
2459 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2460 IEEE80211_MAX_MESH_ID_LEN);
2461 wdev->mesh_id_up_len =
2462 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2463 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2464 wdev->mesh_id_up_len);
2465 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002466 break;
2467 case NL80211_IFTYPE_P2P_DEVICE:
2468 /*
2469 * P2P Device doesn't have a netdev, so doesn't go
2470 * through the netdev notifier and must be added here
2471 */
2472 mutex_init(&wdev->mtx);
2473 INIT_LIST_HEAD(&wdev->event_list);
2474 spin_lock_init(&wdev->event_lock);
2475 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2476 spin_lock_init(&wdev->mgmt_registrations_lock);
2477
Johannes Berg98104fde2012-06-16 00:19:54 +02002478 wdev->identifier = ++rdev->wdev_id;
2479 list_add_rcu(&wdev->list, &rdev->wdev_list);
2480 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002481 break;
2482 default:
2483 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002484 }
2485
Eric W. Biederman15e47302012-09-07 20:12:54 +00002486 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002487 rdev, wdev) < 0) {
2488 nlmsg_free(msg);
2489 return -ENOBUFS;
2490 }
2491
2492 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002493}
2494
2495static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2496{
Johannes Berg4c476992010-10-04 21:36:35 +02002497 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002498 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002499
Johannes Berg4c476992010-10-04 21:36:35 +02002500 if (!rdev->ops->del_virtual_intf)
2501 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002502
Johannes Berg84efbb82012-06-16 00:00:26 +02002503 /*
2504 * If we remove a wireless device without a netdev then clear
2505 * user_ptr[1] so that nl80211_post_doit won't dereference it
2506 * to check if it needs to do dev_put(). Otherwise it crashes
2507 * since the wdev has been freed, unlike with a netdev where
2508 * we need the dev_put() for the netdev to really be freed.
2509 */
2510 if (!wdev->netdev)
2511 info->user_ptr[1] = NULL;
2512
Hila Gonene35e4d22012-06-27 17:19:42 +03002513 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002514}
2515
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002516static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2517{
2518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2519 struct net_device *dev = info->user_ptr[1];
2520 u16 noack_map;
2521
2522 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2523 return -EINVAL;
2524
2525 if (!rdev->ops->set_noack_map)
2526 return -EOPNOTSUPP;
2527
2528 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2529
Hila Gonene35e4d22012-06-27 17:19:42 +03002530 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002531}
2532
Johannes Berg41ade002007-12-19 02:03:29 +01002533struct get_key_cookie {
2534 struct sk_buff *msg;
2535 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002536 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002537};
2538
2539static void get_key_callback(void *c, struct key_params *params)
2540{
Johannes Bergb9454e82009-07-08 13:29:08 +02002541 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002542 struct get_key_cookie *cookie = c;
2543
David S. Miller9360ffd2012-03-29 04:41:26 -04002544 if ((params->key &&
2545 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2546 params->key_len, params->key)) ||
2547 (params->seq &&
2548 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2549 params->seq_len, params->seq)) ||
2550 (params->cipher &&
2551 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2552 params->cipher)))
2553 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002554
Johannes Bergb9454e82009-07-08 13:29:08 +02002555 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2556 if (!key)
2557 goto nla_put_failure;
2558
David S. Miller9360ffd2012-03-29 04:41:26 -04002559 if ((params->key &&
2560 nla_put(cookie->msg, NL80211_KEY_DATA,
2561 params->key_len, params->key)) ||
2562 (params->seq &&
2563 nla_put(cookie->msg, NL80211_KEY_SEQ,
2564 params->seq_len, params->seq)) ||
2565 (params->cipher &&
2566 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2567 params->cipher)))
2568 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002569
David S. Miller9360ffd2012-03-29 04:41:26 -04002570 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2571 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002572
2573 nla_nest_end(cookie->msg, key);
2574
Johannes Berg41ade002007-12-19 02:03:29 +01002575 return;
2576 nla_put_failure:
2577 cookie->error = 1;
2578}
2579
2580static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2581{
Johannes Berg4c476992010-10-04 21:36:35 +02002582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002583 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002584 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002585 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002586 const u8 *mac_addr = NULL;
2587 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002588 struct get_key_cookie cookie = {
2589 .error = 0,
2590 };
2591 void *hdr;
2592 struct sk_buff *msg;
2593
2594 if (info->attrs[NL80211_ATTR_KEY_IDX])
2595 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2596
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002597 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002598 return -EINVAL;
2599
2600 if (info->attrs[NL80211_ATTR_MAC])
2601 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2602
Johannes Berge31b8212010-10-05 19:39:30 +02002603 pairwise = !!mac_addr;
2604 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2605 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2606 if (kt >= NUM_NL80211_KEYTYPES)
2607 return -EINVAL;
2608 if (kt != NL80211_KEYTYPE_GROUP &&
2609 kt != NL80211_KEYTYPE_PAIRWISE)
2610 return -EINVAL;
2611 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2612 }
2613
Johannes Berg4c476992010-10-04 21:36:35 +02002614 if (!rdev->ops->get_key)
2615 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002616
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002618 if (!msg)
2619 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002620
Eric W. Biederman15e47302012-09-07 20:12:54 +00002621 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002622 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002623 if (IS_ERR(hdr))
2624 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002625
2626 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002627 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002628
David S. Miller9360ffd2012-03-29 04:41:26 -04002629 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2630 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2631 goto nla_put_failure;
2632 if (mac_addr &&
2633 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2634 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002635
Johannes Berge31b8212010-10-05 19:39:30 +02002636 if (pairwise && mac_addr &&
2637 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2638 return -ENOENT;
2639
Hila Gonene35e4d22012-06-27 17:19:42 +03002640 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2641 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002642
2643 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002644 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002645
2646 if (cookie.error)
2647 goto nla_put_failure;
2648
2649 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002650 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002651
2652 nla_put_failure:
2653 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002654 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002655 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002656 return err;
2657}
2658
2659static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2660{
Johannes Berg4c476992010-10-04 21:36:35 +02002661 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002662 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002663 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002664 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002665
Johannes Bergb9454e82009-07-08 13:29:08 +02002666 err = nl80211_parse_key(info, &key);
2667 if (err)
2668 return err;
2669
2670 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002671 return -EINVAL;
2672
Johannes Bergb9454e82009-07-08 13:29:08 +02002673 /* only support setting default key */
2674 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002675 return -EINVAL;
2676
Johannes Bergfffd0932009-07-08 14:22:54 +02002677 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002678
2679 if (key.def) {
2680 if (!rdev->ops->set_default_key) {
2681 err = -EOPNOTSUPP;
2682 goto out;
2683 }
2684
2685 err = nl80211_key_allowed(dev->ieee80211_ptr);
2686 if (err)
2687 goto out;
2688
Hila Gonene35e4d22012-06-27 17:19:42 +03002689 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002690 key.def_uni, key.def_multi);
2691
2692 if (err)
2693 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002694
Johannes Berg3d23e342009-09-29 23:27:28 +02002695#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002696 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002697#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002698 } else {
2699 if (key.def_uni || !key.def_multi) {
2700 err = -EINVAL;
2701 goto out;
2702 }
2703
2704 if (!rdev->ops->set_default_mgmt_key) {
2705 err = -EOPNOTSUPP;
2706 goto out;
2707 }
2708
2709 err = nl80211_key_allowed(dev->ieee80211_ptr);
2710 if (err)
2711 goto out;
2712
Hila Gonene35e4d22012-06-27 17:19:42 +03002713 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002714 if (err)
2715 goto out;
2716
2717#ifdef CONFIG_CFG80211_WEXT
2718 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2719#endif
2720 }
2721
2722 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002723 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002724
Johannes Berg41ade002007-12-19 02:03:29 +01002725 return err;
2726}
2727
2728static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2729{
Johannes Berg4c476992010-10-04 21:36:35 +02002730 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002731 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002732 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002733 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002734 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002735
Johannes Bergb9454e82009-07-08 13:29:08 +02002736 err = nl80211_parse_key(info, &key);
2737 if (err)
2738 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002739
Johannes Bergb9454e82009-07-08 13:29:08 +02002740 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002741 return -EINVAL;
2742
Johannes Berg41ade002007-12-19 02:03:29 +01002743 if (info->attrs[NL80211_ATTR_MAC])
2744 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2745
Johannes Berge31b8212010-10-05 19:39:30 +02002746 if (key.type == -1) {
2747 if (mac_addr)
2748 key.type = NL80211_KEYTYPE_PAIRWISE;
2749 else
2750 key.type = NL80211_KEYTYPE_GROUP;
2751 }
2752
2753 /* for now */
2754 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2755 key.type != NL80211_KEYTYPE_GROUP)
2756 return -EINVAL;
2757
Johannes Berg4c476992010-10-04 21:36:35 +02002758 if (!rdev->ops->add_key)
2759 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002760
Johannes Berge31b8212010-10-05 19:39:30 +02002761 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2762 key.type == NL80211_KEYTYPE_PAIRWISE,
2763 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002764 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002765
2766 wdev_lock(dev->ieee80211_ptr);
2767 err = nl80211_key_allowed(dev->ieee80211_ptr);
2768 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002769 err = rdev_add_key(rdev, dev, key.idx,
2770 key.type == NL80211_KEYTYPE_PAIRWISE,
2771 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002772 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002773
Johannes Berg41ade002007-12-19 02:03:29 +01002774 return err;
2775}
2776
2777static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2778{
Johannes Berg4c476992010-10-04 21:36:35 +02002779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002780 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002781 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002782 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002783 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002784
Johannes Bergb9454e82009-07-08 13:29:08 +02002785 err = nl80211_parse_key(info, &key);
2786 if (err)
2787 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002788
2789 if (info->attrs[NL80211_ATTR_MAC])
2790 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2791
Johannes Berge31b8212010-10-05 19:39:30 +02002792 if (key.type == -1) {
2793 if (mac_addr)
2794 key.type = NL80211_KEYTYPE_PAIRWISE;
2795 else
2796 key.type = NL80211_KEYTYPE_GROUP;
2797 }
2798
2799 /* for now */
2800 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2801 key.type != NL80211_KEYTYPE_GROUP)
2802 return -EINVAL;
2803
Johannes Berg4c476992010-10-04 21:36:35 +02002804 if (!rdev->ops->del_key)
2805 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002806
Johannes Bergfffd0932009-07-08 14:22:54 +02002807 wdev_lock(dev->ieee80211_ptr);
2808 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002809
2810 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2811 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2812 err = -ENOENT;
2813
Johannes Bergfffd0932009-07-08 14:22:54 +02002814 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002815 err = rdev_del_key(rdev, dev, key.idx,
2816 key.type == NL80211_KEYTYPE_PAIRWISE,
2817 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002818
Johannes Berg3d23e342009-09-29 23:27:28 +02002819#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002820 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002821 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002822 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002823 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002824 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2825 }
2826#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002827 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002828
Johannes Berg41ade002007-12-19 02:03:29 +01002829 return err;
2830}
2831
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302832/* This function returns an error or the number of nested attributes */
2833static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2834{
2835 struct nlattr *attr;
2836 int n_entries = 0, tmp;
2837
2838 nla_for_each_nested(attr, nl_attr, tmp) {
2839 if (nla_len(attr) != ETH_ALEN)
2840 return -EINVAL;
2841
2842 n_entries++;
2843 }
2844
2845 return n_entries;
2846}
2847
2848/*
2849 * This function parses ACL information and allocates memory for ACL data.
2850 * On successful return, the calling function is responsible to free the
2851 * ACL buffer returned by this function.
2852 */
2853static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2854 struct genl_info *info)
2855{
2856 enum nl80211_acl_policy acl_policy;
2857 struct nlattr *attr;
2858 struct cfg80211_acl_data *acl;
2859 int i = 0, n_entries, tmp;
2860
2861 if (!wiphy->max_acl_mac_addrs)
2862 return ERR_PTR(-EOPNOTSUPP);
2863
2864 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2865 return ERR_PTR(-EINVAL);
2866
2867 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2868 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2869 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2870 return ERR_PTR(-EINVAL);
2871
2872 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2873 return ERR_PTR(-EINVAL);
2874
2875 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2876 if (n_entries < 0)
2877 return ERR_PTR(n_entries);
2878
2879 if (n_entries > wiphy->max_acl_mac_addrs)
2880 return ERR_PTR(-ENOTSUPP);
2881
2882 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2883 GFP_KERNEL);
2884 if (!acl)
2885 return ERR_PTR(-ENOMEM);
2886
2887 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2888 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2889 i++;
2890 }
2891
2892 acl->n_acl_entries = n_entries;
2893 acl->acl_policy = acl_policy;
2894
2895 return acl;
2896}
2897
2898static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2899{
2900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2901 struct net_device *dev = info->user_ptr[1];
2902 struct cfg80211_acl_data *acl;
2903 int err;
2904
2905 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2906 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2907 return -EOPNOTSUPP;
2908
2909 if (!dev->ieee80211_ptr->beacon_interval)
2910 return -EINVAL;
2911
2912 acl = parse_acl_data(&rdev->wiphy, info);
2913 if (IS_ERR(acl))
2914 return PTR_ERR(acl);
2915
2916 err = rdev_set_mac_acl(rdev, dev, acl);
2917
2918 kfree(acl);
2919
2920 return err;
2921}
2922
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002923static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002924 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002925{
Johannes Berg88600202012-02-13 15:17:18 +01002926 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002927
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002928 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2929 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2930 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2931 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002932 return -EINVAL;
2933
Johannes Berg88600202012-02-13 15:17:18 +01002934 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002935
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002936 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2937 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2938 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002939 if (!bcn->head_len)
2940 return -EINVAL;
2941 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002942 }
2943
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002944 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2945 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2946 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002947 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002948 }
2949
Johannes Berg4c476992010-10-04 21:36:35 +02002950 if (!haveinfo)
2951 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002952
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002953 if (attrs[NL80211_ATTR_IE]) {
2954 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2955 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002956 }
2957
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002958 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002959 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002960 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002961 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002962 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002963 }
2964
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002965 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002966 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002967 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002968 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002969 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002970 }
2971
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002972 if (attrs[NL80211_ATTR_PROBE_RESP]) {
2973 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
2974 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02002975 }
2976
Johannes Berg88600202012-02-13 15:17:18 +01002977 return 0;
2978}
2979
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002980static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
2981 struct cfg80211_ap_settings *params)
2982{
2983 struct wireless_dev *wdev;
2984 bool ret = false;
2985
Johannes Berg89a54e42012-06-15 14:33:17 +02002986 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002987 if (wdev->iftype != NL80211_IFTYPE_AP &&
2988 wdev->iftype != NL80211_IFTYPE_P2P_GO)
2989 continue;
2990
Johannes Berg683b6d32012-11-08 21:25:48 +01002991 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002992 continue;
2993
Johannes Berg683b6d32012-11-08 21:25:48 +01002994 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002995 ret = true;
2996 break;
2997 }
2998
Felix Fietkau46c1dd02012-06-19 02:50:57 +02002999 return ret;
3000}
3001
Jouni Malinene39e5b52012-09-30 19:29:39 +03003002static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3003 enum nl80211_auth_type auth_type,
3004 enum nl80211_commands cmd)
3005{
3006 if (auth_type > NL80211_AUTHTYPE_MAX)
3007 return false;
3008
3009 switch (cmd) {
3010 case NL80211_CMD_AUTHENTICATE:
3011 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3012 auth_type == NL80211_AUTHTYPE_SAE)
3013 return false;
3014 return true;
3015 case NL80211_CMD_CONNECT:
3016 case NL80211_CMD_START_AP:
3017 /* SAE not supported yet */
3018 if (auth_type == NL80211_AUTHTYPE_SAE)
3019 return false;
3020 return true;
3021 default:
3022 return false;
3023 }
3024}
3025
Johannes Berg88600202012-02-13 15:17:18 +01003026static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3027{
3028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3029 struct net_device *dev = info->user_ptr[1];
3030 struct wireless_dev *wdev = dev->ieee80211_ptr;
3031 struct cfg80211_ap_settings params;
3032 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003033 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003034
3035 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3036 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3037 return -EOPNOTSUPP;
3038
3039 if (!rdev->ops->start_ap)
3040 return -EOPNOTSUPP;
3041
3042 if (wdev->beacon_interval)
3043 return -EALREADY;
3044
3045 memset(&params, 0, sizeof(params));
3046
3047 /* these are required for START_AP */
3048 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3049 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3050 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3051 return -EINVAL;
3052
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003053 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003054 if (err)
3055 return err;
3056
3057 params.beacon_interval =
3058 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3059 params.dtim_period =
3060 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3061
3062 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3063 if (err)
3064 return err;
3065
3066 /*
3067 * In theory, some of these attributes should be required here
3068 * but since they were not used when the command was originally
3069 * added, keep them optional for old user space programs to let
3070 * them continue to work with drivers that do not need the
3071 * additional information -- drivers must check!
3072 */
3073 if (info->attrs[NL80211_ATTR_SSID]) {
3074 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3075 params.ssid_len =
3076 nla_len(info->attrs[NL80211_ATTR_SSID]);
3077 if (params.ssid_len == 0 ||
3078 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3079 return -EINVAL;
3080 }
3081
3082 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3083 params.hidden_ssid = nla_get_u32(
3084 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3085 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3086 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3087 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3088 return -EINVAL;
3089 }
3090
3091 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3092
3093 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3094 params.auth_type = nla_get_u32(
3095 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003096 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3097 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003098 return -EINVAL;
3099 } else
3100 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3101
3102 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3103 NL80211_MAX_NR_CIPHER_SUITES);
3104 if (err)
3105 return err;
3106
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303107 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3108 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3109 return -EOPNOTSUPP;
3110 params.inactivity_timeout = nla_get_u16(
3111 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3112 }
3113
Johannes Berg53cabad2012-11-14 15:17:28 +01003114 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3116 return -EINVAL;
3117 params.p2p_ctwindow =
3118 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3119 if (params.p2p_ctwindow > 127)
3120 return -EINVAL;
3121 if (params.p2p_ctwindow != 0 &&
3122 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3123 return -EINVAL;
3124 }
3125
3126 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3127 u8 tmp;
3128
3129 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3130 return -EINVAL;
3131 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3132 if (tmp > 1)
3133 return -EINVAL;
3134 params.p2p_opp_ps = tmp;
3135 if (params.p2p_opp_ps != 0 &&
3136 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3137 return -EINVAL;
3138 }
3139
Johannes Bergaa430da2012-05-16 23:50:18 +02003140 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003141 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3142 if (err)
3143 return err;
3144 } else if (wdev->preset_chandef.chan) {
3145 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003146 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003147 return -EINVAL;
3148
Johannes Berg683b6d32012-11-08 21:25:48 +01003149 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003150 return -EINVAL;
3151
Simon Wunderlich04f39042013-02-08 18:16:19 +01003152 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3153 if (err < 0)
3154 return err;
3155 if (err) {
3156 radar_detect_width = BIT(params.chandef.width);
3157 params.radar_required = true;
3158 }
3159
Simon Wunderlich04f39042013-02-08 18:16:19 +01003160 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3161 params.chandef.chan,
3162 CHAN_MODE_SHARED,
3163 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003164 if (err)
3165 return err;
3166
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303167 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3168 params.acl = parse_acl_data(&rdev->wiphy, info);
3169 if (IS_ERR(params.acl))
3170 return PTR_ERR(params.acl);
3171 }
3172
Hila Gonene35e4d22012-06-27 17:19:42 +03003173 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003174 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003175 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003176 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003177 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003178 wdev->ssid_len = params.ssid_len;
3179 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003180 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303181
3182 kfree(params.acl);
3183
Johannes Berg56d18932011-05-09 18:41:15 +02003184 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003185}
3186
Johannes Berg88600202012-02-13 15:17:18 +01003187static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3188{
3189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3190 struct net_device *dev = info->user_ptr[1];
3191 struct wireless_dev *wdev = dev->ieee80211_ptr;
3192 struct cfg80211_beacon_data params;
3193 int err;
3194
3195 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3196 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3197 return -EOPNOTSUPP;
3198
3199 if (!rdev->ops->change_beacon)
3200 return -EOPNOTSUPP;
3201
3202 if (!wdev->beacon_interval)
3203 return -EINVAL;
3204
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003205 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003206 if (err)
3207 return err;
3208
Hila Gonene35e4d22012-06-27 17:19:42 +03003209 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003210}
3211
3212static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003213{
Johannes Berg4c476992010-10-04 21:36:35 +02003214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3215 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003216
Michal Kazior60771782012-06-29 12:46:56 +02003217 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003218}
3219
Johannes Berg5727ef12007-12-19 02:03:34 +01003220static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3221 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3222 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3223 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003224 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003225 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003226 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003227};
3228
Johannes Bergeccb8e82009-05-11 21:57:56 +03003229static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003230 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003231 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003232{
3233 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003234 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003235 int flag;
3236
Johannes Bergeccb8e82009-05-11 21:57:56 +03003237 /*
3238 * Try parsing the new attribute first so userspace
3239 * can specify both for older kernels.
3240 */
3241 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3242 if (nla) {
3243 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003244
Johannes Bergeccb8e82009-05-11 21:57:56 +03003245 sta_flags = nla_data(nla);
3246 params->sta_flags_mask = sta_flags->mask;
3247 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003248 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003249 if ((params->sta_flags_mask |
3250 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3251 return -EINVAL;
3252 return 0;
3253 }
3254
3255 /* if present, parse the old attribute */
3256
3257 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003258 if (!nla)
3259 return 0;
3260
3261 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3262 nla, sta_flags_policy))
3263 return -EINVAL;
3264
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003265 /*
3266 * Only allow certain flags for interface types so that
3267 * other attributes are silently ignored. Remember that
3268 * this is backward compatibility code with old userspace
3269 * and shouldn't be hit in other cases anyway.
3270 */
3271 switch (iftype) {
3272 case NL80211_IFTYPE_AP:
3273 case NL80211_IFTYPE_AP_VLAN:
3274 case NL80211_IFTYPE_P2P_GO:
3275 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3276 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3277 BIT(NL80211_STA_FLAG_WME) |
3278 BIT(NL80211_STA_FLAG_MFP);
3279 break;
3280 case NL80211_IFTYPE_P2P_CLIENT:
3281 case NL80211_IFTYPE_STATION:
3282 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3283 BIT(NL80211_STA_FLAG_TDLS_PEER);
3284 break;
3285 case NL80211_IFTYPE_MESH_POINT:
3286 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3287 BIT(NL80211_STA_FLAG_MFP) |
3288 BIT(NL80211_STA_FLAG_AUTHORIZED);
3289 default:
3290 return -EINVAL;
3291 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003292
Johannes Berg3383b5a2012-05-10 20:14:43 +02003293 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3294 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003295 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003296
Johannes Berg3383b5a2012-05-10 20:14:43 +02003297 /* no longer support new API additions in old API */
3298 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3299 return -EINVAL;
3300 }
3301 }
3302
Johannes Berg5727ef12007-12-19 02:03:34 +01003303 return 0;
3304}
3305
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003306static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3307 int attr)
3308{
3309 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003310 u32 bitrate;
3311 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003312
3313 rate = nla_nest_start(msg, attr);
3314 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003315 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003316
3317 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3318 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003319 /* report 16-bit bitrate only if we can */
3320 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003321 if (bitrate > 0 &&
3322 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3323 return false;
3324 if (bitrate_compat > 0 &&
3325 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3326 return false;
3327
3328 if (info->flags & RATE_INFO_FLAGS_MCS) {
3329 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3330 return false;
3331 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3332 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3333 return false;
3334 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3335 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3336 return false;
3337 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3338 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3339 return false;
3340 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3341 return false;
3342 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3343 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3344 return false;
3345 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3346 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3347 return false;
3348 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3349 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3350 return false;
3351 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3352 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3353 return false;
3354 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3355 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3356 return false;
3357 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003358
3359 nla_nest_end(msg, rate);
3360 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003361}
3362
Felix Fietkau119363c2013-04-22 16:29:30 +02003363static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3364 int id)
3365{
3366 void *attr;
3367 int i = 0;
3368
3369 if (!mask)
3370 return true;
3371
3372 attr = nla_nest_start(msg, id);
3373 if (!attr)
3374 return false;
3375
3376 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3377 if (!(mask & BIT(i)))
3378 continue;
3379
3380 if (nla_put_u8(msg, i, signal[i]))
3381 return false;
3382 }
3383
3384 nla_nest_end(msg, attr);
3385
3386 return true;
3387}
3388
Eric W. Biederman15e47302012-09-07 20:12:54 +00003389static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003390 int flags,
3391 struct cfg80211_registered_device *rdev,
3392 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003393 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003394{
3395 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003396 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003397
Eric W. Biederman15e47302012-09-07 20:12:54 +00003398 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003399 if (!hdr)
3400 return -1;
3401
David S. Miller9360ffd2012-03-29 04:41:26 -04003402 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3403 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3404 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3405 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003406
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003407 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3408 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003409 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3411 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3412 sinfo->connected_time))
3413 goto nla_put_failure;
3414 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3415 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3416 sinfo->inactive_time))
3417 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003418 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3419 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003420 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003421 (u32)sinfo->rx_bytes))
3422 goto nla_put_failure;
3423 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003424 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003425 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3426 (u32)sinfo->tx_bytes))
3427 goto nla_put_failure;
3428 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3429 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003430 sinfo->rx_bytes))
3431 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003432 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3433 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003434 sinfo->tx_bytes))
3435 goto nla_put_failure;
3436 if ((sinfo->filled & STATION_INFO_LLID) &&
3437 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3438 goto nla_put_failure;
3439 if ((sinfo->filled & STATION_INFO_PLID) &&
3440 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3441 goto nla_put_failure;
3442 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3443 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3444 sinfo->plink_state))
3445 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003446 switch (rdev->wiphy.signal_type) {
3447 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003448 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3449 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3450 sinfo->signal))
3451 goto nla_put_failure;
3452 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3453 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3454 sinfo->signal_avg))
3455 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003456 break;
3457 default:
3458 break;
3459 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003460 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3461 if (!nl80211_put_signal(msg, sinfo->chains,
3462 sinfo->chain_signal,
3463 NL80211_STA_INFO_CHAIN_SIGNAL))
3464 goto nla_put_failure;
3465 }
3466 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3467 if (!nl80211_put_signal(msg, sinfo->chains,
3468 sinfo->chain_signal_avg,
3469 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3470 goto nla_put_failure;
3471 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003472 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003473 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3474 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003475 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003476 }
3477 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3478 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3479 NL80211_STA_INFO_RX_BITRATE))
3480 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003481 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003482 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3483 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3484 sinfo->rx_packets))
3485 goto nla_put_failure;
3486 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3487 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3488 sinfo->tx_packets))
3489 goto nla_put_failure;
3490 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3491 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3492 sinfo->tx_retries))
3493 goto nla_put_failure;
3494 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3495 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3496 sinfo->tx_failed))
3497 goto nla_put_failure;
3498 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3499 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3500 sinfo->beacon_loss_count))
3501 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003502 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3503 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3504 sinfo->local_pm))
3505 goto nla_put_failure;
3506 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3507 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3508 sinfo->peer_pm))
3509 goto nla_put_failure;
3510 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3511 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3512 sinfo->nonpeer_pm))
3513 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003514 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3515 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3516 if (!bss_param)
3517 goto nla_put_failure;
3518
David S. Miller9360ffd2012-03-29 04:41:26 -04003519 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3520 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3521 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3522 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3523 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3524 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3525 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3526 sinfo->bss_param.dtim_period) ||
3527 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3528 sinfo->bss_param.beacon_interval))
3529 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003530
3531 nla_nest_end(msg, bss_param);
3532 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003533 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3534 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3535 sizeof(struct nl80211_sta_flag_update),
3536 &sinfo->sta_flags))
3537 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003538 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3539 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3540 sinfo->t_offset))
3541 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003542 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003543
David S. Miller9360ffd2012-03-29 04:41:26 -04003544 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3545 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3546 sinfo->assoc_req_ies))
3547 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003548
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003549 return genlmsg_end(msg, hdr);
3550
3551 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003552 genlmsg_cancel(msg, hdr);
3553 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003554}
3555
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003556static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003557 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003558{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003559 struct station_info sinfo;
3560 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003561 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003562 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003563 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003564 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003565
Johannes Berg97990a02013-04-19 01:02:55 +02003566 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003567 if (err)
3568 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003569
Johannes Berg97990a02013-04-19 01:02:55 +02003570 if (!wdev->netdev) {
3571 err = -EINVAL;
3572 goto out_err;
3573 }
3574
Johannes Bergbba95fe2008-07-29 13:22:51 +02003575 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003576 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003577 goto out_err;
3578 }
3579
Johannes Bergbba95fe2008-07-29 13:22:51 +02003580 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003581 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003582 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003583 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003584 if (err == -ENOENT)
3585 break;
3586 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003587 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003588
3589 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003590 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003591 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003592 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003593 &sinfo) < 0)
3594 goto out;
3595
3596 sta_idx++;
3597 }
3598
3599
3600 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003601 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003602 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003603 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003604 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003605
3606 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003607}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003608
Johannes Berg5727ef12007-12-19 02:03:34 +01003609static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3610{
Johannes Berg4c476992010-10-04 21:36:35 +02003611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3612 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003613 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003614 struct sk_buff *msg;
3615 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003616 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003617
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003618 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003619
3620 if (!info->attrs[NL80211_ATTR_MAC])
3621 return -EINVAL;
3622
3623 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3624
Johannes Berg4c476992010-10-04 21:36:35 +02003625 if (!rdev->ops->get_station)
3626 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003627
Hila Gonene35e4d22012-06-27 17:19:42 +03003628 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003629 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003630 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003631
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003632 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003633 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003634 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003635
Eric W. Biederman15e47302012-09-07 20:12:54 +00003636 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003637 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003638 nlmsg_free(msg);
3639 return -ENOBUFS;
3640 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003641
Johannes Berg4c476992010-10-04 21:36:35 +02003642 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003643}
3644
Johannes Berg77ee7c82013-02-15 00:48:33 +01003645int cfg80211_check_station_change(struct wiphy *wiphy,
3646 struct station_parameters *params,
3647 enum cfg80211_station_type statype)
3648{
3649 if (params->listen_interval != -1)
3650 return -EINVAL;
3651 if (params->aid)
3652 return -EINVAL;
3653
3654 /* When you run into this, adjust the code below for the new flag */
3655 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3656
3657 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003658 case CFG80211_STA_MESH_PEER_KERNEL:
3659 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003660 /*
3661 * No ignoring the TDLS flag here -- the userspace mesh
3662 * code doesn't have the bug of including TDLS in the
3663 * mask everywhere.
3664 */
3665 if (params->sta_flags_mask &
3666 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3667 BIT(NL80211_STA_FLAG_MFP) |
3668 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3669 return -EINVAL;
3670 break;
3671 case CFG80211_STA_TDLS_PEER_SETUP:
3672 case CFG80211_STA_TDLS_PEER_ACTIVE:
3673 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3674 return -EINVAL;
3675 /* ignore since it can't change */
3676 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3677 break;
3678 default:
3679 /* disallow mesh-specific things */
3680 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3681 return -EINVAL;
3682 if (params->local_pm)
3683 return -EINVAL;
3684 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3685 return -EINVAL;
3686 }
3687
3688 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3689 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3690 /* TDLS can't be set, ... */
3691 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3692 return -EINVAL;
3693 /*
3694 * ... but don't bother the driver with it. This works around
3695 * a hostapd/wpa_supplicant issue -- it always includes the
3696 * TLDS_PEER flag in the mask even for AP mode.
3697 */
3698 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3699 }
3700
3701 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3702 /* reject other things that can't change */
3703 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3704 return -EINVAL;
3705 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3706 return -EINVAL;
3707 if (params->supported_rates)
3708 return -EINVAL;
3709 if (params->ext_capab || params->ht_capa || params->vht_capa)
3710 return -EINVAL;
3711 }
3712
3713 if (statype != CFG80211_STA_AP_CLIENT) {
3714 if (params->vlan)
3715 return -EINVAL;
3716 }
3717
3718 switch (statype) {
3719 case CFG80211_STA_AP_MLME_CLIENT:
3720 /* Use this only for authorizing/unauthorizing a station */
3721 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3722 return -EOPNOTSUPP;
3723 break;
3724 case CFG80211_STA_AP_CLIENT:
3725 /* accept only the listed bits */
3726 if (params->sta_flags_mask &
3727 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3728 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3729 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3730 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3731 BIT(NL80211_STA_FLAG_WME) |
3732 BIT(NL80211_STA_FLAG_MFP)))
3733 return -EINVAL;
3734
3735 /* but authenticated/associated only if driver handles it */
3736 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3737 params->sta_flags_mask &
3738 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3739 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3740 return -EINVAL;
3741 break;
3742 case CFG80211_STA_IBSS:
3743 case CFG80211_STA_AP_STA:
3744 /* reject any changes other than AUTHORIZED */
3745 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3746 return -EINVAL;
3747 break;
3748 case CFG80211_STA_TDLS_PEER_SETUP:
3749 /* reject any changes other than AUTHORIZED or WME */
3750 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3751 BIT(NL80211_STA_FLAG_WME)))
3752 return -EINVAL;
3753 /* force (at least) rates when authorizing */
3754 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3755 !params->supported_rates)
3756 return -EINVAL;
3757 break;
3758 case CFG80211_STA_TDLS_PEER_ACTIVE:
3759 /* reject any changes */
3760 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003761 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003762 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3763 return -EINVAL;
3764 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003765 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003766 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3767 return -EINVAL;
3768 break;
3769 }
3770
3771 return 0;
3772}
3773EXPORT_SYMBOL(cfg80211_check_station_change);
3774
Johannes Berg5727ef12007-12-19 02:03:34 +01003775/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003776 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003777 */
Johannes Berg80b99892011-11-18 16:23:01 +01003778static struct net_device *get_vlan(struct genl_info *info,
3779 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003780{
Johannes Berg463d0182009-07-14 00:33:35 +02003781 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003782 struct net_device *v;
3783 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003784
Johannes Berg80b99892011-11-18 16:23:01 +01003785 if (!vlanattr)
3786 return NULL;
3787
3788 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3789 if (!v)
3790 return ERR_PTR(-ENODEV);
3791
3792 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3793 ret = -EINVAL;
3794 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003795 }
Johannes Berg80b99892011-11-18 16:23:01 +01003796
Johannes Berg77ee7c82013-02-15 00:48:33 +01003797 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3798 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3799 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3800 ret = -EINVAL;
3801 goto error;
3802 }
3803
Johannes Berg80b99892011-11-18 16:23:01 +01003804 if (!netif_running(v)) {
3805 ret = -ENETDOWN;
3806 goto error;
3807 }
3808
3809 return v;
3810 error:
3811 dev_put(v);
3812 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003813}
3814
Jouni Malinendf881292013-02-14 21:10:54 +02003815static struct nla_policy
3816nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3817 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3818 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3819};
3820
Johannes Bergff276692013-02-15 00:09:01 +01003821static int nl80211_parse_sta_wme(struct genl_info *info,
3822 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003823{
Jouni Malinendf881292013-02-14 21:10:54 +02003824 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3825 struct nlattr *nla;
3826 int err;
3827
Jouni Malinendf881292013-02-14 21:10:54 +02003828 /* parse WME attributes if present */
3829 if (!info->attrs[NL80211_ATTR_STA_WME])
3830 return 0;
3831
3832 nla = info->attrs[NL80211_ATTR_STA_WME];
3833 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3834 nl80211_sta_wme_policy);
3835 if (err)
3836 return err;
3837
3838 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3839 params->uapsd_queues = nla_get_u8(
3840 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3841 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3842 return -EINVAL;
3843
3844 if (tb[NL80211_STA_WME_MAX_SP])
3845 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3846
3847 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3848 return -EINVAL;
3849
3850 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3851
3852 return 0;
3853}
3854
Johannes Bergff276692013-02-15 00:09:01 +01003855static int nl80211_set_station_tdls(struct genl_info *info,
3856 struct station_parameters *params)
3857{
3858 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003859 if (info->attrs[NL80211_ATTR_PEER_AID])
3860 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003861 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3862 params->ht_capa =
3863 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3864 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3865 params->vht_capa =
3866 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3867
3868 return nl80211_parse_sta_wme(info, params);
3869}
3870
Johannes Berg5727ef12007-12-19 02:03:34 +01003871static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3872{
Johannes Berg4c476992010-10-04 21:36:35 +02003873 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003874 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003875 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003876 u8 *mac_addr;
3877 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003878
3879 memset(&params, 0, sizeof(params));
3880
3881 params.listen_interval = -1;
3882
Johannes Berg77ee7c82013-02-15 00:48:33 +01003883 if (!rdev->ops->change_station)
3884 return -EOPNOTSUPP;
3885
Johannes Berg5727ef12007-12-19 02:03:34 +01003886 if (info->attrs[NL80211_ATTR_STA_AID])
3887 return -EINVAL;
3888
3889 if (!info->attrs[NL80211_ATTR_MAC])
3890 return -EINVAL;
3891
3892 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3893
3894 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3895 params.supported_rates =
3896 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3897 params.supported_rates_len =
3898 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3899 }
3900
Jouni Malinen9d62a982013-02-14 21:10:13 +02003901 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3902 params.capability =
3903 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3904 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3905 }
3906
3907 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3908 params.ext_capab =
3909 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3910 params.ext_capab_len =
3911 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3912 }
3913
Jouni Malinendf881292013-02-14 21:10:54 +02003914 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003915 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003916
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003917 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003918 return -EINVAL;
3919
Johannes Bergf8bacc22013-02-14 23:27:01 +01003920 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003921 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003922 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3923 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3924 return -EINVAL;
3925 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003926
Johannes Bergf8bacc22013-02-14 23:27:01 +01003927 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003928 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003929 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3930 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3931 return -EINVAL;
3932 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3933 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003934
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003935 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3936 enum nl80211_mesh_power_mode pm = nla_get_u32(
3937 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3938
3939 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3940 pm > NL80211_MESH_POWER_MAX)
3941 return -EINVAL;
3942
3943 params.local_pm = pm;
3944 }
3945
Johannes Berg77ee7c82013-02-15 00:48:33 +01003946 /* Include parameters for TDLS peer (will check later) */
3947 err = nl80211_set_station_tdls(info, &params);
3948 if (err)
3949 return err;
3950
3951 params.vlan = get_vlan(info, rdev);
3952 if (IS_ERR(params.vlan))
3953 return PTR_ERR(params.vlan);
3954
Johannes Berga97f4422009-06-18 17:23:43 +02003955 switch (dev->ieee80211_ptr->iftype) {
3956 case NL80211_IFTYPE_AP:
3957 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003958 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003959 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003960 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003961 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003962 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003963 break;
3964 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003965 err = -EOPNOTSUPP;
3966 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02003967 }
3968
Johannes Berg77ee7c82013-02-15 00:48:33 +01003969 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03003970 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01003971
Johannes Berg77ee7c82013-02-15 00:48:33 +01003972 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01003973 if (params.vlan)
3974 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01003975
Johannes Berg5727ef12007-12-19 02:03:34 +01003976 return err;
3977}
3978
3979static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
3980{
Johannes Berg4c476992010-10-04 21:36:35 +02003981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01003982 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003983 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003984 struct station_parameters params;
3985 u8 *mac_addr = NULL;
3986
3987 memset(&params, 0, sizeof(params));
3988
Johannes Berg984c3112013-02-14 23:43:25 +01003989 if (!rdev->ops->add_station)
3990 return -EOPNOTSUPP;
3991
Johannes Berg5727ef12007-12-19 02:03:34 +01003992 if (!info->attrs[NL80211_ATTR_MAC])
3993 return -EINVAL;
3994
Johannes Berg5727ef12007-12-19 02:03:34 +01003995 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
3996 return -EINVAL;
3997
3998 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
3999 return -EINVAL;
4000
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004001 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4002 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004003 return -EINVAL;
4004
Johannes Berg5727ef12007-12-19 02:03:34 +01004005 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4006 params.supported_rates =
4007 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4008 params.supported_rates_len =
4009 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4010 params.listen_interval =
4011 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004012
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004013 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004014 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004015 else
4016 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004017 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4018 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004019
Jouni Malinen9d62a982013-02-14 21:10:13 +02004020 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4021 params.capability =
4022 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4023 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4024 }
4025
4026 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4027 params.ext_capab =
4028 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4029 params.ext_capab_len =
4030 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4031 }
4032
Jouni Malinen36aedc902008-08-25 11:58:58 +03004033 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4034 params.ht_capa =
4035 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004036
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004037 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4038 params.vht_capa =
4039 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4040
Johannes Bergf8bacc22013-02-14 23:27:01 +01004041 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004042 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004043 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4044 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4045 return -EINVAL;
4046 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004047
Johannes Bergff276692013-02-15 00:09:01 +01004048 err = nl80211_parse_sta_wme(info, &params);
4049 if (err)
4050 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004051
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004052 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004053 return -EINVAL;
4054
Johannes Berg77ee7c82013-02-15 00:48:33 +01004055 /* When you run into this, adjust the code below for the new flag */
4056 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4057
Johannes Bergbdd90d52011-12-14 12:20:27 +01004058 switch (dev->ieee80211_ptr->iftype) {
4059 case NL80211_IFTYPE_AP:
4060 case NL80211_IFTYPE_AP_VLAN:
4061 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004062 /* ignore WME attributes if iface/sta is not capable */
4063 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4064 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4065 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004066
Johannes Bergbdd90d52011-12-14 12:20:27 +01004067 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004068 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4069 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004070 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004071 /* but don't bother the driver with it */
4072 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004073
Johannes Bergd582cff2012-10-26 17:53:44 +02004074 /* allow authenticated/associated only if driver handles it */
4075 if (!(rdev->wiphy.features &
4076 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4077 params.sta_flags_mask &
4078 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4079 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4080 return -EINVAL;
4081
Johannes Bergbdd90d52011-12-14 12:20:27 +01004082 /* must be last in here for error handling */
4083 params.vlan = get_vlan(info, rdev);
4084 if (IS_ERR(params.vlan))
4085 return PTR_ERR(params.vlan);
4086 break;
4087 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004088 /* ignore uAPSD data */
4089 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4090
Johannes Bergd582cff2012-10-26 17:53:44 +02004091 /* associated is disallowed */
4092 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4093 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004094 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004095 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4096 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004097 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004098 break;
4099 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004100 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004101 /* ignore uAPSD data */
4102 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4103
Johannes Berg77ee7c82013-02-15 00:48:33 +01004104 /* these are disallowed */
4105 if (params.sta_flags_mask &
4106 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4107 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004108 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004109 /* Only TDLS peers can be added */
4110 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4111 return -EINVAL;
4112 /* Can only add if TDLS ... */
4113 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4114 return -EOPNOTSUPP;
4115 /* ... with external setup is supported */
4116 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4117 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004118 /*
4119 * Older wpa_supplicant versions always mark the TDLS peer
4120 * as authorized, but it shouldn't yet be.
4121 */
4122 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004123 break;
4124 default:
4125 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004126 }
4127
Johannes Bergbdd90d52011-12-14 12:20:27 +01004128 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004129
Hila Gonene35e4d22012-06-27 17:19:42 +03004130 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004131
Johannes Berg5727ef12007-12-19 02:03:34 +01004132 if (params.vlan)
4133 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004134 return err;
4135}
4136
4137static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4138{
Johannes Berg4c476992010-10-04 21:36:35 +02004139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4140 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004141 u8 *mac_addr = NULL;
4142
4143 if (info->attrs[NL80211_ATTR_MAC])
4144 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4145
Johannes Berge80cf852009-05-11 14:43:13 +02004146 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004147 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004148 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004149 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4150 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004151
Johannes Berg4c476992010-10-04 21:36:35 +02004152 if (!rdev->ops->del_station)
4153 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004154
Hila Gonene35e4d22012-06-27 17:19:42 +03004155 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004156}
4157
Eric W. Biederman15e47302012-09-07 20:12:54 +00004158static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004159 int flags, struct net_device *dev,
4160 u8 *dst, u8 *next_hop,
4161 struct mpath_info *pinfo)
4162{
4163 void *hdr;
4164 struct nlattr *pinfoattr;
4165
Eric W. Biederman15e47302012-09-07 20:12:54 +00004166 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004167 if (!hdr)
4168 return -1;
4169
David S. Miller9360ffd2012-03-29 04:41:26 -04004170 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4171 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4172 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4173 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4174 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004175
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004176 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4177 if (!pinfoattr)
4178 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004179 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4180 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4181 pinfo->frame_qlen))
4182 goto nla_put_failure;
4183 if (((pinfo->filled & MPATH_INFO_SN) &&
4184 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4185 ((pinfo->filled & MPATH_INFO_METRIC) &&
4186 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4187 pinfo->metric)) ||
4188 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4189 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4190 pinfo->exptime)) ||
4191 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4192 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4193 pinfo->flags)) ||
4194 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4195 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4196 pinfo->discovery_timeout)) ||
4197 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4198 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4199 pinfo->discovery_retries)))
4200 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004201
4202 nla_nest_end(msg, pinfoattr);
4203
4204 return genlmsg_end(msg, hdr);
4205
4206 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004207 genlmsg_cancel(msg, hdr);
4208 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004209}
4210
4211static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004212 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004213{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004214 struct mpath_info pinfo;
4215 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004216 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004217 u8 dst[ETH_ALEN];
4218 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004219 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004220 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004221
Johannes Berg97990a02013-04-19 01:02:55 +02004222 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004223 if (err)
4224 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004225
4226 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004227 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004228 goto out_err;
4229 }
4230
Johannes Berg97990a02013-04-19 01:02:55 +02004231 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004232 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004233 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004234 }
4235
Johannes Bergbba95fe2008-07-29 13:22:51 +02004236 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004237 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4238 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004239 if (err == -ENOENT)
4240 break;
4241 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004242 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004243
Eric W. Biederman15e47302012-09-07 20:12:54 +00004244 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004245 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004246 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004247 &pinfo) < 0)
4248 goto out;
4249
4250 path_idx++;
4251 }
4252
4253
4254 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004255 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004256 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004257 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004258 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004259 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260}
4261
4262static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4263{
Johannes Berg4c476992010-10-04 21:36:35 +02004264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004265 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004266 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004267 struct mpath_info pinfo;
4268 struct sk_buff *msg;
4269 u8 *dst = NULL;
4270 u8 next_hop[ETH_ALEN];
4271
4272 memset(&pinfo, 0, sizeof(pinfo));
4273
4274 if (!info->attrs[NL80211_ATTR_MAC])
4275 return -EINVAL;
4276
4277 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4278
Johannes Berg4c476992010-10-04 21:36:35 +02004279 if (!rdev->ops->get_mpath)
4280 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004281
Johannes Berg4c476992010-10-04 21:36:35 +02004282 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4283 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004284
Hila Gonene35e4d22012-06-27 17:19:42 +03004285 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004286 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004287 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004288
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004290 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004291 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004292
Eric W. Biederman15e47302012-09-07 20:12:54 +00004293 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004294 dev, dst, next_hop, &pinfo) < 0) {
4295 nlmsg_free(msg);
4296 return -ENOBUFS;
4297 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004298
Johannes Berg4c476992010-10-04 21:36:35 +02004299 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300}
4301
4302static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4303{
Johannes Berg4c476992010-10-04 21:36:35 +02004304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4305 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004306 u8 *dst = NULL;
4307 u8 *next_hop = NULL;
4308
4309 if (!info->attrs[NL80211_ATTR_MAC])
4310 return -EINVAL;
4311
4312 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4313 return -EINVAL;
4314
4315 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4316 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4317
Johannes Berg4c476992010-10-04 21:36:35 +02004318 if (!rdev->ops->change_mpath)
4319 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004320
Johannes Berg4c476992010-10-04 21:36:35 +02004321 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4322 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004323
Hila Gonene35e4d22012-06-27 17:19:42 +03004324 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325}
Johannes Berg4c476992010-10-04 21:36:35 +02004326
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004327static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4328{
Johannes Berg4c476992010-10-04 21:36:35 +02004329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4330 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004331 u8 *dst = NULL;
4332 u8 *next_hop = NULL;
4333
4334 if (!info->attrs[NL80211_ATTR_MAC])
4335 return -EINVAL;
4336
4337 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4338 return -EINVAL;
4339
4340 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4341 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4342
Johannes Berg4c476992010-10-04 21:36:35 +02004343 if (!rdev->ops->add_mpath)
4344 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004345
Johannes Berg4c476992010-10-04 21:36:35 +02004346 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4347 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004348
Hila Gonene35e4d22012-06-27 17:19:42 +03004349 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004350}
4351
4352static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4353{
Johannes Berg4c476992010-10-04 21:36:35 +02004354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4355 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004356 u8 *dst = NULL;
4357
4358 if (info->attrs[NL80211_ATTR_MAC])
4359 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4360
Johannes Berg4c476992010-10-04 21:36:35 +02004361 if (!rdev->ops->del_mpath)
4362 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004363
Hila Gonene35e4d22012-06-27 17:19:42 +03004364 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004365}
4366
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004367static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4368{
Johannes Berg4c476992010-10-04 21:36:35 +02004369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4370 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004371 struct bss_parameters params;
4372
4373 memset(&params, 0, sizeof(params));
4374 /* default to not changing parameters */
4375 params.use_cts_prot = -1;
4376 params.use_short_preamble = -1;
4377 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004378 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004379 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004380 params.p2p_ctwindow = -1;
4381 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004382
4383 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4384 params.use_cts_prot =
4385 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4386 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4387 params.use_short_preamble =
4388 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4389 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4390 params.use_short_slot_time =
4391 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004392 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4393 params.basic_rates =
4394 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4395 params.basic_rates_len =
4396 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4397 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004398 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4399 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004400 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4401 params.ht_opmode =
4402 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004403
Johannes Berg53cabad2012-11-14 15:17:28 +01004404 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4405 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4406 return -EINVAL;
4407 params.p2p_ctwindow =
4408 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4409 if (params.p2p_ctwindow < 0)
4410 return -EINVAL;
4411 if (params.p2p_ctwindow != 0 &&
4412 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4413 return -EINVAL;
4414 }
4415
4416 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4417 u8 tmp;
4418
4419 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4420 return -EINVAL;
4421 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4422 if (tmp > 1)
4423 return -EINVAL;
4424 params.p2p_opp_ps = tmp;
4425 if (params.p2p_opp_ps &&
4426 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4427 return -EINVAL;
4428 }
4429
Johannes Berg4c476992010-10-04 21:36:35 +02004430 if (!rdev->ops->change_bss)
4431 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004432
Johannes Berg074ac8d2010-09-16 14:58:22 +02004433 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004434 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4435 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004436
Hila Gonene35e4d22012-06-27 17:19:42 +03004437 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004438}
4439
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004440static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004441 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4442 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4443 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4444 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4445 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4446 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4447};
4448
4449static int parse_reg_rule(struct nlattr *tb[],
4450 struct ieee80211_reg_rule *reg_rule)
4451{
4452 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4453 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4454
4455 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4456 return -EINVAL;
4457 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4458 return -EINVAL;
4459 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4460 return -EINVAL;
4461 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4462 return -EINVAL;
4463 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4464 return -EINVAL;
4465
4466 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4467
4468 freq_range->start_freq_khz =
4469 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4470 freq_range->end_freq_khz =
4471 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4472 freq_range->max_bandwidth_khz =
4473 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4474
4475 power_rule->max_eirp =
4476 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4477
4478 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4479 power_rule->max_antenna_gain =
4480 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4481
4482 return 0;
4483}
4484
4485static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4486{
4487 int r;
4488 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004489 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004490
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004491 /*
4492 * You should only get this when cfg80211 hasn't yet initialized
4493 * completely when built-in to the kernel right between the time
4494 * window between nl80211_init() and regulatory_init(), if that is
4495 * even possible.
4496 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004497 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004498 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004499
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004500 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4501 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004502
4503 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4504
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004505 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4506 user_reg_hint_type =
4507 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4508 else
4509 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4510
4511 switch (user_reg_hint_type) {
4512 case NL80211_USER_REG_HINT_USER:
4513 case NL80211_USER_REG_HINT_CELL_BASE:
4514 break;
4515 default:
4516 return -EINVAL;
4517 }
4518
4519 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004520
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004521 return r;
4522}
4523
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004524static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004525 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004526{
Johannes Berg4c476992010-10-04 21:36:35 +02004527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004528 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004529 struct wireless_dev *wdev = dev->ieee80211_ptr;
4530 struct mesh_config cur_params;
4531 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004532 void *hdr;
4533 struct nlattr *pinfoattr;
4534 struct sk_buff *msg;
4535
Johannes Berg29cbe682010-12-03 09:20:44 +01004536 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4537 return -EOPNOTSUPP;
4538
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004539 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004540 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004541
Johannes Berg29cbe682010-12-03 09:20:44 +01004542 wdev_lock(wdev);
4543 /* If not connected, get default parameters */
4544 if (!wdev->mesh_id_len)
4545 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4546 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004547 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004548 wdev_unlock(wdev);
4549
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004550 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004551 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004552
4553 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004555 if (!msg)
4556 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004557 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004558 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004559 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004560 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004561 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004562 if (!pinfoattr)
4563 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004564 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4565 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4566 cur_params.dot11MeshRetryTimeout) ||
4567 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4568 cur_params.dot11MeshConfirmTimeout) ||
4569 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4570 cur_params.dot11MeshHoldingTimeout) ||
4571 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4572 cur_params.dot11MeshMaxPeerLinks) ||
4573 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4574 cur_params.dot11MeshMaxRetries) ||
4575 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4576 cur_params.dot11MeshTTL) ||
4577 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4578 cur_params.element_ttl) ||
4579 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4580 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004581 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4582 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004583 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4584 cur_params.dot11MeshHWMPmaxPREQretries) ||
4585 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4586 cur_params.path_refresh_time) ||
4587 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4588 cur_params.min_discovery_timeout) ||
4589 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4590 cur_params.dot11MeshHWMPactivePathTimeout) ||
4591 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4592 cur_params.dot11MeshHWMPpreqMinInterval) ||
4593 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4594 cur_params.dot11MeshHWMPperrMinInterval) ||
4595 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4596 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4597 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4598 cur_params.dot11MeshHWMPRootMode) ||
4599 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4600 cur_params.dot11MeshHWMPRannInterval) ||
4601 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4602 cur_params.dot11MeshGateAnnouncementProtocol) ||
4603 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4604 cur_params.dot11MeshForwarding) ||
4605 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004606 cur_params.rssi_threshold) ||
4607 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004608 cur_params.ht_opmode) ||
4609 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4610 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4611 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004612 cur_params.dot11MeshHWMProotInterval) ||
4613 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004614 cur_params.dot11MeshHWMPconfirmationInterval) ||
4615 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4616 cur_params.power_mode) ||
4617 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004618 cur_params.dot11MeshAwakeWindowDuration) ||
4619 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4620 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004621 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004622 nla_nest_end(msg, pinfoattr);
4623 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004624 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004625
Johannes Berg3b858752009-03-12 09:55:09 +01004626 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004627 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004628 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004629 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004630 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004631}
4632
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004633static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004634 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4635 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4636 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4637 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4638 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4639 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004640 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004641 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004642 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004643 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4644 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4645 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4646 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4647 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004648 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004649 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004650 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004651 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004652 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004653 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004654 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4655 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004656 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4657 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004658 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004659 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4660 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004661 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662};
4663
Javier Cardonac80d5452010-12-16 17:37:49 -08004664static const struct nla_policy
4665 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004666 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004667 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4668 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004669 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004670 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004671 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004672 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004673 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004674 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004675};
4676
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004677static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004678 struct mesh_config *cfg,
4679 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004680{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004681 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004682 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004683
Marco Porschea54fba2013-01-07 16:04:48 +01004684#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4685do { \
4686 if (tb[attr]) { \
4687 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4688 return -EINVAL; \
4689 cfg->param = fn(tb[attr]); \
4690 mask |= (1 << (attr - 1)); \
4691 } \
4692} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004693
4694
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004695 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004696 return -EINVAL;
4697 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004698 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004699 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004700 return -EINVAL;
4701
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004702 /* This makes sure that there aren't more than 32 mesh config
4703 * parameters (otherwise our bitfield scheme would not work.) */
4704 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4705
4706 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004707 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4709 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004711 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4712 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004713 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004714 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4715 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004717 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4718 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004719 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004720 mask, NL80211_MESHCONF_MAX_RETRIES,
4721 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004722 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004723 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004724 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004725 mask, NL80211_MESHCONF_ELEMENT_TTL,
4726 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004727 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004728 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4729 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004730 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4731 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004732 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4733 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004734 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004735 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4736 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004737 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004738 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4739 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004740 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004741 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4742 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004743 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4744 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004745 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4746 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004747 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004748 1, 65535, mask,
4749 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004750 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004752 1, 65535, mask,
4753 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004754 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004755 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004756 dot11MeshHWMPnetDiameterTraversalTime,
4757 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004758 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4759 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004760 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4761 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4762 nla_get_u8);
4763 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4764 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004765 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004766 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004767 dot11MeshGateAnnouncementProtocol, 0, 1,
4768 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004769 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004770 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004771 mask, NL80211_MESHCONF_FORWARDING,
4772 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004773 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004774 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4775 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004776 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004777 mask, NL80211_MESHCONF_HT_OPMODE,
4778 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004779 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004780 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004781 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4782 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004783 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004784 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4785 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004787 dot11MeshHWMPconfirmationInterval,
4788 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004789 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4790 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004791 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4792 NL80211_MESH_POWER_ACTIVE,
4793 NL80211_MESH_POWER_MAX,
4794 mask, NL80211_MESHCONF_POWER_MODE,
4795 nla_get_u32);
4796 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4797 0, 65535, mask,
4798 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004799 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4800 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4801 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004802 if (mask_out)
4803 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004804
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004805 return 0;
4806
4807#undef FILL_IN_MESH_PARAM_IF_SET
4808}
4809
Javier Cardonac80d5452010-12-16 17:37:49 -08004810static int nl80211_parse_mesh_setup(struct genl_info *info,
4811 struct mesh_setup *setup)
4812{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004814 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4815
4816 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4817 return -EINVAL;
4818 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4819 info->attrs[NL80211_ATTR_MESH_SETUP],
4820 nl80211_mesh_setup_params_policy))
4821 return -EINVAL;
4822
Javier Cardonad299a1f2012-03-31 11:31:33 -07004823 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4824 setup->sync_method =
4825 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4826 IEEE80211_SYNC_METHOD_VENDOR :
4827 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4828
Javier Cardonac80d5452010-12-16 17:37:49 -08004829 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4830 setup->path_sel_proto =
4831 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4832 IEEE80211_PATH_PROTOCOL_VENDOR :
4833 IEEE80211_PATH_PROTOCOL_HWMP;
4834
4835 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4836 setup->path_metric =
4837 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4838 IEEE80211_PATH_METRIC_VENDOR :
4839 IEEE80211_PATH_METRIC_AIRTIME;
4840
Javier Cardona581a8b02011-04-07 15:08:27 -07004841
4842 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004843 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004844 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004845 if (!is_valid_ie_attr(ieattr))
4846 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004847 setup->ie = nla_data(ieattr);
4848 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004849 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004850 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4851 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4852 return -EINVAL;
4853 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004854 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4855 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004856 if (setup->is_secure)
4857 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004858
Colleen Twitty6e16d902013-05-08 11:45:59 -07004859 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4860 if (!setup->user_mpm)
4861 return -EINVAL;
4862 setup->auth_id =
4863 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4864 }
4865
Javier Cardonac80d5452010-12-16 17:37:49 -08004866 return 0;
4867}
4868
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004869static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004870 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004871{
4872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4873 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004874 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004875 struct mesh_config cfg;
4876 u32 mask;
4877 int err;
4878
Johannes Berg29cbe682010-12-03 09:20:44 +01004879 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4880 return -EOPNOTSUPP;
4881
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004882 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004883 return -EOPNOTSUPP;
4884
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004885 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004886 if (err)
4887 return err;
4888
Johannes Berg29cbe682010-12-03 09:20:44 +01004889 wdev_lock(wdev);
4890 if (!wdev->mesh_id_len)
4891 err = -ENOLINK;
4892
4893 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004894 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004895
4896 wdev_unlock(wdev);
4897
4898 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004899}
4900
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004901static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4902{
Johannes Berg458f4f92012-12-06 15:47:38 +01004903 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004904 struct sk_buff *msg;
4905 void *hdr = NULL;
4906 struct nlattr *nl_reg_rules;
4907 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004908
4909 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004910 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004911
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004912 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004913 if (!msg)
4914 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004915
Eric W. Biederman15e47302012-09-07 20:12:54 +00004916 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004917 NL80211_CMD_GET_REG);
4918 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004919 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004920
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004921 if (reg_last_request_cell_base() &&
4922 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4923 NL80211_USER_REG_HINT_CELL_BASE))
4924 goto nla_put_failure;
4925
Johannes Berg458f4f92012-12-06 15:47:38 +01004926 rcu_read_lock();
4927 regdom = rcu_dereference(cfg80211_regdomain);
4928
4929 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4930 (regdom->dfs_region &&
4931 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4932 goto nla_put_failure_rcu;
4933
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004934 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4935 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004936 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004937
Johannes Berg458f4f92012-12-06 15:47:38 +01004938 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939 struct nlattr *nl_reg_rule;
4940 const struct ieee80211_reg_rule *reg_rule;
4941 const struct ieee80211_freq_range *freq_range;
4942 const struct ieee80211_power_rule *power_rule;
4943
Johannes Berg458f4f92012-12-06 15:47:38 +01004944 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004945 freq_range = &reg_rule->freq_range;
4946 power_rule = &reg_rule->power_rule;
4947
4948 nl_reg_rule = nla_nest_start(msg, i);
4949 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004950 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004951
David S. Miller9360ffd2012-03-29 04:41:26 -04004952 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4953 reg_rule->flags) ||
4954 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4955 freq_range->start_freq_khz) ||
4956 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4957 freq_range->end_freq_khz) ||
4958 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4959 freq_range->max_bandwidth_khz) ||
4960 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4961 power_rule->max_antenna_gain) ||
4962 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4963 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004964 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004965
4966 nla_nest_end(msg, nl_reg_rule);
4967 }
Johannes Berg458f4f92012-12-06 15:47:38 +01004968 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004969
4970 nla_nest_end(msg, nl_reg_rules);
4971
4972 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004973 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004974
Johannes Berg458f4f92012-12-06 15:47:38 +01004975nla_put_failure_rcu:
4976 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004977nla_put_failure:
4978 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004979put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04004980 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004981 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004982}
4983
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004984static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
4985{
4986 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
4987 struct nlattr *nl_reg_rule;
4988 char *alpha2 = NULL;
4989 int rem_reg_rules = 0, r = 0;
4990 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07004991 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992 struct ieee80211_regdomain *rd = NULL;
4993
4994 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4995 return -EINVAL;
4996
4997 if (!info->attrs[NL80211_ATTR_REG_RULES])
4998 return -EINVAL;
4999
5000 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5001
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005002 if (info->attrs[NL80211_ATTR_DFS_REGION])
5003 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5004
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005005 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005006 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005007 num_rules++;
5008 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005009 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005010 }
5011
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005012 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005013 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005014
5015 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005016 if (!rd)
5017 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005018
5019 rd->n_reg_rules = num_rules;
5020 rd->alpha2[0] = alpha2[0];
5021 rd->alpha2[1] = alpha2[1];
5022
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005023 /*
5024 * Disable DFS master mode if the DFS region was
5025 * not supported or known on this kernel.
5026 */
5027 if (reg_supported_dfs_region(dfs_region))
5028 rd->dfs_region = dfs_region;
5029
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005030 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005031 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005032 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005033 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5034 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005035 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5036 if (r)
5037 goto bad_reg;
5038
5039 rule_idx++;
5040
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005041 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5042 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005043 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005044 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005045 }
5046
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005047 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005048 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005049 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005050
Johannes Bergd2372b32008-10-24 20:32:20 +02005051 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005052 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005053 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005054}
5055
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005056static int validate_scan_freqs(struct nlattr *freqs)
5057{
5058 struct nlattr *attr1, *attr2;
5059 int n_channels = 0, tmp1, tmp2;
5060
5061 nla_for_each_nested(attr1, freqs, tmp1) {
5062 n_channels++;
5063 /*
5064 * Some hardware has a limited channel list for
5065 * scanning, and it is pretty much nonsensical
5066 * to scan for a channel twice, so disallow that
5067 * and don't require drivers to check that the
5068 * channel list they get isn't longer than what
5069 * they can scan, as long as they can scan all
5070 * the channels they registered at once.
5071 */
5072 nla_for_each_nested(attr2, freqs, tmp2)
5073 if (attr1 != attr2 &&
5074 nla_get_u32(attr1) == nla_get_u32(attr2))
5075 return 0;
5076 }
5077
5078 return n_channels;
5079}
5080
Johannes Berg2a519312009-02-10 21:25:55 +01005081static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5082{
Johannes Berg4c476992010-10-04 21:36:35 +02005083 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005084 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005085 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005086 struct nlattr *attr;
5087 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005088 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005089 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005090
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005091 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5092 return -EINVAL;
5093
Johannes Berg79c97e92009-07-07 03:56:12 +02005094 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005095
Johannes Berg4c476992010-10-04 21:36:35 +02005096 if (!rdev->ops->scan)
5097 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005098
Johannes Bergf9f47522013-03-19 15:04:07 +01005099 if (rdev->scan_req) {
5100 err = -EBUSY;
5101 goto unlock;
5102 }
Johannes Berg2a519312009-02-10 21:25:55 +01005103
5104 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005105 n_channels = validate_scan_freqs(
5106 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005107 if (!n_channels) {
5108 err = -EINVAL;
5109 goto unlock;
5110 }
Johannes Berg2a519312009-02-10 21:25:55 +01005111 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005112 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005113 n_channels = 0;
5114
Johannes Berg2a519312009-02-10 21:25:55 +01005115 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5116 if (wiphy->bands[band])
5117 n_channels += wiphy->bands[band]->n_channels;
5118 }
5119
5120 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5121 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5122 n_ssids++;
5123
Johannes Bergf9f47522013-03-19 15:04:07 +01005124 if (n_ssids > wiphy->max_scan_ssids) {
5125 err = -EINVAL;
5126 goto unlock;
5127 }
Johannes Berg2a519312009-02-10 21:25:55 +01005128
Jouni Malinen70692ad2009-02-16 19:39:13 +02005129 if (info->attrs[NL80211_ATTR_IE])
5130 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5131 else
5132 ie_len = 0;
5133
Johannes Bergf9f47522013-03-19 15:04:07 +01005134 if (ie_len > wiphy->max_scan_ie_len) {
5135 err = -EINVAL;
5136 goto unlock;
5137 }
Johannes Berg18a83652009-03-31 12:12:05 +02005138
Johannes Berg2a519312009-02-10 21:25:55 +01005139 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005140 + sizeof(*request->ssids) * n_ssids
5141 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005142 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005143 if (!request) {
5144 err = -ENOMEM;
5145 goto unlock;
5146 }
Johannes Berg2a519312009-02-10 21:25:55 +01005147
Johannes Berg2a519312009-02-10 21:25:55 +01005148 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005149 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005150 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005151 if (ie_len) {
5152 if (request->ssids)
5153 request->ie = (void *)(request->ssids + n_ssids);
5154 else
5155 request->ie = (void *)(request->channels + n_channels);
5156 }
Johannes Berg2a519312009-02-10 21:25:55 +01005157
Johannes Berg584991d2009-11-02 13:32:03 +01005158 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005159 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5160 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005161 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005162 struct ieee80211_channel *chan;
5163
5164 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5165
5166 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005167 err = -EINVAL;
5168 goto out_free;
5169 }
Johannes Berg584991d2009-11-02 13:32:03 +01005170
5171 /* ignore disabled channels */
5172 if (chan->flags & IEEE80211_CHAN_DISABLED)
5173 continue;
5174
5175 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005176 i++;
5177 }
5178 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005179 enum ieee80211_band band;
5180
Johannes Berg2a519312009-02-10 21:25:55 +01005181 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005182 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5183 int j;
5184 if (!wiphy->bands[band])
5185 continue;
5186 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005187 struct ieee80211_channel *chan;
5188
5189 chan = &wiphy->bands[band]->channels[j];
5190
5191 if (chan->flags & IEEE80211_CHAN_DISABLED)
5192 continue;
5193
5194 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005195 i++;
5196 }
5197 }
5198 }
5199
Johannes Berg584991d2009-11-02 13:32:03 +01005200 if (!i) {
5201 err = -EINVAL;
5202 goto out_free;
5203 }
5204
5205 request->n_channels = i;
5206
Johannes Berg2a519312009-02-10 21:25:55 +01005207 i = 0;
5208 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5209 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005210 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005211 err = -EINVAL;
5212 goto out_free;
5213 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005214 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005215 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005216 i++;
5217 }
5218 }
5219
Jouni Malinen70692ad2009-02-16 19:39:13 +02005220 if (info->attrs[NL80211_ATTR_IE]) {
5221 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005222 memcpy((void *)request->ie,
5223 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005224 request->ie_len);
5225 }
5226
Johannes Berg34850ab2011-07-18 18:08:35 +02005227 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005228 if (wiphy->bands[i])
5229 request->rates[i] =
5230 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005231
5232 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5233 nla_for_each_nested(attr,
5234 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5235 tmp) {
5236 enum ieee80211_band band = nla_type(attr);
5237
Dan Carpenter84404622011-07-29 11:52:18 +03005238 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005239 err = -EINVAL;
5240 goto out_free;
5241 }
5242 err = ieee80211_get_ratemask(wiphy->bands[band],
5243 nla_data(attr),
5244 nla_len(attr),
5245 &request->rates[band]);
5246 if (err)
5247 goto out_free;
5248 }
5249 }
5250
Sam Leffler46856bb2012-10-11 21:03:32 -07005251 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005252 request->flags = nla_get_u32(
5253 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005254 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5255 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5256 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5257 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005258 err = -EOPNOTSUPP;
5259 goto out_free;
5260 }
5261 }
Sam Lefflered4737712012-10-11 21:03:31 -07005262
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305263 request->no_cck =
5264 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5265
Johannes Bergfd014282012-06-18 19:17:03 +02005266 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005267 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005268 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005269
Johannes Berg79c97e92009-07-07 03:56:12 +02005270 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005271 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005272
Johannes Berg463d0182009-07-14 00:33:35 +02005273 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005274 nl80211_send_scan_start(rdev, wdev);
5275 if (wdev->netdev)
5276 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005277 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005278 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005279 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005280 kfree(request);
5281 }
Johannes Berg3b858752009-03-12 09:55:09 +01005282
Johannes Bergf9f47522013-03-19 15:04:07 +01005283 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005284 return err;
5285}
5286
Luciano Coelho807f8a82011-05-11 17:09:35 +03005287static int nl80211_start_sched_scan(struct sk_buff *skb,
5288 struct genl_info *info)
5289{
5290 struct cfg80211_sched_scan_request *request;
5291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5292 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005293 struct nlattr *attr;
5294 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005295 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005296 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005297 enum ieee80211_band band;
5298 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005299 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005300
5301 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5302 !rdev->ops->sched_scan_start)
5303 return -EOPNOTSUPP;
5304
5305 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5306 return -EINVAL;
5307
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005308 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5309 return -EINVAL;
5310
5311 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5312 if (interval == 0)
5313 return -EINVAL;
5314
Luciano Coelho807f8a82011-05-11 17:09:35 +03005315 wiphy = &rdev->wiphy;
5316
5317 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5318 n_channels = validate_scan_freqs(
5319 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5320 if (!n_channels)
5321 return -EINVAL;
5322 } else {
5323 n_channels = 0;
5324
5325 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5326 if (wiphy->bands[band])
5327 n_channels += wiphy->bands[band]->n_channels;
5328 }
5329
5330 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5331 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5332 tmp)
5333 n_ssids++;
5334
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005335 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005336 return -EINVAL;
5337
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005338 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5339 nla_for_each_nested(attr,
5340 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5341 tmp)
5342 n_match_sets++;
5343
5344 if (n_match_sets > wiphy->max_match_sets)
5345 return -EINVAL;
5346
Luciano Coelho807f8a82011-05-11 17:09:35 +03005347 if (info->attrs[NL80211_ATTR_IE])
5348 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5349 else
5350 ie_len = 0;
5351
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005352 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005353 return -EINVAL;
5354
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005355 if (rdev->sched_scan_req) {
5356 err = -EINPROGRESS;
5357 goto out;
5358 }
5359
Luciano Coelho807f8a82011-05-11 17:09:35 +03005360 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005361 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005362 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005363 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005364 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005365 if (!request) {
5366 err = -ENOMEM;
5367 goto out;
5368 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005369
5370 if (n_ssids)
5371 request->ssids = (void *)&request->channels[n_channels];
5372 request->n_ssids = n_ssids;
5373 if (ie_len) {
5374 if (request->ssids)
5375 request->ie = (void *)(request->ssids + n_ssids);
5376 else
5377 request->ie = (void *)(request->channels + n_channels);
5378 }
5379
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005380 if (n_match_sets) {
5381 if (request->ie)
5382 request->match_sets = (void *)(request->ie + ie_len);
5383 else if (request->ssids)
5384 request->match_sets =
5385 (void *)(request->ssids + n_ssids);
5386 else
5387 request->match_sets =
5388 (void *)(request->channels + n_channels);
5389 }
5390 request->n_match_sets = n_match_sets;
5391
Luciano Coelho807f8a82011-05-11 17:09:35 +03005392 i = 0;
5393 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5394 /* user specified, bail out if channel not found */
5395 nla_for_each_nested(attr,
5396 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5397 tmp) {
5398 struct ieee80211_channel *chan;
5399
5400 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5401
5402 if (!chan) {
5403 err = -EINVAL;
5404 goto out_free;
5405 }
5406
5407 /* ignore disabled channels */
5408 if (chan->flags & IEEE80211_CHAN_DISABLED)
5409 continue;
5410
5411 request->channels[i] = chan;
5412 i++;
5413 }
5414 } else {
5415 /* all channels */
5416 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5417 int j;
5418 if (!wiphy->bands[band])
5419 continue;
5420 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5421 struct ieee80211_channel *chan;
5422
5423 chan = &wiphy->bands[band]->channels[j];
5424
5425 if (chan->flags & IEEE80211_CHAN_DISABLED)
5426 continue;
5427
5428 request->channels[i] = chan;
5429 i++;
5430 }
5431 }
5432 }
5433
5434 if (!i) {
5435 err = -EINVAL;
5436 goto out_free;
5437 }
5438
5439 request->n_channels = i;
5440
5441 i = 0;
5442 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5443 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5444 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005445 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005446 err = -EINVAL;
5447 goto out_free;
5448 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005449 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005450 memcpy(request->ssids[i].ssid, nla_data(attr),
5451 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005452 i++;
5453 }
5454 }
5455
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005456 i = 0;
5457 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5458 nla_for_each_nested(attr,
5459 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5460 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005461 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005462
5463 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5464 nla_data(attr), nla_len(attr),
5465 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005466 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005467 if (ssid) {
5468 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5469 err = -EINVAL;
5470 goto out_free;
5471 }
5472 memcpy(request->match_sets[i].ssid.ssid,
5473 nla_data(ssid), nla_len(ssid));
5474 request->match_sets[i].ssid.ssid_len =
5475 nla_len(ssid);
5476 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005477 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5478 if (rssi)
5479 request->rssi_thold = nla_get_u32(rssi);
5480 else
5481 request->rssi_thold =
5482 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005483 i++;
5484 }
5485 }
5486
Luciano Coelho807f8a82011-05-11 17:09:35 +03005487 if (info->attrs[NL80211_ATTR_IE]) {
5488 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5489 memcpy((void *)request->ie,
5490 nla_data(info->attrs[NL80211_ATTR_IE]),
5491 request->ie_len);
5492 }
5493
Sam Leffler46856bb2012-10-11 21:03:32 -07005494 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005495 request->flags = nla_get_u32(
5496 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005497 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5498 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5499 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5500 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005501 err = -EOPNOTSUPP;
5502 goto out_free;
5503 }
5504 }
Sam Lefflered4737712012-10-11 21:03:31 -07005505
Luciano Coelho807f8a82011-05-11 17:09:35 +03005506 request->dev = dev;
5507 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005508 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005509 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005510
Hila Gonene35e4d22012-06-27 17:19:42 +03005511 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005512 if (!err) {
5513 rdev->sched_scan_req = request;
5514 nl80211_send_sched_scan(rdev, dev,
5515 NL80211_CMD_START_SCHED_SCAN);
5516 goto out;
5517 }
5518
5519out_free:
5520 kfree(request);
5521out:
5522 return err;
5523}
5524
5525static int nl80211_stop_sched_scan(struct sk_buff *skb,
5526 struct genl_info *info)
5527{
5528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5529
5530 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5531 !rdev->ops->sched_scan_stop)
5532 return -EOPNOTSUPP;
5533
Johannes Berg5fe231e2013-05-08 21:45:15 +02005534 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005535}
5536
Simon Wunderlich04f39042013-02-08 18:16:19 +01005537static int nl80211_start_radar_detection(struct sk_buff *skb,
5538 struct genl_info *info)
5539{
5540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5541 struct net_device *dev = info->user_ptr[1];
5542 struct wireless_dev *wdev = dev->ieee80211_ptr;
5543 struct cfg80211_chan_def chandef;
5544 int err;
5545
5546 err = nl80211_parse_chandef(rdev, info, &chandef);
5547 if (err)
5548 return err;
5549
5550 if (wdev->cac_started)
5551 return -EBUSY;
5552
5553 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5554 if (err < 0)
5555 return err;
5556
5557 if (err == 0)
5558 return -EINVAL;
5559
5560 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5561 return -EINVAL;
5562
5563 if (!rdev->ops->start_radar_detection)
5564 return -EOPNOTSUPP;
5565
Simon Wunderlich04f39042013-02-08 18:16:19 +01005566 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5567 chandef.chan, CHAN_MODE_SHARED,
5568 BIT(chandef.width));
5569 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005570 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005571
5572 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5573 if (!err) {
5574 wdev->channel = chandef.chan;
5575 wdev->cac_started = true;
5576 wdev->cac_start_time = jiffies;
5577 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005578 return err;
5579}
5580
Johannes Berg9720bb32011-06-21 09:45:33 +02005581static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5582 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005583 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005584 struct wireless_dev *wdev,
5585 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005586{
Johannes Berg48ab9052009-07-10 18:42:31 +02005587 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005588 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005589 void *hdr;
5590 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005591 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005592
5593 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005594
Eric W. Biederman15e47302012-09-07 20:12:54 +00005595 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005596 NL80211_CMD_NEW_SCAN_RESULTS);
5597 if (!hdr)
5598 return -1;
5599
Johannes Berg9720bb32011-06-21 09:45:33 +02005600 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5601
Johannes Berg97990a02013-04-19 01:02:55 +02005602 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5603 goto nla_put_failure;
5604 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005605 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5606 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005607 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5608 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005609
5610 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5611 if (!bss)
5612 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005613 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005614 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005615 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005616
5617 rcu_read_lock();
5618 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005619 if (ies) {
5620 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5621 goto fail_unlock_rcu;
5622 tsf = true;
5623 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5624 ies->len, ies->data))
5625 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005626 }
5627 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005628 if (ies) {
5629 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5630 goto fail_unlock_rcu;
5631 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5632 ies->len, ies->data))
5633 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005634 }
5635 rcu_read_unlock();
5636
David S. Miller9360ffd2012-03-29 04:41:26 -04005637 if (res->beacon_interval &&
5638 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5639 goto nla_put_failure;
5640 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5641 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
5642 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5643 jiffies_to_msecs(jiffies - intbss->ts)))
5644 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005645
Johannes Berg77965c92009-02-18 18:45:06 +01005646 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005647 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005648 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5649 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005650 break;
5651 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005652 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5653 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005654 break;
5655 default:
5656 break;
5657 }
5658
Johannes Berg48ab9052009-07-10 18:42:31 +02005659 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005660 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005661 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005662 if (intbss == wdev->current_bss &&
5663 nla_put_u32(msg, NL80211_BSS_STATUS,
5664 NL80211_BSS_STATUS_ASSOCIATED))
5665 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005666 break;
5667 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005668 if (intbss == wdev->current_bss &&
5669 nla_put_u32(msg, NL80211_BSS_STATUS,
5670 NL80211_BSS_STATUS_IBSS_JOINED))
5671 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005672 break;
5673 default:
5674 break;
5675 }
5676
Johannes Berg2a519312009-02-10 21:25:55 +01005677 nla_nest_end(msg, bss);
5678
5679 return genlmsg_end(msg, hdr);
5680
Johannes Berg8cef2c92013-02-05 16:54:31 +01005681 fail_unlock_rcu:
5682 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005683 nla_put_failure:
5684 genlmsg_cancel(msg, hdr);
5685 return -EMSGSIZE;
5686}
5687
Johannes Berg97990a02013-04-19 01:02:55 +02005688static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005689{
Johannes Berg48ab9052009-07-10 18:42:31 +02005690 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005691 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005692 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005693 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005694 int err;
5695
Johannes Berg97990a02013-04-19 01:02:55 +02005696 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005697 if (err)
5698 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005699
Johannes Berg48ab9052009-07-10 18:42:31 +02005700 wdev_lock(wdev);
5701 spin_lock_bh(&rdev->bss_lock);
5702 cfg80211_bss_expire(rdev);
5703
Johannes Berg9720bb32011-06-21 09:45:33 +02005704 cb->seq = rdev->bss_generation;
5705
Johannes Berg48ab9052009-07-10 18:42:31 +02005706 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005707 if (++idx <= start)
5708 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005709 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005710 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005711 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005712 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005713 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005714 }
5715 }
5716
Johannes Berg48ab9052009-07-10 18:42:31 +02005717 spin_unlock_bh(&rdev->bss_lock);
5718 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005719
Johannes Berg97990a02013-04-19 01:02:55 +02005720 cb->args[2] = idx;
5721 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005722
Johannes Berg67748892010-10-04 21:14:06 +02005723 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005724}
5725
Eric W. Biederman15e47302012-09-07 20:12:54 +00005726static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005727 int flags, struct net_device *dev,
5728 struct survey_info *survey)
5729{
5730 void *hdr;
5731 struct nlattr *infoattr;
5732
Eric W. Biederman15e47302012-09-07 20:12:54 +00005733 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005734 NL80211_CMD_NEW_SURVEY_RESULTS);
5735 if (!hdr)
5736 return -ENOMEM;
5737
David S. Miller9360ffd2012-03-29 04:41:26 -04005738 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5739 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005740
5741 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5742 if (!infoattr)
5743 goto nla_put_failure;
5744
David S. Miller9360ffd2012-03-29 04:41:26 -04005745 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5746 survey->channel->center_freq))
5747 goto nla_put_failure;
5748
5749 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5750 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5751 goto nla_put_failure;
5752 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5753 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5754 goto nla_put_failure;
5755 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5756 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5757 survey->channel_time))
5758 goto nla_put_failure;
5759 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5760 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5761 survey->channel_time_busy))
5762 goto nla_put_failure;
5763 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5764 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5765 survey->channel_time_ext_busy))
5766 goto nla_put_failure;
5767 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5768 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5769 survey->channel_time_rx))
5770 goto nla_put_failure;
5771 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5772 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5773 survey->channel_time_tx))
5774 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005775
5776 nla_nest_end(msg, infoattr);
5777
5778 return genlmsg_end(msg, hdr);
5779
5780 nla_put_failure:
5781 genlmsg_cancel(msg, hdr);
5782 return -EMSGSIZE;
5783}
5784
5785static int nl80211_dump_survey(struct sk_buff *skb,
5786 struct netlink_callback *cb)
5787{
5788 struct survey_info survey;
5789 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005790 struct wireless_dev *wdev;
5791 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005792 int res;
5793
Johannes Berg97990a02013-04-19 01:02:55 +02005794 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005795 if (res)
5796 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005797
Johannes Berg97990a02013-04-19 01:02:55 +02005798 if (!wdev->netdev) {
5799 res = -EINVAL;
5800 goto out_err;
5801 }
5802
Holger Schurig61fa7132009-11-11 12:25:40 +01005803 if (!dev->ops->dump_survey) {
5804 res = -EOPNOTSUPP;
5805 goto out_err;
5806 }
5807
5808 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005809 struct ieee80211_channel *chan;
5810
Johannes Berg97990a02013-04-19 01:02:55 +02005811 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005812 if (res == -ENOENT)
5813 break;
5814 if (res)
5815 goto out_err;
5816
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005817 /* Survey without a channel doesn't make sense */
5818 if (!survey.channel) {
5819 res = -EINVAL;
5820 goto out;
5821 }
5822
5823 chan = ieee80211_get_channel(&dev->wiphy,
5824 survey.channel->center_freq);
5825 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5826 survey_idx++;
5827 continue;
5828 }
5829
Holger Schurig61fa7132009-11-11 12:25:40 +01005830 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005831 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005832 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005833 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005834 goto out;
5835 survey_idx++;
5836 }
5837
5838 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005839 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005840 res = skb->len;
5841 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005842 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005843 return res;
5844}
5845
Samuel Ortizb23aa672009-07-01 21:26:54 +02005846static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5847{
5848 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5849 NL80211_WPA_VERSION_2));
5850}
5851
Jouni Malinen636a5d32009-03-19 13:39:22 +02005852static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5853{
Johannes Berg4c476992010-10-04 21:36:35 +02005854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5855 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005856 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005857 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5858 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005859 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005860 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005861 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005862
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005863 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5864 return -EINVAL;
5865
5866 if (!info->attrs[NL80211_ATTR_MAC])
5867 return -EINVAL;
5868
Jouni Malinen17780922009-03-27 20:52:47 +02005869 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5870 return -EINVAL;
5871
Johannes Berg19957bb2009-07-02 17:20:43 +02005872 if (!info->attrs[NL80211_ATTR_SSID])
5873 return -EINVAL;
5874
5875 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5876 return -EINVAL;
5877
Johannes Bergfffd0932009-07-08 14:22:54 +02005878 err = nl80211_parse_key(info, &key);
5879 if (err)
5880 return err;
5881
5882 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005883 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5884 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005885 if (!key.p.key || !key.p.key_len)
5886 return -EINVAL;
5887 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5888 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5889 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5890 key.p.key_len != WLAN_KEY_LEN_WEP104))
5891 return -EINVAL;
5892 if (key.idx > 4)
5893 return -EINVAL;
5894 } else {
5895 key.p.key_len = 0;
5896 key.p.key = NULL;
5897 }
5898
Johannes Bergafea0b72010-08-10 09:46:42 +02005899 if (key.idx >= 0) {
5900 int i;
5901 bool ok = false;
5902 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5903 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5904 ok = true;
5905 break;
5906 }
5907 }
Johannes Berg4c476992010-10-04 21:36:35 +02005908 if (!ok)
5909 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005910 }
5911
Johannes Berg4c476992010-10-04 21:36:35 +02005912 if (!rdev->ops->auth)
5913 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005914
Johannes Berg074ac8d2010-09-16 14:58:22 +02005915 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005916 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5917 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005918
Johannes Berg19957bb2009-07-02 17:20:43 +02005919 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005920 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005921 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005922 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5923 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005924
Johannes Berg19957bb2009-07-02 17:20:43 +02005925 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5926 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5927
5928 if (info->attrs[NL80211_ATTR_IE]) {
5929 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5930 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5931 }
5932
5933 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005934 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005935 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005936
Jouni Malinene39e5b52012-09-30 19:29:39 +03005937 if (auth_type == NL80211_AUTHTYPE_SAE &&
5938 !info->attrs[NL80211_ATTR_SAE_DATA])
5939 return -EINVAL;
5940
5941 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5942 if (auth_type != NL80211_AUTHTYPE_SAE)
5943 return -EINVAL;
5944 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5945 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5946 /* need to include at least Auth Transaction and Status Code */
5947 if (sae_data_len < 4)
5948 return -EINVAL;
5949 }
5950
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005951 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5952
Johannes Berg95de8172012-01-20 13:55:25 +01005953 /*
5954 * Since we no longer track auth state, ignore
5955 * requests to only change local state.
5956 */
5957 if (local_state_change)
5958 return 0;
5959
Johannes Berg91bf9b22013-05-15 17:44:01 +02005960 wdev_lock(dev->ieee80211_ptr);
5961 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5962 ssid, ssid_len, ie, ie_len,
5963 key.p.key, key.p.key_len, key.idx,
5964 sae_data, sae_data_len);
5965 wdev_unlock(dev->ieee80211_ptr);
5966 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005967}
5968
Johannes Bergc0692b82010-08-27 14:26:53 +03005969static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
5970 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02005971 struct cfg80211_crypto_settings *settings,
5972 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02005973{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02005974 memset(settings, 0, sizeof(*settings));
5975
Samuel Ortizb23aa672009-07-01 21:26:54 +02005976 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
5977
Johannes Bergc0692b82010-08-27 14:26:53 +03005978 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
5979 u16 proto;
5980 proto = nla_get_u16(
5981 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
5982 settings->control_port_ethertype = cpu_to_be16(proto);
5983 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
5984 proto != ETH_P_PAE)
5985 return -EINVAL;
5986 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
5987 settings->control_port_no_encrypt = true;
5988 } else
5989 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
5990
Samuel Ortizb23aa672009-07-01 21:26:54 +02005991 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
5992 void *data;
5993 int len, i;
5994
5995 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5996 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
5997 settings->n_ciphers_pairwise = len / sizeof(u32);
5998
5999 if (len % sizeof(u32))
6000 return -EINVAL;
6001
Johannes Berg3dc27d22009-07-02 21:36:37 +02006002 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006003 return -EINVAL;
6004
6005 memcpy(settings->ciphers_pairwise, data, len);
6006
6007 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006008 if (!cfg80211_supported_cipher_suite(
6009 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006010 settings->ciphers_pairwise[i]))
6011 return -EINVAL;
6012 }
6013
6014 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6015 settings->cipher_group =
6016 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006017 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6018 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006019 return -EINVAL;
6020 }
6021
6022 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6023 settings->wpa_versions =
6024 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6025 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6026 return -EINVAL;
6027 }
6028
6029 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6030 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006031 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006032
6033 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6034 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6035 settings->n_akm_suites = len / sizeof(u32);
6036
6037 if (len % sizeof(u32))
6038 return -EINVAL;
6039
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006040 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6041 return -EINVAL;
6042
Samuel Ortizb23aa672009-07-01 21:26:54 +02006043 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006044 }
6045
6046 return 0;
6047}
6048
Jouni Malinen636a5d32009-03-19 13:39:22 +02006049static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6050{
Johannes Berg4c476992010-10-04 21:36:35 +02006051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6052 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006053 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006054 struct cfg80211_assoc_request req = {};
6055 const u8 *bssid, *ssid;
6056 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006057
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006058 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6059 return -EINVAL;
6060
6061 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006062 !info->attrs[NL80211_ATTR_SSID] ||
6063 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006064 return -EINVAL;
6065
Johannes Berg4c476992010-10-04 21:36:35 +02006066 if (!rdev->ops->assoc)
6067 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006068
Johannes Berg074ac8d2010-09-16 14:58:22 +02006069 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006070 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6071 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006072
Johannes Berg19957bb2009-07-02 17:20:43 +02006073 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006074
Johannes Berg19957bb2009-07-02 17:20:43 +02006075 chan = ieee80211_get_channel(&rdev->wiphy,
6076 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006077 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6078 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006079
Johannes Berg19957bb2009-07-02 17:20:43 +02006080 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6081 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006082
6083 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006084 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6085 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006086 }
6087
Jouni Malinendc6382c2009-05-06 22:09:37 +03006088 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006089 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006090 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006091 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006092 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006093 else if (mfp != NL80211_MFP_NO)
6094 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006095 }
6096
Johannes Berg3e5d7642009-07-07 14:37:26 +02006097 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006098 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006099
Ben Greear7e7c8922011-11-18 11:31:59 -08006100 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006101 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006102
6103 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006104 memcpy(&req.ht_capa_mask,
6105 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6106 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006107
6108 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006109 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006110 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006111 memcpy(&req.ht_capa,
6112 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6113 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006114 }
6115
Johannes Bergee2aca32013-02-21 17:36:01 +01006116 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006117 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006118
6119 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006120 memcpy(&req.vht_capa_mask,
6121 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6122 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006123
6124 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006125 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006126 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006127 memcpy(&req.vht_capa,
6128 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6129 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006130 }
6131
Johannes Bergf62fab72013-02-21 20:09:09 +01006132 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006133 if (!err) {
6134 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006135 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6136 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006137 wdev_unlock(dev->ieee80211_ptr);
6138 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006139
Jouni Malinen636a5d32009-03-19 13:39:22 +02006140 return err;
6141}
6142
6143static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6144{
Johannes Berg4c476992010-10-04 21:36:35 +02006145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6146 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006147 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006148 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006149 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006150 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006151
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006152 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6153 return -EINVAL;
6154
6155 if (!info->attrs[NL80211_ATTR_MAC])
6156 return -EINVAL;
6157
6158 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6159 return -EINVAL;
6160
Johannes Berg4c476992010-10-04 21:36:35 +02006161 if (!rdev->ops->deauth)
6162 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006163
Johannes Berg074ac8d2010-09-16 14:58:22 +02006164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006165 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6166 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006167
Johannes Berg19957bb2009-07-02 17:20:43 +02006168 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006169
Johannes Berg19957bb2009-07-02 17:20:43 +02006170 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6171 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006172 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006173 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006174 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006175
6176 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006177 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6178 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006179 }
6180
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006181 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6182
Johannes Berg91bf9b22013-05-15 17:44:01 +02006183 wdev_lock(dev->ieee80211_ptr);
6184 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6185 local_state_change);
6186 wdev_unlock(dev->ieee80211_ptr);
6187 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006188}
6189
6190static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6191{
Johannes Berg4c476992010-10-04 21:36:35 +02006192 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6193 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006194 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006195 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006196 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006197 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006198
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006199 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6200 return -EINVAL;
6201
6202 if (!info->attrs[NL80211_ATTR_MAC])
6203 return -EINVAL;
6204
6205 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6206 return -EINVAL;
6207
Johannes Berg4c476992010-10-04 21:36:35 +02006208 if (!rdev->ops->disassoc)
6209 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006210
Johannes Berg074ac8d2010-09-16 14:58:22 +02006211 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006212 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6213 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006214
Johannes Berg19957bb2009-07-02 17:20:43 +02006215 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006216
Johannes Berg19957bb2009-07-02 17:20:43 +02006217 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6218 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006219 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006220 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006221 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006222
6223 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006224 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6225 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006226 }
6227
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006228 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6229
Johannes Berg91bf9b22013-05-15 17:44:01 +02006230 wdev_lock(dev->ieee80211_ptr);
6231 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6232 local_state_change);
6233 wdev_unlock(dev->ieee80211_ptr);
6234 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006235}
6236
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006237static bool
6238nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6239 int mcast_rate[IEEE80211_NUM_BANDS],
6240 int rateval)
6241{
6242 struct wiphy *wiphy = &rdev->wiphy;
6243 bool found = false;
6244 int band, i;
6245
6246 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6247 struct ieee80211_supported_band *sband;
6248
6249 sband = wiphy->bands[band];
6250 if (!sband)
6251 continue;
6252
6253 for (i = 0; i < sband->n_bitrates; i++) {
6254 if (sband->bitrates[i].bitrate == rateval) {
6255 mcast_rate[band] = i + 1;
6256 found = true;
6257 break;
6258 }
6259 }
6260 }
6261
6262 return found;
6263}
6264
Johannes Berg04a773a2009-04-19 21:24:32 +02006265static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6266{
Johannes Berg4c476992010-10-04 21:36:35 +02006267 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6268 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006269 struct cfg80211_ibss_params ibss;
6270 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006271 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006272 int err;
6273
Johannes Berg8e30bc52009-04-22 17:45:38 +02006274 memset(&ibss, 0, sizeof(ibss));
6275
Johannes Berg04a773a2009-04-19 21:24:32 +02006276 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6277 return -EINVAL;
6278
Johannes Berg683b6d32012-11-08 21:25:48 +01006279 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006280 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6281 return -EINVAL;
6282
Johannes Berg8e30bc52009-04-22 17:45:38 +02006283 ibss.beacon_interval = 100;
6284
6285 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6286 ibss.beacon_interval =
6287 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6288 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6289 return -EINVAL;
6290 }
6291
Johannes Berg4c476992010-10-04 21:36:35 +02006292 if (!rdev->ops->join_ibss)
6293 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006294
Johannes Berg4c476992010-10-04 21:36:35 +02006295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6296 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006297
Johannes Berg79c97e92009-07-07 03:56:12 +02006298 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006299
Johannes Berg39193492011-09-16 13:45:25 +02006300 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006301 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006302
6303 if (!is_valid_ether_addr(ibss.bssid))
6304 return -EINVAL;
6305 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006306 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6307 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6308
6309 if (info->attrs[NL80211_ATTR_IE]) {
6310 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6311 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6312 }
6313
Johannes Berg683b6d32012-11-08 21:25:48 +01006314 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6315 if (err)
6316 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006317
Johannes Berg683b6d32012-11-08 21:25:48 +01006318 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006319 return -EINVAL;
6320
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006321 switch (ibss.chandef.width) {
6322 case NL80211_CHAN_WIDTH_20_NOHT:
6323 break;
6324 case NL80211_CHAN_WIDTH_20:
6325 case NL80211_CHAN_WIDTH_40:
6326 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6327 break;
6328 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006329 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006330 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006331
Johannes Berg04a773a2009-04-19 21:24:32 +02006332 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006333 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006334
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006335 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6336 u8 *rates =
6337 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6338 int n_rates =
6339 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6340 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006341 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006342
Johannes Berg34850ab2011-07-18 18:08:35 +02006343 err = ieee80211_get_ratemask(sband, rates, n_rates,
6344 &ibss.basic_rates);
6345 if (err)
6346 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006347 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006348
6349 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6350 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6351 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6352 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006353
Johannes Berg4c476992010-10-04 21:36:35 +02006354 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306355 bool no_ht = false;
6356
Johannes Berg4c476992010-10-04 21:36:35 +02006357 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306358 info->attrs[NL80211_ATTR_KEYS],
6359 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006360 if (IS_ERR(connkeys))
6361 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306362
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006363 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6364 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306365 kfree(connkeys);
6366 return -EINVAL;
6367 }
Johannes Berg4c476992010-10-04 21:36:35 +02006368 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006369
Antonio Quartulli267335d2012-01-31 20:25:47 +01006370 ibss.control_port =
6371 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6372
Johannes Berg4c476992010-10-04 21:36:35 +02006373 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006374 if (err)
6375 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006376 return err;
6377}
6378
6379static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6380{
Johannes Berg4c476992010-10-04 21:36:35 +02006381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6382 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006383
Johannes Berg4c476992010-10-04 21:36:35 +02006384 if (!rdev->ops->leave_ibss)
6385 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006386
Johannes Berg4c476992010-10-04 21:36:35 +02006387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6388 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006389
Johannes Berg4c476992010-10-04 21:36:35 +02006390 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006391}
6392
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006393static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6394{
6395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6396 struct net_device *dev = info->user_ptr[1];
6397 int mcast_rate[IEEE80211_NUM_BANDS];
6398 u32 nla_rate;
6399 int err;
6400
6401 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6402 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6403 return -EOPNOTSUPP;
6404
6405 if (!rdev->ops->set_mcast_rate)
6406 return -EOPNOTSUPP;
6407
6408 memset(mcast_rate, 0, sizeof(mcast_rate));
6409
6410 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6411 return -EINVAL;
6412
6413 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6414 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6415 return -EINVAL;
6416
6417 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6418
6419 return err;
6420}
6421
6422
Johannes Bergaff89a92009-07-01 21:26:51 +02006423#ifdef CONFIG_NL80211_TESTMODE
6424static struct genl_multicast_group nl80211_testmode_mcgrp = {
6425 .name = "testmode",
6426};
6427
6428static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6429{
Johannes Berg4c476992010-10-04 21:36:35 +02006430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006431 int err;
6432
6433 if (!info->attrs[NL80211_ATTR_TESTDATA])
6434 return -EINVAL;
6435
Johannes Bergaff89a92009-07-01 21:26:51 +02006436 err = -EOPNOTSUPP;
6437 if (rdev->ops->testmode_cmd) {
6438 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006439 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006440 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6441 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6442 rdev->testmode_info = NULL;
6443 }
6444
Johannes Bergaff89a92009-07-01 21:26:51 +02006445 return err;
6446}
6447
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006448static int nl80211_testmode_dump(struct sk_buff *skb,
6449 struct netlink_callback *cb)
6450{
Johannes Berg00918d32011-12-13 17:22:05 +01006451 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006452 int err;
6453 long phy_idx;
6454 void *data = NULL;
6455 int data_len = 0;
6456
Johannes Berg5fe231e2013-05-08 21:45:15 +02006457 rtnl_lock();
6458
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006459 if (cb->args[0]) {
6460 /*
6461 * 0 is a valid index, but not valid for args[0],
6462 * so we need to offset by 1.
6463 */
6464 phy_idx = cb->args[0] - 1;
6465 } else {
6466 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6467 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6468 nl80211_policy);
6469 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006470 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006471
Johannes Berg2bd7e352012-06-15 14:23:16 +02006472 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6473 nl80211_fam.attrbuf);
6474 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006475 err = PTR_ERR(rdev);
6476 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006477 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006478 phy_idx = rdev->wiphy_idx;
6479 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006480
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006481 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6482 cb->args[1] =
6483 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6484 }
6485
6486 if (cb->args[1]) {
6487 data = nla_data((void *)cb->args[1]);
6488 data_len = nla_len((void *)cb->args[1]);
6489 }
6490
Johannes Berg00918d32011-12-13 17:22:05 +01006491 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6492 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006493 err = -ENOENT;
6494 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006495 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006496
Johannes Berg00918d32011-12-13 17:22:05 +01006497 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006498 err = -EOPNOTSUPP;
6499 goto out_err;
6500 }
6501
6502 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006503 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006504 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6505 NL80211_CMD_TESTMODE);
6506 struct nlattr *tmdata;
6507
David S. Miller9360ffd2012-03-29 04:41:26 -04006508 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006509 genlmsg_cancel(skb, hdr);
6510 break;
6511 }
6512
6513 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6514 if (!tmdata) {
6515 genlmsg_cancel(skb, hdr);
6516 break;
6517 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006518 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006519 nla_nest_end(skb, tmdata);
6520
6521 if (err == -ENOBUFS || err == -ENOENT) {
6522 genlmsg_cancel(skb, hdr);
6523 break;
6524 } else if (err) {
6525 genlmsg_cancel(skb, hdr);
6526 goto out_err;
6527 }
6528
6529 genlmsg_end(skb, hdr);
6530 }
6531
6532 err = skb->len;
6533 /* see above */
6534 cb->args[0] = phy_idx + 1;
6535 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006536 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006537 return err;
6538}
6539
Johannes Bergaff89a92009-07-01 21:26:51 +02006540static struct sk_buff *
6541__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006542 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006543{
6544 struct sk_buff *skb;
6545 void *hdr;
6546 struct nlattr *data;
6547
6548 skb = nlmsg_new(approxlen + 100, gfp);
6549 if (!skb)
6550 return NULL;
6551
Eric W. Biederman15e47302012-09-07 20:12:54 +00006552 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006553 if (!hdr) {
6554 kfree_skb(skb);
6555 return NULL;
6556 }
6557
David S. Miller9360ffd2012-03-29 04:41:26 -04006558 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6559 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006560 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6561
6562 ((void **)skb->cb)[0] = rdev;
6563 ((void **)skb->cb)[1] = hdr;
6564 ((void **)skb->cb)[2] = data;
6565
6566 return skb;
6567
6568 nla_put_failure:
6569 kfree_skb(skb);
6570 return NULL;
6571}
6572
6573struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6574 int approxlen)
6575{
6576 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6577
6578 if (WARN_ON(!rdev->testmode_info))
6579 return NULL;
6580
6581 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006582 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006583 rdev->testmode_info->snd_seq,
6584 GFP_KERNEL);
6585}
6586EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6587
6588int cfg80211_testmode_reply(struct sk_buff *skb)
6589{
6590 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6591 void *hdr = ((void **)skb->cb)[1];
6592 struct nlattr *data = ((void **)skb->cb)[2];
6593
6594 if (WARN_ON(!rdev->testmode_info)) {
6595 kfree_skb(skb);
6596 return -EINVAL;
6597 }
6598
6599 nla_nest_end(skb, data);
6600 genlmsg_end(skb, hdr);
6601 return genlmsg_reply(skb, rdev->testmode_info);
6602}
6603EXPORT_SYMBOL(cfg80211_testmode_reply);
6604
6605struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6606 int approxlen, gfp_t gfp)
6607{
6608 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6609
6610 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6611}
6612EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6613
6614void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6615{
6616 void *hdr = ((void **)skb->cb)[1];
6617 struct nlattr *data = ((void **)skb->cb)[2];
6618
6619 nla_nest_end(skb, data);
6620 genlmsg_end(skb, hdr);
6621 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6622}
6623EXPORT_SYMBOL(cfg80211_testmode_event);
6624#endif
6625
Samuel Ortizb23aa672009-07-01 21:26:54 +02006626static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6627{
Johannes Berg4c476992010-10-04 21:36:35 +02006628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6629 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006630 struct cfg80211_connect_params connect;
6631 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006632 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006633 int err;
6634
6635 memset(&connect, 0, sizeof(connect));
6636
6637 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6638 return -EINVAL;
6639
6640 if (!info->attrs[NL80211_ATTR_SSID] ||
6641 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6642 return -EINVAL;
6643
6644 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6645 connect.auth_type =
6646 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006647 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6648 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006649 return -EINVAL;
6650 } else
6651 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6652
6653 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6654
Johannes Bergc0692b82010-08-27 14:26:53 +03006655 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006656 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006657 if (err)
6658 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006659
Johannes Berg074ac8d2010-09-16 14:58:22 +02006660 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006661 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6662 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006663
Johannes Berg79c97e92009-07-07 03:56:12 +02006664 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006665
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306666 connect.bg_scan_period = -1;
6667 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6668 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6669 connect.bg_scan_period =
6670 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6671 }
6672
Samuel Ortizb23aa672009-07-01 21:26:54 +02006673 if (info->attrs[NL80211_ATTR_MAC])
6674 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6675 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6676 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6677
6678 if (info->attrs[NL80211_ATTR_IE]) {
6679 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6680 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6681 }
6682
Jouni Malinencee00a92013-01-15 17:15:57 +02006683 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6684 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6685 if (connect.mfp != NL80211_MFP_REQUIRED &&
6686 connect.mfp != NL80211_MFP_NO)
6687 return -EINVAL;
6688 } else {
6689 connect.mfp = NL80211_MFP_NO;
6690 }
6691
Samuel Ortizb23aa672009-07-01 21:26:54 +02006692 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6693 connect.channel =
6694 ieee80211_get_channel(wiphy,
6695 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6696 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006697 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6698 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006699 }
6700
Johannes Bergfffd0932009-07-08 14:22:54 +02006701 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6702 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306703 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006704 if (IS_ERR(connkeys))
6705 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006706 }
6707
Ben Greear7e7c8922011-11-18 11:31:59 -08006708 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6709 connect.flags |= ASSOC_REQ_DISABLE_HT;
6710
6711 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6712 memcpy(&connect.ht_capa_mask,
6713 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6714 sizeof(connect.ht_capa_mask));
6715
6716 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006717 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6718 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006719 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006720 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006721 memcpy(&connect.ht_capa,
6722 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6723 sizeof(connect.ht_capa));
6724 }
6725
Johannes Bergee2aca32013-02-21 17:36:01 +01006726 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6727 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6728
6729 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6730 memcpy(&connect.vht_capa_mask,
6731 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6732 sizeof(connect.vht_capa_mask));
6733
6734 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6735 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6736 kfree(connkeys);
6737 return -EINVAL;
6738 }
6739 memcpy(&connect.vht_capa,
6740 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6741 sizeof(connect.vht_capa));
6742 }
6743
Johannes Berg83739b02013-05-15 17:44:01 +02006744 wdev_lock(dev->ieee80211_ptr);
6745 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6746 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006747 if (err)
6748 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006749 return err;
6750}
6751
6752static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6753{
Johannes Berg4c476992010-10-04 21:36:35 +02006754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6755 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006756 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006757 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006758
6759 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6760 reason = WLAN_REASON_DEAUTH_LEAVING;
6761 else
6762 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6763
6764 if (reason == 0)
6765 return -EINVAL;
6766
Johannes Berg074ac8d2010-09-16 14:58:22 +02006767 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006768 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6769 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006770
Johannes Berg83739b02013-05-15 17:44:01 +02006771 wdev_lock(dev->ieee80211_ptr);
6772 ret = cfg80211_disconnect(rdev, dev, reason, true);
6773 wdev_unlock(dev->ieee80211_ptr);
6774 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006775}
6776
Johannes Berg463d0182009-07-14 00:33:35 +02006777static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6778{
Johannes Berg4c476992010-10-04 21:36:35 +02006779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006780 struct net *net;
6781 int err;
6782 u32 pid;
6783
6784 if (!info->attrs[NL80211_ATTR_PID])
6785 return -EINVAL;
6786
6787 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6788
Johannes Berg463d0182009-07-14 00:33:35 +02006789 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006790 if (IS_ERR(net))
6791 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006792
6793 err = 0;
6794
6795 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006796 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6797 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006798
Johannes Berg463d0182009-07-14 00:33:35 +02006799 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006800 return err;
6801}
6802
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006803static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6804{
Johannes Berg4c476992010-10-04 21:36:35 +02006805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006806 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6807 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006808 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006809 struct cfg80211_pmksa pmksa;
6810
6811 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6812
6813 if (!info->attrs[NL80211_ATTR_MAC])
6814 return -EINVAL;
6815
6816 if (!info->attrs[NL80211_ATTR_PMKID])
6817 return -EINVAL;
6818
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006819 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6820 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6821
Johannes Berg074ac8d2010-09-16 14:58:22 +02006822 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006823 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6824 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006825
6826 switch (info->genlhdr->cmd) {
6827 case NL80211_CMD_SET_PMKSA:
6828 rdev_ops = rdev->ops->set_pmksa;
6829 break;
6830 case NL80211_CMD_DEL_PMKSA:
6831 rdev_ops = rdev->ops->del_pmksa;
6832 break;
6833 default:
6834 WARN_ON(1);
6835 break;
6836 }
6837
Johannes Berg4c476992010-10-04 21:36:35 +02006838 if (!rdev_ops)
6839 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006840
Johannes Berg4c476992010-10-04 21:36:35 +02006841 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006842}
6843
6844static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6845{
Johannes Berg4c476992010-10-04 21:36:35 +02006846 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6847 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006848
Johannes Berg074ac8d2010-09-16 14:58:22 +02006849 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006850 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6851 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006852
Johannes Berg4c476992010-10-04 21:36:35 +02006853 if (!rdev->ops->flush_pmksa)
6854 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006855
Hila Gonene35e4d22012-06-27 17:19:42 +03006856 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006857}
6858
Arik Nemtsov109086c2011-09-28 14:12:50 +03006859static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6860{
6861 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6862 struct net_device *dev = info->user_ptr[1];
6863 u8 action_code, dialog_token;
6864 u16 status_code;
6865 u8 *peer;
6866
6867 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6868 !rdev->ops->tdls_mgmt)
6869 return -EOPNOTSUPP;
6870
6871 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6872 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6873 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6874 !info->attrs[NL80211_ATTR_IE] ||
6875 !info->attrs[NL80211_ATTR_MAC])
6876 return -EINVAL;
6877
6878 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6879 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6880 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6881 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6882
Hila Gonene35e4d22012-06-27 17:19:42 +03006883 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6884 dialog_token, status_code,
6885 nla_data(info->attrs[NL80211_ATTR_IE]),
6886 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006887}
6888
6889static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6890{
6891 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6892 struct net_device *dev = info->user_ptr[1];
6893 enum nl80211_tdls_operation operation;
6894 u8 *peer;
6895
6896 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6897 !rdev->ops->tdls_oper)
6898 return -EOPNOTSUPP;
6899
6900 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6901 !info->attrs[NL80211_ATTR_MAC])
6902 return -EINVAL;
6903
6904 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6905 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6906
Hila Gonene35e4d22012-06-27 17:19:42 +03006907 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006908}
6909
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006910static int nl80211_remain_on_channel(struct sk_buff *skb,
6911 struct genl_info *info)
6912{
Johannes Berg4c476992010-10-04 21:36:35 +02006913 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006914 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006915 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006916 struct sk_buff *msg;
6917 void *hdr;
6918 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006919 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006920 int err;
6921
6922 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6923 !info->attrs[NL80211_ATTR_DURATION])
6924 return -EINVAL;
6925
6926 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6927
Johannes Berg7c4ef712011-11-18 15:33:48 +01006928 if (!rdev->ops->remain_on_channel ||
6929 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006930 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006931
Johannes Bergebf348f2012-06-01 12:50:54 +02006932 /*
6933 * We should be on that channel for at least a minimum amount of
6934 * time (10ms) but no longer than the driver supports.
6935 */
6936 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6937 duration > rdev->wiphy.max_remain_on_channel_duration)
6938 return -EINVAL;
6939
Johannes Berg683b6d32012-11-08 21:25:48 +01006940 err = nl80211_parse_chandef(rdev, info, &chandef);
6941 if (err)
6942 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006943
6944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006945 if (!msg)
6946 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006947
Eric W. Biederman15e47302012-09-07 20:12:54 +00006948 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006949 NL80211_CMD_REMAIN_ON_CHANNEL);
6950
6951 if (IS_ERR(hdr)) {
6952 err = PTR_ERR(hdr);
6953 goto free_msg;
6954 }
6955
Johannes Berg683b6d32012-11-08 21:25:48 +01006956 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6957 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006958
6959 if (err)
6960 goto free_msg;
6961
David S. Miller9360ffd2012-03-29 04:41:26 -04006962 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6963 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006964
6965 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006966
6967 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006968
6969 nla_put_failure:
6970 err = -ENOBUFS;
6971 free_msg:
6972 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006973 return err;
6974}
6975
6976static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6977 struct genl_info *info)
6978{
Johannes Berg4c476992010-10-04 21:36:35 +02006979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006980 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006981 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006982
6983 if (!info->attrs[NL80211_ATTR_COOKIE])
6984 return -EINVAL;
6985
Johannes Berg4c476992010-10-04 21:36:35 +02006986 if (!rdev->ops->cancel_remain_on_channel)
6987 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006988
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006989 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
6990
Hila Gonene35e4d22012-06-27 17:19:42 +03006991 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006992}
6993
Jouni Malinen13ae75b2009-12-29 12:59:45 +02006994static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
6995 u8 *rates, u8 rates_len)
6996{
6997 u8 i;
6998 u32 mask = 0;
6999
7000 for (i = 0; i < rates_len; i++) {
7001 int rate = (rates[i] & 0x7f) * 5;
7002 int ridx;
7003 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7004 struct ieee80211_rate *srate =
7005 &sband->bitrates[ridx];
7006 if (rate == srate->bitrate) {
7007 mask |= 1 << ridx;
7008 break;
7009 }
7010 }
7011 if (ridx == sband->n_bitrates)
7012 return 0; /* rate not found */
7013 }
7014
7015 return mask;
7016}
7017
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007018static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7019 u8 *rates, u8 rates_len,
7020 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7021{
7022 u8 i;
7023
7024 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7025
7026 for (i = 0; i < rates_len; i++) {
7027 int ridx, rbit;
7028
7029 ridx = rates[i] / 8;
7030 rbit = BIT(rates[i] % 8);
7031
7032 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007033 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007034 return false;
7035
7036 /* check availability */
7037 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7038 mcs[ridx] |= rbit;
7039 else
7040 return false;
7041 }
7042
7043 return true;
7044}
7045
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007046static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007047 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7048 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007049 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7050 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007051};
7052
7053static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7054 struct genl_info *info)
7055{
7056 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007058 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007059 int rem, i;
7060 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007061 struct nlattr *tx_rates;
7062 struct ieee80211_supported_band *sband;
7063
7064 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7065 return -EINVAL;
7066
Johannes Berg4c476992010-10-04 21:36:35 +02007067 if (!rdev->ops->set_bitrate_mask)
7068 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007069
7070 memset(&mask, 0, sizeof(mask));
7071 /* Default to all rates enabled */
7072 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7073 sband = rdev->wiphy.bands[i];
7074 mask.control[i].legacy =
7075 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007076 if (sband)
7077 memcpy(mask.control[i].mcs,
7078 sband->ht_cap.mcs.rx_mask,
7079 sizeof(mask.control[i].mcs));
7080 else
7081 memset(mask.control[i].mcs, 0,
7082 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007083 }
7084
7085 /*
7086 * The nested attribute uses enum nl80211_band as the index. This maps
7087 * directly to the enum ieee80211_band values used in cfg80211.
7088 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007089 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007090 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7091 {
7092 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007093 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7094 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007095 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007096 if (sband == NULL)
7097 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007098 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7099 nla_len(tx_rates), nl80211_txattr_policy);
7100 if (tb[NL80211_TXRATE_LEGACY]) {
7101 mask.control[band].legacy = rateset_to_mask(
7102 sband,
7103 nla_data(tb[NL80211_TXRATE_LEGACY]),
7104 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307105 if ((mask.control[band].legacy == 0) &&
7106 nla_len(tb[NL80211_TXRATE_LEGACY]))
7107 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007108 }
7109 if (tb[NL80211_TXRATE_MCS]) {
7110 if (!ht_rateset_to_mask(
7111 sband,
7112 nla_data(tb[NL80211_TXRATE_MCS]),
7113 nla_len(tb[NL80211_TXRATE_MCS]),
7114 mask.control[band].mcs))
7115 return -EINVAL;
7116 }
7117
7118 if (mask.control[band].legacy == 0) {
7119 /* don't allow empty legacy rates if HT
7120 * is not even supported. */
7121 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7122 return -EINVAL;
7123
7124 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7125 if (mask.control[band].mcs[i])
7126 break;
7127
7128 /* legacy and mcs rates may not be both empty */
7129 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007130 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007131 }
7132 }
7133
Hila Gonene35e4d22012-06-27 17:19:42 +03007134 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007135}
7136
Johannes Berg2e161f72010-08-12 15:38:38 +02007137static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007138{
Johannes Berg4c476992010-10-04 21:36:35 +02007139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007140 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007141 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007142
7143 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7144 return -EINVAL;
7145
Johannes Berg2e161f72010-08-12 15:38:38 +02007146 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7147 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007148
Johannes Berg71bbc992012-06-15 15:30:18 +02007149 switch (wdev->iftype) {
7150 case NL80211_IFTYPE_STATION:
7151 case NL80211_IFTYPE_ADHOC:
7152 case NL80211_IFTYPE_P2P_CLIENT:
7153 case NL80211_IFTYPE_AP:
7154 case NL80211_IFTYPE_AP_VLAN:
7155 case NL80211_IFTYPE_MESH_POINT:
7156 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007157 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007158 break;
7159 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007160 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007161 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007162
7163 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007164 if (!rdev->ops->mgmt_tx)
7165 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007166
Eric W. Biederman15e47302012-09-07 20:12:54 +00007167 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007168 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7169 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007170}
7171
Johannes Berg2e161f72010-08-12 15:38:38 +02007172static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007173{
Johannes Berg4c476992010-10-04 21:36:35 +02007174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007175 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007176 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007177 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007178 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007179 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007180 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007181 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007182 bool offchan, no_cck, dont_wait_for_ack;
7183
7184 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007185
Johannes Berg683b6d32012-11-08 21:25:48 +01007186 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007187 return -EINVAL;
7188
Johannes Berg4c476992010-10-04 21:36:35 +02007189 if (!rdev->ops->mgmt_tx)
7190 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007191
Johannes Berg71bbc992012-06-15 15:30:18 +02007192 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007193 case NL80211_IFTYPE_P2P_DEVICE:
7194 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7195 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007196 case NL80211_IFTYPE_STATION:
7197 case NL80211_IFTYPE_ADHOC:
7198 case NL80211_IFTYPE_P2P_CLIENT:
7199 case NL80211_IFTYPE_AP:
7200 case NL80211_IFTYPE_AP_VLAN:
7201 case NL80211_IFTYPE_MESH_POINT:
7202 case NL80211_IFTYPE_P2P_GO:
7203 break;
7204 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007205 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007206 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007207
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007208 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007209 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007210 return -EINVAL;
7211 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007212
7213 /*
7214 * We should wait on the channel for at least a minimum amount
7215 * of time (10ms) but no longer than the driver supports.
7216 */
7217 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7218 wait > rdev->wiphy.max_remain_on_channel_duration)
7219 return -EINVAL;
7220
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007221 }
7222
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007223 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7224
Johannes Berg7c4ef712011-11-18 15:33:48 +01007225 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7226 return -EINVAL;
7227
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307228 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7229
Antonio Quartulliea141b752013-06-11 14:20:03 +02007230 /* get the channel if any has been specified, otherwise pass NULL to
7231 * the driver. The latter will use the current one
7232 */
7233 chandef.chan = NULL;
7234 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7235 err = nl80211_parse_chandef(rdev, info, &chandef);
7236 if (err)
7237 return err;
7238 }
7239
7240 if (!chandef.chan && offchan)
7241 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007242
Johannes Berge247bd902011-11-04 11:18:21 +01007243 if (!dont_wait_for_ack) {
7244 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7245 if (!msg)
7246 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007247
Eric W. Biederman15e47302012-09-07 20:12:54 +00007248 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007249 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007250
Johannes Berge247bd902011-11-04 11:18:21 +01007251 if (IS_ERR(hdr)) {
7252 err = PTR_ERR(hdr);
7253 goto free_msg;
7254 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007255 }
Johannes Berge247bd902011-11-04 11:18:21 +01007256
Johannes Berg683b6d32012-11-08 21:25:48 +01007257 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007258 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7259 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007260 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007261 if (err)
7262 goto free_msg;
7263
Johannes Berge247bd902011-11-04 11:18:21 +01007264 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007265 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7266 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007267
Johannes Berge247bd902011-11-04 11:18:21 +01007268 genlmsg_end(msg, hdr);
7269 return genlmsg_reply(msg, info);
7270 }
7271
7272 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007273
7274 nla_put_failure:
7275 err = -ENOBUFS;
7276 free_msg:
7277 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007278 return err;
7279}
7280
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007281static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7282{
7283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007284 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007285 u64 cookie;
7286
7287 if (!info->attrs[NL80211_ATTR_COOKIE])
7288 return -EINVAL;
7289
7290 if (!rdev->ops->mgmt_tx_cancel_wait)
7291 return -EOPNOTSUPP;
7292
Johannes Berg71bbc992012-06-15 15:30:18 +02007293 switch (wdev->iftype) {
7294 case NL80211_IFTYPE_STATION:
7295 case NL80211_IFTYPE_ADHOC:
7296 case NL80211_IFTYPE_P2P_CLIENT:
7297 case NL80211_IFTYPE_AP:
7298 case NL80211_IFTYPE_AP_VLAN:
7299 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007300 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007301 break;
7302 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007303 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007304 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007305
7306 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7307
Hila Gonene35e4d22012-06-27 17:19:42 +03007308 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007309}
7310
Kalle Valoffb9eb32010-02-17 17:58:10 +02007311static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7312{
Johannes Berg4c476992010-10-04 21:36:35 +02007313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007314 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007315 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007316 u8 ps_state;
7317 bool state;
7318 int err;
7319
Johannes Berg4c476992010-10-04 21:36:35 +02007320 if (!info->attrs[NL80211_ATTR_PS_STATE])
7321 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007322
7323 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7324
Johannes Berg4c476992010-10-04 21:36:35 +02007325 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7326 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007327
7328 wdev = dev->ieee80211_ptr;
7329
Johannes Berg4c476992010-10-04 21:36:35 +02007330 if (!rdev->ops->set_power_mgmt)
7331 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007332
7333 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7334
7335 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007336 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007337
Hila Gonene35e4d22012-06-27 17:19:42 +03007338 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007339 if (!err)
7340 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007341 return err;
7342}
7343
7344static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7345{
Johannes Berg4c476992010-10-04 21:36:35 +02007346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007347 enum nl80211_ps_state ps_state;
7348 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007349 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007350 struct sk_buff *msg;
7351 void *hdr;
7352 int err;
7353
Kalle Valoffb9eb32010-02-17 17:58:10 +02007354 wdev = dev->ieee80211_ptr;
7355
Johannes Berg4c476992010-10-04 21:36:35 +02007356 if (!rdev->ops->set_power_mgmt)
7357 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007358
7359 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007360 if (!msg)
7361 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007362
Eric W. Biederman15e47302012-09-07 20:12:54 +00007363 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007364 NL80211_CMD_GET_POWER_SAVE);
7365 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007366 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007367 goto free_msg;
7368 }
7369
7370 if (wdev->ps)
7371 ps_state = NL80211_PS_ENABLED;
7372 else
7373 ps_state = NL80211_PS_DISABLED;
7374
David S. Miller9360ffd2012-03-29 04:41:26 -04007375 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7376 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007377
7378 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007379 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007380
Johannes Berg4c476992010-10-04 21:36:35 +02007381 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007382 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007383 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007384 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007385 return err;
7386}
7387
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007388static struct nla_policy
7389nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7390 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7391 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7392 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007393 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7394 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7395 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007396};
7397
Thomas Pedersen84f10702012-07-12 16:17:33 -07007398static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007399 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007400{
7401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7402 struct wireless_dev *wdev;
7403 struct net_device *dev = info->user_ptr[1];
7404
Johannes Bergd9d8b012012-11-26 12:51:52 +01007405 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007406 return -EINVAL;
7407
7408 wdev = dev->ieee80211_ptr;
7409
7410 if (!rdev->ops->set_cqm_txe_config)
7411 return -EOPNOTSUPP;
7412
7413 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7414 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7415 return -EOPNOTSUPP;
7416
Hila Gonene35e4d22012-06-27 17:19:42 +03007417 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007418}
7419
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007420static int nl80211_set_cqm_rssi(struct genl_info *info,
7421 s32 threshold, u32 hysteresis)
7422{
Johannes Berg4c476992010-10-04 21:36:35 +02007423 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007424 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007425 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007426
7427 if (threshold > 0)
7428 return -EINVAL;
7429
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007430 wdev = dev->ieee80211_ptr;
7431
Johannes Berg4c476992010-10-04 21:36:35 +02007432 if (!rdev->ops->set_cqm_rssi_config)
7433 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007434
Johannes Berg074ac8d2010-09-16 14:58:22 +02007435 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007436 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7437 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007438
Hila Gonene35e4d22012-06-27 17:19:42 +03007439 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007440}
7441
7442static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7443{
7444 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7445 struct nlattr *cqm;
7446 int err;
7447
7448 cqm = info->attrs[NL80211_ATTR_CQM];
7449 if (!cqm) {
7450 err = -EINVAL;
7451 goto out;
7452 }
7453
7454 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7455 nl80211_attr_cqm_policy);
7456 if (err)
7457 goto out;
7458
7459 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7460 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7461 s32 threshold;
7462 u32 hysteresis;
7463 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7464 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7465 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007466 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7467 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7468 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7469 u32 rate, pkts, intvl;
7470 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7471 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7472 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7473 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007474 } else
7475 err = -EINVAL;
7476
7477out:
7478 return err;
7479}
7480
Johannes Berg29cbe682010-12-03 09:20:44 +01007481static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7482{
7483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7484 struct net_device *dev = info->user_ptr[1];
7485 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007486 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007487 int err;
7488
7489 /* start with default */
7490 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007491 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007492
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007493 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007494 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007495 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007496 if (err)
7497 return err;
7498 }
7499
7500 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7501 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7502 return -EINVAL;
7503
Javier Cardonac80d5452010-12-16 17:37:49 -08007504 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7505 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7506
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007507 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7508 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7509 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7510 return -EINVAL;
7511
Marco Porsch9bdbf042013-01-07 16:04:51 +01007512 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7513 setup.beacon_interval =
7514 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7515 if (setup.beacon_interval < 10 ||
7516 setup.beacon_interval > 10000)
7517 return -EINVAL;
7518 }
7519
7520 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7521 setup.dtim_period =
7522 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7523 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7524 return -EINVAL;
7525 }
7526
Javier Cardonac80d5452010-12-16 17:37:49 -08007527 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7528 /* parse additional setup parameters if given */
7529 err = nl80211_parse_mesh_setup(info, &setup);
7530 if (err)
7531 return err;
7532 }
7533
Thomas Pedersend37bb182013-03-04 13:06:13 -08007534 if (setup.user_mpm)
7535 cfg.auto_open_plinks = false;
7536
Johannes Bergcc1d2802012-05-16 23:50:20 +02007537 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007538 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7539 if (err)
7540 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007541 } else {
7542 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007543 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007544 }
7545
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007546 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7547 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7548 int n_rates =
7549 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7550 struct ieee80211_supported_band *sband;
7551
7552 if (!setup.chandef.chan)
7553 return -EINVAL;
7554
7555 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7556
7557 err = ieee80211_get_ratemask(sband, rates, n_rates,
7558 &setup.basic_rates);
7559 if (err)
7560 return err;
7561 }
7562
Javier Cardonac80d5452010-12-16 17:37:49 -08007563 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007564}
7565
7566static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7567{
7568 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7569 struct net_device *dev = info->user_ptr[1];
7570
7571 return cfg80211_leave_mesh(rdev, dev);
7572}
7573
Johannes Bergdfb89c52012-06-27 09:23:48 +02007574#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007575static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7576 struct cfg80211_registered_device *rdev)
7577{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007578 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007579 struct nlattr *nl_pats, *nl_pat;
7580 int i, pat_len;
7581
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007582 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007583 return 0;
7584
7585 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7586 if (!nl_pats)
7587 return -ENOBUFS;
7588
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007589 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007590 nl_pat = nla_nest_start(msg, i + 1);
7591 if (!nl_pat)
7592 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007593 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007594 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007595 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007596 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7597 wowlan->patterns[i].pattern) ||
7598 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007599 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007600 return -ENOBUFS;
7601 nla_nest_end(msg, nl_pat);
7602 }
7603 nla_nest_end(msg, nl_pats);
7604
7605 return 0;
7606}
7607
Johannes Berg2a0e0472013-01-23 22:57:40 +01007608static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7609 struct cfg80211_wowlan_tcp *tcp)
7610{
7611 struct nlattr *nl_tcp;
7612
7613 if (!tcp)
7614 return 0;
7615
7616 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7617 if (!nl_tcp)
7618 return -ENOBUFS;
7619
7620 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7621 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7622 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7623 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7624 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7625 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7626 tcp->payload_len, tcp->payload) ||
7627 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7628 tcp->data_interval) ||
7629 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7630 tcp->wake_len, tcp->wake_data) ||
7631 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7632 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7633 return -ENOBUFS;
7634
7635 if (tcp->payload_seq.len &&
7636 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7637 sizeof(tcp->payload_seq), &tcp->payload_seq))
7638 return -ENOBUFS;
7639
7640 if (tcp->payload_tok.len &&
7641 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7642 sizeof(tcp->payload_tok) + tcp->tokens_size,
7643 &tcp->payload_tok))
7644 return -ENOBUFS;
7645
Johannes Berge248ad32013-05-16 10:24:28 +02007646 nla_nest_end(msg, nl_tcp);
7647
Johannes Berg2a0e0472013-01-23 22:57:40 +01007648 return 0;
7649}
7650
Johannes Bergff1b6e62011-05-04 15:37:28 +02007651static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7652{
7653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7654 struct sk_buff *msg;
7655 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007656 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007657
Johannes Berg964dc9e2013-06-03 17:25:34 +02007658 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007659 return -EOPNOTSUPP;
7660
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007661 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007662 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007663 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7664 rdev->wiphy.wowlan_config->tcp->payload_len +
7665 rdev->wiphy.wowlan_config->tcp->wake_len +
7666 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007667 }
7668
7669 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007670 if (!msg)
7671 return -ENOMEM;
7672
Eric W. Biederman15e47302012-09-07 20:12:54 +00007673 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007674 NL80211_CMD_GET_WOWLAN);
7675 if (!hdr)
7676 goto nla_put_failure;
7677
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007678 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007679 struct nlattr *nl_wowlan;
7680
7681 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7682 if (!nl_wowlan)
7683 goto nla_put_failure;
7684
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007685 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007686 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007687 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007688 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007689 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007690 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007691 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007692 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007693 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007694 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007695 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007696 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007697 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007698 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7699 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007700
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007701 if (nl80211_send_wowlan_patterns(msg, rdev))
7702 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007703
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007704 if (nl80211_send_wowlan_tcp(msg,
7705 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007706 goto nla_put_failure;
7707
Johannes Bergff1b6e62011-05-04 15:37:28 +02007708 nla_nest_end(msg, nl_wowlan);
7709 }
7710
7711 genlmsg_end(msg, hdr);
7712 return genlmsg_reply(msg, info);
7713
7714nla_put_failure:
7715 nlmsg_free(msg);
7716 return -ENOBUFS;
7717}
7718
Johannes Berg2a0e0472013-01-23 22:57:40 +01007719static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7720 struct nlattr *attr,
7721 struct cfg80211_wowlan *trig)
7722{
7723 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7724 struct cfg80211_wowlan_tcp *cfg;
7725 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7726 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7727 u32 size;
7728 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7729 int err, port;
7730
Johannes Berg964dc9e2013-06-03 17:25:34 +02007731 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007732 return -EINVAL;
7733
7734 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7735 nla_data(attr), nla_len(attr),
7736 nl80211_wowlan_tcp_policy);
7737 if (err)
7738 return err;
7739
7740 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7741 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7742 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7743 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7744 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7745 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7746 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7747 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7748 return -EINVAL;
7749
7750 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007751 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007752 return -EINVAL;
7753
7754 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007755 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007756 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007757 return -EINVAL;
7758
7759 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007760 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007761 return -EINVAL;
7762
7763 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7764 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7765 return -EINVAL;
7766
7767 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7768 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7769
7770 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7771 tokens_size = tokln - sizeof(*tok);
7772
7773 if (!tok->len || tokens_size % tok->len)
7774 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007775 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007776 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007777 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007778 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007779 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007780 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007781 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007782 return -EINVAL;
7783 if (tok->offset + tok->len > data_size)
7784 return -EINVAL;
7785 }
7786
7787 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7788 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007789 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007790 return -EINVAL;
7791 if (seq->len == 0 || seq->len > 4)
7792 return -EINVAL;
7793 if (seq->len + seq->offset > data_size)
7794 return -EINVAL;
7795 }
7796
7797 size = sizeof(*cfg);
7798 size += data_size;
7799 size += wake_size + wake_mask_size;
7800 size += tokens_size;
7801
7802 cfg = kzalloc(size, GFP_KERNEL);
7803 if (!cfg)
7804 return -ENOMEM;
7805 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7806 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7807 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7808 ETH_ALEN);
7809 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7810 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7811 else
7812 port = 0;
7813#ifdef CONFIG_INET
7814 /* allocate a socket and port for it and use it */
7815 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7816 IPPROTO_TCP, &cfg->sock, 1);
7817 if (err) {
7818 kfree(cfg);
7819 return err;
7820 }
7821 if (inet_csk_get_port(cfg->sock->sk, port)) {
7822 sock_release(cfg->sock);
7823 kfree(cfg);
7824 return -EADDRINUSE;
7825 }
7826 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7827#else
7828 if (!port) {
7829 kfree(cfg);
7830 return -EINVAL;
7831 }
7832 cfg->src_port = port;
7833#endif
7834
7835 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7836 cfg->payload_len = data_size;
7837 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7838 memcpy((void *)cfg->payload,
7839 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7840 data_size);
7841 if (seq)
7842 cfg->payload_seq = *seq;
7843 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7844 cfg->wake_len = wake_size;
7845 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7846 memcpy((void *)cfg->wake_data,
7847 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7848 wake_size);
7849 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7850 data_size + wake_size;
7851 memcpy((void *)cfg->wake_mask,
7852 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7853 wake_mask_size);
7854 if (tok) {
7855 cfg->tokens_size = tokens_size;
7856 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7857 }
7858
7859 trig->tcp = cfg;
7860
7861 return 0;
7862}
7863
Johannes Bergff1b6e62011-05-04 15:37:28 +02007864static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7865{
7866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7867 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007868 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007869 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007870 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007871 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007872 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007873
Johannes Berg964dc9e2013-06-03 17:25:34 +02007874 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007875 return -EOPNOTSUPP;
7876
Johannes Bergae33bd82012-07-12 16:25:02 +02007877 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7878 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007879 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007880 goto set_wakeup;
7881 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007882
7883 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7884 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7885 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7886 nl80211_wowlan_policy);
7887 if (err)
7888 return err;
7889
7890 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7891 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7892 return -EINVAL;
7893 new_triggers.any = true;
7894 }
7895
7896 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7897 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7898 return -EINVAL;
7899 new_triggers.disconnect = true;
7900 }
7901
7902 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7903 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7904 return -EINVAL;
7905 new_triggers.magic_pkt = true;
7906 }
7907
Johannes Berg77dbbb12011-07-13 10:48:55 +02007908 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7909 return -EINVAL;
7910
7911 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7912 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7913 return -EINVAL;
7914 new_triggers.gtk_rekey_failure = true;
7915 }
7916
7917 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7918 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7919 return -EINVAL;
7920 new_triggers.eap_identity_req = true;
7921 }
7922
7923 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7924 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7925 return -EINVAL;
7926 new_triggers.four_way_handshake = true;
7927 }
7928
7929 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7930 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7931 return -EINVAL;
7932 new_triggers.rfkill_release = true;
7933 }
7934
Johannes Bergff1b6e62011-05-04 15:37:28 +02007935 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7936 struct nlattr *pat;
7937 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007938 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007939 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007940
7941 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7942 rem)
7943 n_patterns++;
7944 if (n_patterns > wowlan->n_patterns)
7945 return -EINVAL;
7946
7947 new_triggers.patterns = kcalloc(n_patterns,
7948 sizeof(new_triggers.patterns[0]),
7949 GFP_KERNEL);
7950 if (!new_triggers.patterns)
7951 return -ENOMEM;
7952
7953 new_triggers.n_patterns = n_patterns;
7954 i = 0;
7955
7956 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7957 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007958 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
7959 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007960 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007961 if (!pat_tb[NL80211_PKTPAT_MASK] ||
7962 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02007963 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007964 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007965 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007966 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007967 goto error;
7968 if (pat_len > wowlan->pattern_max_len ||
7969 pat_len < wowlan->pattern_min_len)
7970 goto error;
7971
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007972 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007973 pkt_offset = 0;
7974 else
7975 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007976 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007977 if (pkt_offset > wowlan->max_pkt_offset)
7978 goto error;
7979 new_triggers.patterns[i].pkt_offset = pkt_offset;
7980
Johannes Bergff1b6e62011-05-04 15:37:28 +02007981 new_triggers.patterns[i].mask =
7982 kmalloc(mask_len + pat_len, GFP_KERNEL);
7983 if (!new_triggers.patterns[i].mask) {
7984 err = -ENOMEM;
7985 goto error;
7986 }
7987 new_triggers.patterns[i].pattern =
7988 new_triggers.patterns[i].mask + mask_len;
7989 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007990 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02007991 mask_len);
7992 new_triggers.patterns[i].pattern_len = pat_len;
7993 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007994 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02007995 pat_len);
7996 i++;
7997 }
7998 }
7999
Johannes Berg2a0e0472013-01-23 22:57:40 +01008000 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8001 err = nl80211_parse_wowlan_tcp(
8002 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8003 &new_triggers);
8004 if (err)
8005 goto error;
8006 }
8007
Johannes Bergae33bd82012-07-12 16:25:02 +02008008 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8009 if (!ntrig) {
8010 err = -ENOMEM;
8011 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008012 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008013 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008014 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008015
Johannes Bergae33bd82012-07-12 16:25:02 +02008016 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008017 if (rdev->ops->set_wakeup &&
8018 prev_enabled != !!rdev->wiphy.wowlan_config)
8019 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008020
Johannes Bergff1b6e62011-05-04 15:37:28 +02008021 return 0;
8022 error:
8023 for (i = 0; i < new_triggers.n_patterns; i++)
8024 kfree(new_triggers.patterns[i].mask);
8025 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008026 if (new_triggers.tcp && new_triggers.tcp->sock)
8027 sock_release(new_triggers.tcp->sock);
8028 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008029 return err;
8030}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008031#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008032
Johannes Berge5497d72011-07-05 16:35:40 +02008033static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8034{
8035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8036 struct net_device *dev = info->user_ptr[1];
8037 struct wireless_dev *wdev = dev->ieee80211_ptr;
8038 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8039 struct cfg80211_gtk_rekey_data rekey_data;
8040 int err;
8041
8042 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8043 return -EINVAL;
8044
8045 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8046 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8047 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8048 nl80211_rekey_policy);
8049 if (err)
8050 return err;
8051
8052 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8053 return -ERANGE;
8054 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8055 return -ERANGE;
8056 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8057 return -ERANGE;
8058
8059 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8060 NL80211_KEK_LEN);
8061 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8062 NL80211_KCK_LEN);
8063 memcpy(rekey_data.replay_ctr,
8064 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8065 NL80211_REPLAY_CTR_LEN);
8066
8067 wdev_lock(wdev);
8068 if (!wdev->current_bss) {
8069 err = -ENOTCONN;
8070 goto out;
8071 }
8072
8073 if (!rdev->ops->set_rekey_data) {
8074 err = -EOPNOTSUPP;
8075 goto out;
8076 }
8077
Hila Gonene35e4d22012-06-27 17:19:42 +03008078 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008079 out:
8080 wdev_unlock(wdev);
8081 return err;
8082}
8083
Johannes Berg28946da2011-11-04 11:18:12 +01008084static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8085 struct genl_info *info)
8086{
8087 struct net_device *dev = info->user_ptr[1];
8088 struct wireless_dev *wdev = dev->ieee80211_ptr;
8089
8090 if (wdev->iftype != NL80211_IFTYPE_AP &&
8091 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8092 return -EINVAL;
8093
Eric W. Biederman15e47302012-09-07 20:12:54 +00008094 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008095 return -EBUSY;
8096
Eric W. Biederman15e47302012-09-07 20:12:54 +00008097 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008098 return 0;
8099}
8100
Johannes Berg7f6cf312011-11-04 11:18:15 +01008101static int nl80211_probe_client(struct sk_buff *skb,
8102 struct genl_info *info)
8103{
8104 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8105 struct net_device *dev = info->user_ptr[1];
8106 struct wireless_dev *wdev = dev->ieee80211_ptr;
8107 struct sk_buff *msg;
8108 void *hdr;
8109 const u8 *addr;
8110 u64 cookie;
8111 int err;
8112
8113 if (wdev->iftype != NL80211_IFTYPE_AP &&
8114 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8115 return -EOPNOTSUPP;
8116
8117 if (!info->attrs[NL80211_ATTR_MAC])
8118 return -EINVAL;
8119
8120 if (!rdev->ops->probe_client)
8121 return -EOPNOTSUPP;
8122
8123 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8124 if (!msg)
8125 return -ENOMEM;
8126
Eric W. Biederman15e47302012-09-07 20:12:54 +00008127 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008128 NL80211_CMD_PROBE_CLIENT);
8129
8130 if (IS_ERR(hdr)) {
8131 err = PTR_ERR(hdr);
8132 goto free_msg;
8133 }
8134
8135 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8136
Hila Gonene35e4d22012-06-27 17:19:42 +03008137 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008138 if (err)
8139 goto free_msg;
8140
David S. Miller9360ffd2012-03-29 04:41:26 -04008141 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8142 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008143
8144 genlmsg_end(msg, hdr);
8145
8146 return genlmsg_reply(msg, info);
8147
8148 nla_put_failure:
8149 err = -ENOBUFS;
8150 free_msg:
8151 nlmsg_free(msg);
8152 return err;
8153}
8154
Johannes Berg5e7602302011-11-04 11:18:17 +01008155static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8156{
8157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008158 struct cfg80211_beacon_registration *reg, *nreg;
8159 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008160
8161 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8162 return -EOPNOTSUPP;
8163
Ben Greear37c73b52012-10-26 14:49:25 -07008164 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8165 if (!nreg)
8166 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008167
Ben Greear37c73b52012-10-26 14:49:25 -07008168 /* First, check if already registered. */
8169 spin_lock_bh(&rdev->beacon_registrations_lock);
8170 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8171 if (reg->nlportid == info->snd_portid) {
8172 rv = -EALREADY;
8173 goto out_err;
8174 }
8175 }
8176 /* Add it to the list */
8177 nreg->nlportid = info->snd_portid;
8178 list_add(&nreg->list, &rdev->beacon_registrations);
8179
8180 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008181
8182 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008183out_err:
8184 spin_unlock_bh(&rdev->beacon_registrations_lock);
8185 kfree(nreg);
8186 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008187}
8188
Johannes Berg98104fde2012-06-16 00:19:54 +02008189static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8190{
8191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8192 struct wireless_dev *wdev = info->user_ptr[1];
8193 int err;
8194
8195 if (!rdev->ops->start_p2p_device)
8196 return -EOPNOTSUPP;
8197
8198 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8199 return -EOPNOTSUPP;
8200
8201 if (wdev->p2p_started)
8202 return 0;
8203
Johannes Berg98104fde2012-06-16 00:19:54 +02008204 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008205 if (err)
8206 return err;
8207
Johannes Bergeeb126e2012-10-23 15:16:50 +02008208 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008209 if (err)
8210 return err;
8211
8212 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008213 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008214
8215 return 0;
8216}
8217
8218static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8219{
8220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8221 struct wireless_dev *wdev = info->user_ptr[1];
8222
8223 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8224 return -EOPNOTSUPP;
8225
8226 if (!rdev->ops->stop_p2p_device)
8227 return -EOPNOTSUPP;
8228
Johannes Bergf9f47522013-03-19 15:04:07 +01008229 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008230
8231 return 0;
8232}
8233
Johannes Berg3713b4e2013-02-14 16:19:38 +01008234static int nl80211_get_protocol_features(struct sk_buff *skb,
8235 struct genl_info *info)
8236{
8237 void *hdr;
8238 struct sk_buff *msg;
8239
8240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8241 if (!msg)
8242 return -ENOMEM;
8243
8244 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8245 NL80211_CMD_GET_PROTOCOL_FEATURES);
8246 if (!hdr)
8247 goto nla_put_failure;
8248
8249 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8250 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8251 goto nla_put_failure;
8252
8253 genlmsg_end(msg, hdr);
8254 return genlmsg_reply(msg, info);
8255
8256 nla_put_failure:
8257 kfree_skb(msg);
8258 return -ENOBUFS;
8259}
8260
Jouni Malinen355199e2013-02-27 17:14:27 +02008261static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8262{
8263 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8264 struct cfg80211_update_ft_ies_params ft_params;
8265 struct net_device *dev = info->user_ptr[1];
8266
8267 if (!rdev->ops->update_ft_ies)
8268 return -EOPNOTSUPP;
8269
8270 if (!info->attrs[NL80211_ATTR_MDID] ||
8271 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8272 return -EINVAL;
8273
8274 memset(&ft_params, 0, sizeof(ft_params));
8275 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8276 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8277 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8278
8279 return rdev_update_ft_ies(rdev, dev, &ft_params);
8280}
8281
Arend van Spriel5de17982013-04-18 15:49:00 +02008282static int nl80211_crit_protocol_start(struct sk_buff *skb,
8283 struct genl_info *info)
8284{
8285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8286 struct wireless_dev *wdev = info->user_ptr[1];
8287 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8288 u16 duration;
8289 int ret;
8290
8291 if (!rdev->ops->crit_proto_start)
8292 return -EOPNOTSUPP;
8293
8294 if (WARN_ON(!rdev->ops->crit_proto_stop))
8295 return -EINVAL;
8296
8297 if (rdev->crit_proto_nlportid)
8298 return -EBUSY;
8299
8300 /* determine protocol if provided */
8301 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8302 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8303
8304 if (proto >= NUM_NL80211_CRIT_PROTO)
8305 return -EINVAL;
8306
8307 /* timeout must be provided */
8308 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8309 return -EINVAL;
8310
8311 duration =
8312 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8313
8314 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8315 return -ERANGE;
8316
8317 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8318 if (!ret)
8319 rdev->crit_proto_nlportid = info->snd_portid;
8320
8321 return ret;
8322}
8323
8324static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8325 struct genl_info *info)
8326{
8327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8328 struct wireless_dev *wdev = info->user_ptr[1];
8329
8330 if (!rdev->ops->crit_proto_stop)
8331 return -EOPNOTSUPP;
8332
8333 if (rdev->crit_proto_nlportid) {
8334 rdev->crit_proto_nlportid = 0;
8335 rdev_crit_proto_stop(rdev, wdev);
8336 }
8337 return 0;
8338}
8339
Johannes Berg4c476992010-10-04 21:36:35 +02008340#define NL80211_FLAG_NEED_WIPHY 0x01
8341#define NL80211_FLAG_NEED_NETDEV 0x02
8342#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008343#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8344#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8345 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008346#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008347/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008348#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8349 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008350
8351static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8352 struct genl_info *info)
8353{
8354 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008355 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008356 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008357 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8358
8359 if (rtnl)
8360 rtnl_lock();
8361
8362 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008363 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008364 if (IS_ERR(rdev)) {
8365 if (rtnl)
8366 rtnl_unlock();
8367 return PTR_ERR(rdev);
8368 }
8369 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008370 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8371 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008372 ASSERT_RTNL();
8373
Johannes Berg89a54e42012-06-15 14:33:17 +02008374 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8375 info->attrs);
8376 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008377 if (rtnl)
8378 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008379 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008380 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008381
Johannes Berg89a54e42012-06-15 14:33:17 +02008382 dev = wdev->netdev;
8383 rdev = wiphy_to_dev(wdev->wiphy);
8384
Johannes Berg1bf614e2012-06-15 15:23:36 +02008385 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8386 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008387 if (rtnl)
8388 rtnl_unlock();
8389 return -EINVAL;
8390 }
8391
8392 info->user_ptr[1] = dev;
8393 } else {
8394 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008395 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008396
Johannes Berg1bf614e2012-06-15 15:23:36 +02008397 if (dev) {
8398 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8399 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008400 if (rtnl)
8401 rtnl_unlock();
8402 return -ENETDOWN;
8403 }
8404
8405 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008406 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8407 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008408 if (rtnl)
8409 rtnl_unlock();
8410 return -ENETDOWN;
8411 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008412 }
8413
Johannes Berg4c476992010-10-04 21:36:35 +02008414 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008415 }
8416
8417 return 0;
8418}
8419
8420static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8421 struct genl_info *info)
8422{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008423 if (info->user_ptr[1]) {
8424 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8425 struct wireless_dev *wdev = info->user_ptr[1];
8426
8427 if (wdev->netdev)
8428 dev_put(wdev->netdev);
8429 } else {
8430 dev_put(info->user_ptr[1]);
8431 }
8432 }
Johannes Berg4c476992010-10-04 21:36:35 +02008433 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8434 rtnl_unlock();
8435}
8436
Johannes Berg55682962007-09-20 13:09:35 -04008437static struct genl_ops nl80211_ops[] = {
8438 {
8439 .cmd = NL80211_CMD_GET_WIPHY,
8440 .doit = nl80211_get_wiphy,
8441 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008442 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008443 .policy = nl80211_policy,
8444 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008445 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8446 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008447 },
8448 {
8449 .cmd = NL80211_CMD_SET_WIPHY,
8450 .doit = nl80211_set_wiphy,
8451 .policy = nl80211_policy,
8452 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008453 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008454 },
8455 {
8456 .cmd = NL80211_CMD_GET_INTERFACE,
8457 .doit = nl80211_get_interface,
8458 .dumpit = nl80211_dump_interface,
8459 .policy = nl80211_policy,
8460 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008461 .internal_flags = NL80211_FLAG_NEED_WDEV |
8462 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008463 },
8464 {
8465 .cmd = NL80211_CMD_SET_INTERFACE,
8466 .doit = nl80211_set_interface,
8467 .policy = nl80211_policy,
8468 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008469 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8470 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008471 },
8472 {
8473 .cmd = NL80211_CMD_NEW_INTERFACE,
8474 .doit = nl80211_new_interface,
8475 .policy = nl80211_policy,
8476 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008477 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8478 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008479 },
8480 {
8481 .cmd = NL80211_CMD_DEL_INTERFACE,
8482 .doit = nl80211_del_interface,
8483 .policy = nl80211_policy,
8484 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008485 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008486 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008487 },
Johannes Berg41ade002007-12-19 02:03:29 +01008488 {
8489 .cmd = NL80211_CMD_GET_KEY,
8490 .doit = nl80211_get_key,
8491 .policy = nl80211_policy,
8492 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008494 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008495 },
8496 {
8497 .cmd = NL80211_CMD_SET_KEY,
8498 .doit = nl80211_set_key,
8499 .policy = nl80211_policy,
8500 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008502 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008503 },
8504 {
8505 .cmd = NL80211_CMD_NEW_KEY,
8506 .doit = nl80211_new_key,
8507 .policy = nl80211_policy,
8508 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008510 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008511 },
8512 {
8513 .cmd = NL80211_CMD_DEL_KEY,
8514 .doit = nl80211_del_key,
8515 .policy = nl80211_policy,
8516 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008518 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008519 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008520 {
8521 .cmd = NL80211_CMD_SET_BEACON,
8522 .policy = nl80211_policy,
8523 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008524 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008526 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008527 },
8528 {
Johannes Berg88600202012-02-13 15:17:18 +01008529 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008530 .policy = nl80211_policy,
8531 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008532 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008534 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008535 },
8536 {
Johannes Berg88600202012-02-13 15:17:18 +01008537 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008538 .policy = nl80211_policy,
8539 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008540 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008541 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008542 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008543 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008544 {
8545 .cmd = NL80211_CMD_GET_STATION,
8546 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008547 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008548 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008549 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8550 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008551 },
8552 {
8553 .cmd = NL80211_CMD_SET_STATION,
8554 .doit = nl80211_set_station,
8555 .policy = nl80211_policy,
8556 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008557 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008558 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008559 },
8560 {
8561 .cmd = NL80211_CMD_NEW_STATION,
8562 .doit = nl80211_new_station,
8563 .policy = nl80211_policy,
8564 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008565 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008566 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008567 },
8568 {
8569 .cmd = NL80211_CMD_DEL_STATION,
8570 .doit = nl80211_del_station,
8571 .policy = nl80211_policy,
8572 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008573 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008574 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008575 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008576 {
8577 .cmd = NL80211_CMD_GET_MPATH,
8578 .doit = nl80211_get_mpath,
8579 .dumpit = nl80211_dump_mpath,
8580 .policy = nl80211_policy,
8581 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008582 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008583 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008584 },
8585 {
8586 .cmd = NL80211_CMD_SET_MPATH,
8587 .doit = nl80211_set_mpath,
8588 .policy = nl80211_policy,
8589 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008591 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008592 },
8593 {
8594 .cmd = NL80211_CMD_NEW_MPATH,
8595 .doit = nl80211_new_mpath,
8596 .policy = nl80211_policy,
8597 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008599 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008600 },
8601 {
8602 .cmd = NL80211_CMD_DEL_MPATH,
8603 .doit = nl80211_del_mpath,
8604 .policy = nl80211_policy,
8605 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008607 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008608 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008609 {
8610 .cmd = NL80211_CMD_SET_BSS,
8611 .doit = nl80211_set_bss,
8612 .policy = nl80211_policy,
8613 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008615 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008616 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008617 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008618 .cmd = NL80211_CMD_GET_REG,
8619 .doit = nl80211_get_reg,
8620 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008621 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008622 /* can be retrieved by unprivileged users */
8623 },
8624 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008625 .cmd = NL80211_CMD_SET_REG,
8626 .doit = nl80211_set_reg,
8627 .policy = nl80211_policy,
8628 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008629 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008630 },
8631 {
8632 .cmd = NL80211_CMD_REQ_SET_REG,
8633 .doit = nl80211_req_set_reg,
8634 .policy = nl80211_policy,
8635 .flags = GENL_ADMIN_PERM,
8636 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008637 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008638 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8639 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008640 .policy = nl80211_policy,
8641 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008643 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008644 },
8645 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008646 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8647 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008648 .policy = nl80211_policy,
8649 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008650 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008651 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008652 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008653 {
Johannes Berg2a519312009-02-10 21:25:55 +01008654 .cmd = NL80211_CMD_TRIGGER_SCAN,
8655 .doit = nl80211_trigger_scan,
8656 .policy = nl80211_policy,
8657 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008658 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008659 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008660 },
8661 {
8662 .cmd = NL80211_CMD_GET_SCAN,
8663 .policy = nl80211_policy,
8664 .dumpit = nl80211_dump_scan,
8665 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008666 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008667 .cmd = NL80211_CMD_START_SCHED_SCAN,
8668 .doit = nl80211_start_sched_scan,
8669 .policy = nl80211_policy,
8670 .flags = GENL_ADMIN_PERM,
8671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8672 NL80211_FLAG_NEED_RTNL,
8673 },
8674 {
8675 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8676 .doit = nl80211_stop_sched_scan,
8677 .policy = nl80211_policy,
8678 .flags = GENL_ADMIN_PERM,
8679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8680 NL80211_FLAG_NEED_RTNL,
8681 },
8682 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008683 .cmd = NL80211_CMD_AUTHENTICATE,
8684 .doit = nl80211_authenticate,
8685 .policy = nl80211_policy,
8686 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008688 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008689 },
8690 {
8691 .cmd = NL80211_CMD_ASSOCIATE,
8692 .doit = nl80211_associate,
8693 .policy = nl80211_policy,
8694 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008695 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008696 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008697 },
8698 {
8699 .cmd = NL80211_CMD_DEAUTHENTICATE,
8700 .doit = nl80211_deauthenticate,
8701 .policy = nl80211_policy,
8702 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008703 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008704 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008705 },
8706 {
8707 .cmd = NL80211_CMD_DISASSOCIATE,
8708 .doit = nl80211_disassociate,
8709 .policy = nl80211_policy,
8710 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008712 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008713 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008714 {
8715 .cmd = NL80211_CMD_JOIN_IBSS,
8716 .doit = nl80211_join_ibss,
8717 .policy = nl80211_policy,
8718 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008720 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008721 },
8722 {
8723 .cmd = NL80211_CMD_LEAVE_IBSS,
8724 .doit = nl80211_leave_ibss,
8725 .policy = nl80211_policy,
8726 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008727 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008728 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008729 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008730#ifdef CONFIG_NL80211_TESTMODE
8731 {
8732 .cmd = NL80211_CMD_TESTMODE,
8733 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008734 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008735 .policy = nl80211_policy,
8736 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008737 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8738 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008739 },
8740#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008741 {
8742 .cmd = NL80211_CMD_CONNECT,
8743 .doit = nl80211_connect,
8744 .policy = nl80211_policy,
8745 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008747 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008748 },
8749 {
8750 .cmd = NL80211_CMD_DISCONNECT,
8751 .doit = nl80211_disconnect,
8752 .policy = nl80211_policy,
8753 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008754 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008755 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008756 },
Johannes Berg463d0182009-07-14 00:33:35 +02008757 {
8758 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8759 .doit = nl80211_wiphy_netns,
8760 .policy = nl80211_policy,
8761 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008762 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8763 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008764 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008765 {
8766 .cmd = NL80211_CMD_GET_SURVEY,
8767 .policy = nl80211_policy,
8768 .dumpit = nl80211_dump_survey,
8769 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008770 {
8771 .cmd = NL80211_CMD_SET_PMKSA,
8772 .doit = nl80211_setdel_pmksa,
8773 .policy = nl80211_policy,
8774 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008775 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008776 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008777 },
8778 {
8779 .cmd = NL80211_CMD_DEL_PMKSA,
8780 .doit = nl80211_setdel_pmksa,
8781 .policy = nl80211_policy,
8782 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008783 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008784 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008785 },
8786 {
8787 .cmd = NL80211_CMD_FLUSH_PMKSA,
8788 .doit = nl80211_flush_pmksa,
8789 .policy = nl80211_policy,
8790 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008791 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008792 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008793 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008794 {
8795 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8796 .doit = nl80211_remain_on_channel,
8797 .policy = nl80211_policy,
8798 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008799 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008800 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008801 },
8802 {
8803 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8804 .doit = nl80211_cancel_remain_on_channel,
8805 .policy = nl80211_policy,
8806 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008807 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008808 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008809 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008810 {
8811 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8812 .doit = nl80211_set_tx_bitrate_mask,
8813 .policy = nl80211_policy,
8814 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008815 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8816 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008817 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008818 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008819 .cmd = NL80211_CMD_REGISTER_FRAME,
8820 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008821 .policy = nl80211_policy,
8822 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008823 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008824 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008825 },
8826 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008827 .cmd = NL80211_CMD_FRAME,
8828 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008829 .policy = nl80211_policy,
8830 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008831 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008832 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008833 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008834 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008835 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8836 .doit = nl80211_tx_mgmt_cancel_wait,
8837 .policy = nl80211_policy,
8838 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008839 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008840 NL80211_FLAG_NEED_RTNL,
8841 },
8842 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008843 .cmd = NL80211_CMD_SET_POWER_SAVE,
8844 .doit = nl80211_set_power_save,
8845 .policy = nl80211_policy,
8846 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008847 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8848 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008849 },
8850 {
8851 .cmd = NL80211_CMD_GET_POWER_SAVE,
8852 .doit = nl80211_get_power_save,
8853 .policy = nl80211_policy,
8854 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008855 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8856 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008857 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008858 {
8859 .cmd = NL80211_CMD_SET_CQM,
8860 .doit = nl80211_set_cqm,
8861 .policy = nl80211_policy,
8862 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008863 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8864 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008865 },
Johannes Bergf444de02010-05-05 15:25:02 +02008866 {
8867 .cmd = NL80211_CMD_SET_CHANNEL,
8868 .doit = nl80211_set_channel,
8869 .policy = nl80211_policy,
8870 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008871 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8872 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008873 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008874 {
8875 .cmd = NL80211_CMD_SET_WDS_PEER,
8876 .doit = nl80211_set_wds_peer,
8877 .policy = nl80211_policy,
8878 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008879 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8880 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008881 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008882 {
8883 .cmd = NL80211_CMD_JOIN_MESH,
8884 .doit = nl80211_join_mesh,
8885 .policy = nl80211_policy,
8886 .flags = GENL_ADMIN_PERM,
8887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8888 NL80211_FLAG_NEED_RTNL,
8889 },
8890 {
8891 .cmd = NL80211_CMD_LEAVE_MESH,
8892 .doit = nl80211_leave_mesh,
8893 .policy = nl80211_policy,
8894 .flags = GENL_ADMIN_PERM,
8895 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8896 NL80211_FLAG_NEED_RTNL,
8897 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008898#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008899 {
8900 .cmd = NL80211_CMD_GET_WOWLAN,
8901 .doit = nl80211_get_wowlan,
8902 .policy = nl80211_policy,
8903 /* can be retrieved by unprivileged users */
8904 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8905 NL80211_FLAG_NEED_RTNL,
8906 },
8907 {
8908 .cmd = NL80211_CMD_SET_WOWLAN,
8909 .doit = nl80211_set_wowlan,
8910 .policy = nl80211_policy,
8911 .flags = GENL_ADMIN_PERM,
8912 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8913 NL80211_FLAG_NEED_RTNL,
8914 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008915#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008916 {
8917 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8918 .doit = nl80211_set_rekey_data,
8919 .policy = nl80211_policy,
8920 .flags = GENL_ADMIN_PERM,
8921 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8922 NL80211_FLAG_NEED_RTNL,
8923 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008924 {
8925 .cmd = NL80211_CMD_TDLS_MGMT,
8926 .doit = nl80211_tdls_mgmt,
8927 .policy = nl80211_policy,
8928 .flags = GENL_ADMIN_PERM,
8929 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8930 NL80211_FLAG_NEED_RTNL,
8931 },
8932 {
8933 .cmd = NL80211_CMD_TDLS_OPER,
8934 .doit = nl80211_tdls_oper,
8935 .policy = nl80211_policy,
8936 .flags = GENL_ADMIN_PERM,
8937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8938 NL80211_FLAG_NEED_RTNL,
8939 },
Johannes Berg28946da2011-11-04 11:18:12 +01008940 {
8941 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8942 .doit = nl80211_register_unexpected_frame,
8943 .policy = nl80211_policy,
8944 .flags = GENL_ADMIN_PERM,
8945 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8946 NL80211_FLAG_NEED_RTNL,
8947 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008948 {
8949 .cmd = NL80211_CMD_PROBE_CLIENT,
8950 .doit = nl80211_probe_client,
8951 .policy = nl80211_policy,
8952 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008953 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008954 NL80211_FLAG_NEED_RTNL,
8955 },
Johannes Berg5e7602302011-11-04 11:18:17 +01008956 {
8957 .cmd = NL80211_CMD_REGISTER_BEACONS,
8958 .doit = nl80211_register_beacons,
8959 .policy = nl80211_policy,
8960 .flags = GENL_ADMIN_PERM,
8961 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8962 NL80211_FLAG_NEED_RTNL,
8963 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008964 {
8965 .cmd = NL80211_CMD_SET_NOACK_MAP,
8966 .doit = nl80211_set_noack_map,
8967 .policy = nl80211_policy,
8968 .flags = GENL_ADMIN_PERM,
8969 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8970 NL80211_FLAG_NEED_RTNL,
8971 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008972 {
8973 .cmd = NL80211_CMD_START_P2P_DEVICE,
8974 .doit = nl80211_start_p2p_device,
8975 .policy = nl80211_policy,
8976 .flags = GENL_ADMIN_PERM,
8977 .internal_flags = NL80211_FLAG_NEED_WDEV |
8978 NL80211_FLAG_NEED_RTNL,
8979 },
8980 {
8981 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8982 .doit = nl80211_stop_p2p_device,
8983 .policy = nl80211_policy,
8984 .flags = GENL_ADMIN_PERM,
8985 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8986 NL80211_FLAG_NEED_RTNL,
8987 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01008988 {
8989 .cmd = NL80211_CMD_SET_MCAST_RATE,
8990 .doit = nl80211_set_mcast_rate,
8991 .policy = nl80211_policy,
8992 .flags = GENL_ADMIN_PERM,
8993 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8994 NL80211_FLAG_NEED_RTNL,
8995 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05308996 {
8997 .cmd = NL80211_CMD_SET_MAC_ACL,
8998 .doit = nl80211_set_mac_acl,
8999 .policy = nl80211_policy,
9000 .flags = GENL_ADMIN_PERM,
9001 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9002 NL80211_FLAG_NEED_RTNL,
9003 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009004 {
9005 .cmd = NL80211_CMD_RADAR_DETECT,
9006 .doit = nl80211_start_radar_detection,
9007 .policy = nl80211_policy,
9008 .flags = GENL_ADMIN_PERM,
9009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9010 NL80211_FLAG_NEED_RTNL,
9011 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009012 {
9013 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9014 .doit = nl80211_get_protocol_features,
9015 .policy = nl80211_policy,
9016 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009017 {
9018 .cmd = NL80211_CMD_UPDATE_FT_IES,
9019 .doit = nl80211_update_ft_ies,
9020 .policy = nl80211_policy,
9021 .flags = GENL_ADMIN_PERM,
9022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9023 NL80211_FLAG_NEED_RTNL,
9024 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009025 {
9026 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9027 .doit = nl80211_crit_protocol_start,
9028 .policy = nl80211_policy,
9029 .flags = GENL_ADMIN_PERM,
9030 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9031 NL80211_FLAG_NEED_RTNL,
9032 },
9033 {
9034 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9035 .doit = nl80211_crit_protocol_stop,
9036 .policy = nl80211_policy,
9037 .flags = GENL_ADMIN_PERM,
9038 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9039 NL80211_FLAG_NEED_RTNL,
9040 }
Johannes Berg55682962007-09-20 13:09:35 -04009041};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009042
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009043static struct genl_multicast_group nl80211_mlme_mcgrp = {
9044 .name = "mlme",
9045};
Johannes Berg55682962007-09-20 13:09:35 -04009046
9047/* multicast groups */
9048static struct genl_multicast_group nl80211_config_mcgrp = {
9049 .name = "config",
9050};
Johannes Berg2a519312009-02-10 21:25:55 +01009051static struct genl_multicast_group nl80211_scan_mcgrp = {
9052 .name = "scan",
9053};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009054static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9055 .name = "regulatory",
9056};
Johannes Berg55682962007-09-20 13:09:35 -04009057
9058/* notification functions */
9059
9060void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9061{
9062 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009063 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009064
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009066 if (!msg)
9067 return;
9068
Johannes Berg86e8cf92013-06-19 10:57:22 +02009069 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009070 nlmsg_free(msg);
9071 return;
9072 }
9073
Johannes Berg463d0182009-07-14 00:33:35 +02009074 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9075 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009076}
9077
Johannes Berg362a4152009-05-24 16:43:15 +02009078static int nl80211_add_scan_req(struct sk_buff *msg,
9079 struct cfg80211_registered_device *rdev)
9080{
9081 struct cfg80211_scan_request *req = rdev->scan_req;
9082 struct nlattr *nest;
9083 int i;
9084
9085 if (WARN_ON(!req))
9086 return 0;
9087
9088 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9089 if (!nest)
9090 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009091 for (i = 0; i < req->n_ssids; i++) {
9092 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9093 goto nla_put_failure;
9094 }
Johannes Berg362a4152009-05-24 16:43:15 +02009095 nla_nest_end(msg, nest);
9096
9097 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9098 if (!nest)
9099 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009100 for (i = 0; i < req->n_channels; i++) {
9101 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9102 goto nla_put_failure;
9103 }
Johannes Berg362a4152009-05-24 16:43:15 +02009104 nla_nest_end(msg, nest);
9105
David S. Miller9360ffd2012-03-29 04:41:26 -04009106 if (req->ie &&
9107 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9108 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009109
Sam Lefflered4737712012-10-11 21:03:31 -07009110 if (req->flags)
9111 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9112
Johannes Berg362a4152009-05-24 16:43:15 +02009113 return 0;
9114 nla_put_failure:
9115 return -ENOBUFS;
9116}
9117
Johannes Berga538e2d2009-06-16 19:56:42 +02009118static int nl80211_send_scan_msg(struct sk_buff *msg,
9119 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009120 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009121 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009122 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009123{
9124 void *hdr;
9125
Eric W. Biederman15e47302012-09-07 20:12:54 +00009126 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009127 if (!hdr)
9128 return -1;
9129
David S. Miller9360ffd2012-03-29 04:41:26 -04009130 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009131 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9132 wdev->netdev->ifindex)) ||
9133 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009134 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009135
Johannes Berg362a4152009-05-24 16:43:15 +02009136 /* ignore errors and send incomplete event anyway */
9137 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009138
9139 return genlmsg_end(msg, hdr);
9140
9141 nla_put_failure:
9142 genlmsg_cancel(msg, hdr);
9143 return -EMSGSIZE;
9144}
9145
Luciano Coelho807f8a82011-05-11 17:09:35 +03009146static int
9147nl80211_send_sched_scan_msg(struct sk_buff *msg,
9148 struct cfg80211_registered_device *rdev,
9149 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009150 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009151{
9152 void *hdr;
9153
Eric W. Biederman15e47302012-09-07 20:12:54 +00009154 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009155 if (!hdr)
9156 return -1;
9157
David S. Miller9360ffd2012-03-29 04:41:26 -04009158 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9159 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9160 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009161
9162 return genlmsg_end(msg, hdr);
9163
9164 nla_put_failure:
9165 genlmsg_cancel(msg, hdr);
9166 return -EMSGSIZE;
9167}
9168
Johannes Berga538e2d2009-06-16 19:56:42 +02009169void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009170 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009171{
9172 struct sk_buff *msg;
9173
Thomas Graf58050fc2012-06-28 03:57:45 +00009174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009175 if (!msg)
9176 return;
9177
Johannes Bergfd014282012-06-18 19:17:03 +02009178 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009179 NL80211_CMD_TRIGGER_SCAN) < 0) {
9180 nlmsg_free(msg);
9181 return;
9182 }
9183
Johannes Berg463d0182009-07-14 00:33:35 +02009184 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9185 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009186}
9187
Johannes Berg2a519312009-02-10 21:25:55 +01009188void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009189 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009190{
9191 struct sk_buff *msg;
9192
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009193 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009194 if (!msg)
9195 return;
9196
Johannes Bergfd014282012-06-18 19:17:03 +02009197 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009198 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009199 nlmsg_free(msg);
9200 return;
9201 }
9202
Johannes Berg463d0182009-07-14 00:33:35 +02009203 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9204 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009205}
9206
9207void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009208 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009209{
9210 struct sk_buff *msg;
9211
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009213 if (!msg)
9214 return;
9215
Johannes Bergfd014282012-06-18 19:17:03 +02009216 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009217 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009218 nlmsg_free(msg);
9219 return;
9220 }
9221
Johannes Berg463d0182009-07-14 00:33:35 +02009222 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9223 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009224}
9225
Luciano Coelho807f8a82011-05-11 17:09:35 +03009226void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9227 struct net_device *netdev)
9228{
9229 struct sk_buff *msg;
9230
9231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9232 if (!msg)
9233 return;
9234
9235 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9236 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9237 nlmsg_free(msg);
9238 return;
9239 }
9240
9241 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9242 nl80211_scan_mcgrp.id, GFP_KERNEL);
9243}
9244
9245void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9246 struct net_device *netdev, u32 cmd)
9247{
9248 struct sk_buff *msg;
9249
Thomas Graf58050fc2012-06-28 03:57:45 +00009250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009251 if (!msg)
9252 return;
9253
9254 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9255 nlmsg_free(msg);
9256 return;
9257 }
9258
9259 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9260 nl80211_scan_mcgrp.id, GFP_KERNEL);
9261}
9262
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009263/*
9264 * This can happen on global regulatory changes or device specific settings
9265 * based on custom world regulatory domains.
9266 */
9267void nl80211_send_reg_change_event(struct regulatory_request *request)
9268{
9269 struct sk_buff *msg;
9270 void *hdr;
9271
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009272 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009273 if (!msg)
9274 return;
9275
9276 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9277 if (!hdr) {
9278 nlmsg_free(msg);
9279 return;
9280 }
9281
9282 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009283 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9284 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009285
David S. Miller9360ffd2012-03-29 04:41:26 -04009286 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9287 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9288 NL80211_REGDOM_TYPE_WORLD))
9289 goto nla_put_failure;
9290 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9291 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9292 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9293 goto nla_put_failure;
9294 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9295 request->intersect) {
9296 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9297 NL80211_REGDOM_TYPE_INTERSECTION))
9298 goto nla_put_failure;
9299 } else {
9300 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9301 NL80211_REGDOM_TYPE_COUNTRY) ||
9302 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9303 request->alpha2))
9304 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009305 }
9306
Johannes Bergf4173762012-12-03 18:23:37 +01009307 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009308 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9309 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009310
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009311 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009312
Johannes Bergbc43b282009-07-25 10:54:13 +02009313 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009314 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009315 GFP_ATOMIC);
9316 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009317
9318 return;
9319
9320nla_put_failure:
9321 genlmsg_cancel(msg, hdr);
9322 nlmsg_free(msg);
9323}
9324
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009325static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9326 struct net_device *netdev,
9327 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009328 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009329{
9330 struct sk_buff *msg;
9331 void *hdr;
9332
Johannes Berge6d6e342009-07-01 21:26:47 +02009333 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009334 if (!msg)
9335 return;
9336
9337 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9338 if (!hdr) {
9339 nlmsg_free(msg);
9340 return;
9341 }
9342
David S. Miller9360ffd2012-03-29 04:41:26 -04009343 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9344 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9345 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9346 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009347
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009348 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009349
Johannes Berg463d0182009-07-14 00:33:35 +02009350 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9351 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009352 return;
9353
9354 nla_put_failure:
9355 genlmsg_cancel(msg, hdr);
9356 nlmsg_free(msg);
9357}
9358
9359void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009360 struct net_device *netdev, const u8 *buf,
9361 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009362{
9363 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009364 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009365}
9366
9367void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9368 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009369 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009370{
Johannes Berge6d6e342009-07-01 21:26:47 +02009371 nl80211_send_mlme_event(rdev, netdev, buf, len,
9372 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009373}
9374
Jouni Malinen53b46b82009-03-27 20:53:56 +02009375void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009376 struct net_device *netdev, const u8 *buf,
9377 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009378{
9379 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009380 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009381}
9382
Jouni Malinen53b46b82009-03-27 20:53:56 +02009383void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9384 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009385 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009386{
9387 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009388 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009389}
9390
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009391void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9392 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009393{
Johannes Berg947add32013-02-22 22:05:20 +01009394 struct wireless_dev *wdev = dev->ieee80211_ptr;
9395 struct wiphy *wiphy = wdev->wiphy;
9396 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009397 const struct ieee80211_mgmt *mgmt = (void *)buf;
9398 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009399
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009400 if (WARN_ON(len < 2))
9401 return;
9402
9403 if (ieee80211_is_deauth(mgmt->frame_control))
9404 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9405 else
9406 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9407
9408 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9409 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009410}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009411EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009412
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009413static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9414 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009415 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009416{
9417 struct sk_buff *msg;
9418 void *hdr;
9419
Johannes Berge6d6e342009-07-01 21:26:47 +02009420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009421 if (!msg)
9422 return;
9423
9424 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9425 if (!hdr) {
9426 nlmsg_free(msg);
9427 return;
9428 }
9429
David S. Miller9360ffd2012-03-29 04:41:26 -04009430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9431 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9432 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9433 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9434 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009435
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009436 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009437
Johannes Berg463d0182009-07-14 00:33:35 +02009438 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9439 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009440 return;
9441
9442 nla_put_failure:
9443 genlmsg_cancel(msg, hdr);
9444 nlmsg_free(msg);
9445}
9446
9447void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009448 struct net_device *netdev, const u8 *addr,
9449 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009450{
9451 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009452 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009453}
9454
9455void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009456 struct net_device *netdev, const u8 *addr,
9457 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009458{
Johannes Berge6d6e342009-07-01 21:26:47 +02009459 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9460 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009461}
9462
Samuel Ortizb23aa672009-07-01 21:26:54 +02009463void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9464 struct net_device *netdev, const u8 *bssid,
9465 const u8 *req_ie, size_t req_ie_len,
9466 const u8 *resp_ie, size_t resp_ie_len,
9467 u16 status, gfp_t gfp)
9468{
9469 struct sk_buff *msg;
9470 void *hdr;
9471
Thomas Graf58050fc2012-06-28 03:57:45 +00009472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009473 if (!msg)
9474 return;
9475
9476 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9477 if (!hdr) {
9478 nlmsg_free(msg);
9479 return;
9480 }
9481
David S. Miller9360ffd2012-03-29 04:41:26 -04009482 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9483 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9484 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9485 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9486 (req_ie &&
9487 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9488 (resp_ie &&
9489 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9490 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009491
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009492 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009493
Johannes Berg463d0182009-07-14 00:33:35 +02009494 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9495 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009496 return;
9497
9498 nla_put_failure:
9499 genlmsg_cancel(msg, hdr);
9500 nlmsg_free(msg);
9501
9502}
9503
9504void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9505 struct net_device *netdev, const u8 *bssid,
9506 const u8 *req_ie, size_t req_ie_len,
9507 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9508{
9509 struct sk_buff *msg;
9510 void *hdr;
9511
Thomas Graf58050fc2012-06-28 03:57:45 +00009512 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009513 if (!msg)
9514 return;
9515
9516 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9517 if (!hdr) {
9518 nlmsg_free(msg);
9519 return;
9520 }
9521
David S. Miller9360ffd2012-03-29 04:41:26 -04009522 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9523 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9524 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9525 (req_ie &&
9526 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9527 (resp_ie &&
9528 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9529 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009530
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009531 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009532
Johannes Berg463d0182009-07-14 00:33:35 +02009533 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9534 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009535 return;
9536
9537 nla_put_failure:
9538 genlmsg_cancel(msg, hdr);
9539 nlmsg_free(msg);
9540
9541}
9542
9543void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9544 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009545 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009546{
9547 struct sk_buff *msg;
9548 void *hdr;
9549
Thomas Graf58050fc2012-06-28 03:57:45 +00009550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009551 if (!msg)
9552 return;
9553
9554 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9555 if (!hdr) {
9556 nlmsg_free(msg);
9557 return;
9558 }
9559
David S. Miller9360ffd2012-03-29 04:41:26 -04009560 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9561 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9562 (from_ap && reason &&
9563 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9564 (from_ap &&
9565 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9566 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9567 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009568
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009569 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009570
Johannes Berg463d0182009-07-14 00:33:35 +02009571 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9572 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009573 return;
9574
9575 nla_put_failure:
9576 genlmsg_cancel(msg, hdr);
9577 nlmsg_free(msg);
9578
9579}
9580
Johannes Berg04a773a2009-04-19 21:24:32 +02009581void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9582 struct net_device *netdev, const u8 *bssid,
9583 gfp_t gfp)
9584{
9585 struct sk_buff *msg;
9586 void *hdr;
9587
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009588 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009589 if (!msg)
9590 return;
9591
9592 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9593 if (!hdr) {
9594 nlmsg_free(msg);
9595 return;
9596 }
9597
David S. Miller9360ffd2012-03-29 04:41:26 -04009598 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9599 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9600 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9601 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009602
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009603 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009604
Johannes Berg463d0182009-07-14 00:33:35 +02009605 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9606 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009607 return;
9608
9609 nla_put_failure:
9610 genlmsg_cancel(msg, hdr);
9611 nlmsg_free(msg);
9612}
9613
Johannes Berg947add32013-02-22 22:05:20 +01009614void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9615 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009616{
Johannes Berg947add32013-02-22 22:05:20 +01009617 struct wireless_dev *wdev = dev->ieee80211_ptr;
9618 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009619 struct sk_buff *msg;
9620 void *hdr;
9621
Johannes Berg947add32013-02-22 22:05:20 +01009622 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9623 return;
9624
9625 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9626
Javier Cardonac93b5e72011-04-07 15:08:34 -07009627 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9628 if (!msg)
9629 return;
9630
9631 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9632 if (!hdr) {
9633 nlmsg_free(msg);
9634 return;
9635 }
9636
David S. Miller9360ffd2012-03-29 04:41:26 -04009637 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009638 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9639 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009640 (ie_len && ie &&
9641 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9642 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009643
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009644 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009645
9646 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9647 nl80211_mlme_mcgrp.id, gfp);
9648 return;
9649
9650 nla_put_failure:
9651 genlmsg_cancel(msg, hdr);
9652 nlmsg_free(msg);
9653}
Johannes Berg947add32013-02-22 22:05:20 +01009654EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009655
Jouni Malinena3b8b052009-03-27 21:59:49 +02009656void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9657 struct net_device *netdev, const u8 *addr,
9658 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009659 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009660{
9661 struct sk_buff *msg;
9662 void *hdr;
9663
Johannes Berge6d6e342009-07-01 21:26:47 +02009664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009665 if (!msg)
9666 return;
9667
9668 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9669 if (!hdr) {
9670 nlmsg_free(msg);
9671 return;
9672 }
9673
David S. Miller9360ffd2012-03-29 04:41:26 -04009674 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9676 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9677 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9678 (key_id != -1 &&
9679 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9680 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9681 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009682
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009683 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009684
Johannes Berg463d0182009-07-14 00:33:35 +02009685 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9686 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009687 return;
9688
9689 nla_put_failure:
9690 genlmsg_cancel(msg, hdr);
9691 nlmsg_free(msg);
9692}
9693
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009694void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9695 struct ieee80211_channel *channel_before,
9696 struct ieee80211_channel *channel_after)
9697{
9698 struct sk_buff *msg;
9699 void *hdr;
9700 struct nlattr *nl_freq;
9701
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009703 if (!msg)
9704 return;
9705
9706 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9707 if (!hdr) {
9708 nlmsg_free(msg);
9709 return;
9710 }
9711
9712 /*
9713 * Since we are applying the beacon hint to a wiphy we know its
9714 * wiphy_idx is valid
9715 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009716 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9717 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009718
9719 /* Before */
9720 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9721 if (!nl_freq)
9722 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009723 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009724 goto nla_put_failure;
9725 nla_nest_end(msg, nl_freq);
9726
9727 /* After */
9728 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9729 if (!nl_freq)
9730 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009731 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009732 goto nla_put_failure;
9733 nla_nest_end(msg, nl_freq);
9734
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009735 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009736
Johannes Berg463d0182009-07-14 00:33:35 +02009737 rcu_read_lock();
9738 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9739 GFP_ATOMIC);
9740 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009741
9742 return;
9743
9744nla_put_failure:
9745 genlmsg_cancel(msg, hdr);
9746 nlmsg_free(msg);
9747}
9748
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009749static void nl80211_send_remain_on_chan_event(
9750 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009751 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009752 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009753 unsigned int duration, gfp_t gfp)
9754{
9755 struct sk_buff *msg;
9756 void *hdr;
9757
9758 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9759 if (!msg)
9760 return;
9761
9762 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9763 if (!hdr) {
9764 nlmsg_free(msg);
9765 return;
9766 }
9767
David S. Miller9360ffd2012-03-29 04:41:26 -04009768 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009769 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9770 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009771 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009772 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009773 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9774 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009775 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9776 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009777
David S. Miller9360ffd2012-03-29 04:41:26 -04009778 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9779 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9780 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009781
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009782 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009783
9784 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9785 nl80211_mlme_mcgrp.id, gfp);
9786 return;
9787
9788 nla_put_failure:
9789 genlmsg_cancel(msg, hdr);
9790 nlmsg_free(msg);
9791}
9792
Johannes Berg947add32013-02-22 22:05:20 +01009793void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9794 struct ieee80211_channel *chan,
9795 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009796{
Johannes Berg947add32013-02-22 22:05:20 +01009797 struct wiphy *wiphy = wdev->wiphy;
9798 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9799
9800 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009801 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009802 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009803 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009804}
Johannes Berg947add32013-02-22 22:05:20 +01009805EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009806
Johannes Berg947add32013-02-22 22:05:20 +01009807void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9808 struct ieee80211_channel *chan,
9809 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009810{
Johannes Berg947add32013-02-22 22:05:20 +01009811 struct wiphy *wiphy = wdev->wiphy;
9812 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9813
9814 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009815 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009816 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009817}
Johannes Berg947add32013-02-22 22:05:20 +01009818EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009819
Johannes Berg947add32013-02-22 22:05:20 +01009820void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9821 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009822{
Johannes Berg947add32013-02-22 22:05:20 +01009823 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9824 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009825 struct sk_buff *msg;
9826
Johannes Berg947add32013-02-22 22:05:20 +01009827 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9828
Thomas Graf58050fc2012-06-28 03:57:45 +00009829 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009830 if (!msg)
9831 return;
9832
John W. Linville66266b32012-03-15 13:25:41 -04009833 if (nl80211_send_station(msg, 0, 0, 0,
9834 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009835 nlmsg_free(msg);
9836 return;
9837 }
9838
9839 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9840 nl80211_mlme_mcgrp.id, gfp);
9841}
Johannes Berg947add32013-02-22 22:05:20 +01009842EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009843
Johannes Berg947add32013-02-22 22:05:20 +01009844void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009845{
Johannes Berg947add32013-02-22 22:05:20 +01009846 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9847 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009848 struct sk_buff *msg;
9849 void *hdr;
9850
Johannes Berg947add32013-02-22 22:05:20 +01009851 trace_cfg80211_del_sta(dev, mac_addr);
9852
Thomas Graf58050fc2012-06-28 03:57:45 +00009853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009854 if (!msg)
9855 return;
9856
9857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9858 if (!hdr) {
9859 nlmsg_free(msg);
9860 return;
9861 }
9862
David S. Miller9360ffd2012-03-29 04:41:26 -04009863 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9864 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9865 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009866
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009867 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009868
9869 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9870 nl80211_mlme_mcgrp.id, gfp);
9871 return;
9872
9873 nla_put_failure:
9874 genlmsg_cancel(msg, hdr);
9875 nlmsg_free(msg);
9876}
Johannes Berg947add32013-02-22 22:05:20 +01009877EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009878
Johannes Berg947add32013-02-22 22:05:20 +01009879void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9880 enum nl80211_connect_failed_reason reason,
9881 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309882{
Johannes Berg947add32013-02-22 22:05:20 +01009883 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9884 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309885 struct sk_buff *msg;
9886 void *hdr;
9887
9888 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9889 if (!msg)
9890 return;
9891
9892 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9893 if (!hdr) {
9894 nlmsg_free(msg);
9895 return;
9896 }
9897
9898 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9899 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9900 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9901 goto nla_put_failure;
9902
9903 genlmsg_end(msg, hdr);
9904
9905 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9906 nl80211_mlme_mcgrp.id, gfp);
9907 return;
9908
9909 nla_put_failure:
9910 genlmsg_cancel(msg, hdr);
9911 nlmsg_free(msg);
9912}
Johannes Berg947add32013-02-22 22:05:20 +01009913EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309914
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009915static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9916 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009917{
9918 struct wireless_dev *wdev = dev->ieee80211_ptr;
9919 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9920 struct sk_buff *msg;
9921 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009922 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009923
Eric W. Biederman15e47302012-09-07 20:12:54 +00009924 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009925 return false;
9926
9927 msg = nlmsg_new(100, gfp);
9928 if (!msg)
9929 return true;
9930
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009931 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009932 if (!hdr) {
9933 nlmsg_free(msg);
9934 return true;
9935 }
9936
David S. Miller9360ffd2012-03-29 04:41:26 -04009937 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9938 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9939 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9940 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009941
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009942 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009943 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009944 return true;
9945
9946 nla_put_failure:
9947 genlmsg_cancel(msg, hdr);
9948 nlmsg_free(msg);
9949 return true;
9950}
9951
Johannes Berg947add32013-02-22 22:05:20 +01009952bool cfg80211_rx_spurious_frame(struct net_device *dev,
9953 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009954{
Johannes Berg947add32013-02-22 22:05:20 +01009955 struct wireless_dev *wdev = dev->ieee80211_ptr;
9956 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009957
Johannes Berg947add32013-02-22 22:05:20 +01009958 trace_cfg80211_rx_spurious_frame(dev, addr);
9959
9960 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9961 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9962 trace_cfg80211_return_bool(false);
9963 return false;
9964 }
9965 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9966 addr, gfp);
9967 trace_cfg80211_return_bool(ret);
9968 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009969}
Johannes Berg947add32013-02-22 22:05:20 +01009970EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9971
9972bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9973 const u8 *addr, gfp_t gfp)
9974{
9975 struct wireless_dev *wdev = dev->ieee80211_ptr;
9976 bool ret;
9977
9978 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9979
9980 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9981 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9982 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9983 trace_cfg80211_return_bool(false);
9984 return false;
9985 }
9986 ret = __nl80211_unexpected_frame(dev,
9987 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
9988 addr, gfp);
9989 trace_cfg80211_return_bool(ret);
9990 return ret;
9991}
9992EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009993
Johannes Berg2e161f72010-08-12 15:38:38 +02009994int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009995 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +01009996 int freq, int sig_dbm,
9997 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +02009998{
Johannes Berg71bbc992012-06-15 15:30:18 +02009999 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010000 struct sk_buff *msg;
10001 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010002
10003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10004 if (!msg)
10005 return -ENOMEM;
10006
Johannes Berg2e161f72010-08-12 15:38:38 +020010007 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010008 if (!hdr) {
10009 nlmsg_free(msg);
10010 return -ENOMEM;
10011 }
10012
David S. Miller9360ffd2012-03-29 04:41:26 -040010013 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010014 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10015 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010016 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010017 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10018 (sig_dbm &&
10019 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10020 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10021 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010022
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010023 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010024
Eric W. Biederman15e47302012-09-07 20:12:54 +000010025 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010026
10027 nla_put_failure:
10028 genlmsg_cancel(msg, hdr);
10029 nlmsg_free(msg);
10030 return -ENOBUFS;
10031}
10032
Johannes Berg947add32013-02-22 22:05:20 +010010033void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10034 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010035{
Johannes Berg947add32013-02-22 22:05:20 +010010036 struct wiphy *wiphy = wdev->wiphy;
10037 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010038 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010039 struct sk_buff *msg;
10040 void *hdr;
10041
Johannes Berg947add32013-02-22 22:05:20 +010010042 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10043
Jouni Malinen026331c2010-02-15 12:53:10 +020010044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10045 if (!msg)
10046 return;
10047
Johannes Berg2e161f72010-08-12 15:38:38 +020010048 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010049 if (!hdr) {
10050 nlmsg_free(msg);
10051 return;
10052 }
10053
David S. Miller9360ffd2012-03-29 04:41:26 -040010054 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010055 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10056 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010057 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010058 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10059 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10060 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10061 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010062
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010063 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010064
10065 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10066 return;
10067
10068 nla_put_failure:
10069 genlmsg_cancel(msg, hdr);
10070 nlmsg_free(msg);
10071}
Johannes Berg947add32013-02-22 22:05:20 +010010072EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010073
Johannes Berg947add32013-02-22 22:05:20 +010010074void cfg80211_cqm_rssi_notify(struct net_device *dev,
10075 enum nl80211_cqm_rssi_threshold_event rssi_event,
10076 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010077{
Johannes Berg947add32013-02-22 22:05:20 +010010078 struct wireless_dev *wdev = dev->ieee80211_ptr;
10079 struct wiphy *wiphy = wdev->wiphy;
10080 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010081 struct sk_buff *msg;
10082 struct nlattr *pinfoattr;
10083 void *hdr;
10084
Johannes Berg947add32013-02-22 22:05:20 +010010085 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10086
Thomas Graf58050fc2012-06-28 03:57:45 +000010087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010088 if (!msg)
10089 return;
10090
10091 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10092 if (!hdr) {
10093 nlmsg_free(msg);
10094 return;
10095 }
10096
David S. Miller9360ffd2012-03-29 04:41:26 -040010097 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010098 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010099 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010100
10101 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10102 if (!pinfoattr)
10103 goto nla_put_failure;
10104
David S. Miller9360ffd2012-03-29 04:41:26 -040010105 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10106 rssi_event))
10107 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010108
10109 nla_nest_end(msg, pinfoattr);
10110
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010111 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010112
10113 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10114 nl80211_mlme_mcgrp.id, gfp);
10115 return;
10116
10117 nla_put_failure:
10118 genlmsg_cancel(msg, hdr);
10119 nlmsg_free(msg);
10120}
Johannes Berg947add32013-02-22 22:05:20 +010010121EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010122
Johannes Berg947add32013-02-22 22:05:20 +010010123static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10124 struct net_device *netdev, const u8 *bssid,
10125 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010126{
10127 struct sk_buff *msg;
10128 struct nlattr *rekey_attr;
10129 void *hdr;
10130
Thomas Graf58050fc2012-06-28 03:57:45 +000010131 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010132 if (!msg)
10133 return;
10134
10135 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10136 if (!hdr) {
10137 nlmsg_free(msg);
10138 return;
10139 }
10140
David S. Miller9360ffd2012-03-29 04:41:26 -040010141 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10142 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10143 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10144 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010145
10146 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10147 if (!rekey_attr)
10148 goto nla_put_failure;
10149
David S. Miller9360ffd2012-03-29 04:41:26 -040010150 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10151 NL80211_REPLAY_CTR_LEN, replay_ctr))
10152 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010153
10154 nla_nest_end(msg, rekey_attr);
10155
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010156 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010157
10158 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10159 nl80211_mlme_mcgrp.id, gfp);
10160 return;
10161
10162 nla_put_failure:
10163 genlmsg_cancel(msg, hdr);
10164 nlmsg_free(msg);
10165}
10166
Johannes Berg947add32013-02-22 22:05:20 +010010167void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10168 const u8 *replay_ctr, gfp_t gfp)
10169{
10170 struct wireless_dev *wdev = dev->ieee80211_ptr;
10171 struct wiphy *wiphy = wdev->wiphy;
10172 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10173
10174 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10175 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10176}
10177EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10178
10179static void
10180nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10181 struct net_device *netdev, int index,
10182 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010183{
10184 struct sk_buff *msg;
10185 struct nlattr *attr;
10186 void *hdr;
10187
Thomas Graf58050fc2012-06-28 03:57:45 +000010188 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010189 if (!msg)
10190 return;
10191
10192 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10193 if (!hdr) {
10194 nlmsg_free(msg);
10195 return;
10196 }
10197
David S. Miller9360ffd2012-03-29 04:41:26 -040010198 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10199 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10200 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010201
10202 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10203 if (!attr)
10204 goto nla_put_failure;
10205
David S. Miller9360ffd2012-03-29 04:41:26 -040010206 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10207 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10208 (preauth &&
10209 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10210 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010211
10212 nla_nest_end(msg, attr);
10213
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010214 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010215
10216 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10217 nl80211_mlme_mcgrp.id, gfp);
10218 return;
10219
10220 nla_put_failure:
10221 genlmsg_cancel(msg, hdr);
10222 nlmsg_free(msg);
10223}
10224
Johannes Berg947add32013-02-22 22:05:20 +010010225void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10226 const u8 *bssid, bool preauth, gfp_t gfp)
10227{
10228 struct wireless_dev *wdev = dev->ieee80211_ptr;
10229 struct wiphy *wiphy = wdev->wiphy;
10230 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10231
10232 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10233 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10234}
10235EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10236
10237static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10238 struct net_device *netdev,
10239 struct cfg80211_chan_def *chandef,
10240 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010241{
10242 struct sk_buff *msg;
10243 void *hdr;
10244
Thomas Graf58050fc2012-06-28 03:57:45 +000010245 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010246 if (!msg)
10247 return;
10248
10249 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10250 if (!hdr) {
10251 nlmsg_free(msg);
10252 return;
10253 }
10254
Johannes Berg683b6d32012-11-08 21:25:48 +010010255 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10256 goto nla_put_failure;
10257
10258 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010259 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010260
10261 genlmsg_end(msg, hdr);
10262
10263 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10264 nl80211_mlme_mcgrp.id, gfp);
10265 return;
10266
10267 nla_put_failure:
10268 genlmsg_cancel(msg, hdr);
10269 nlmsg_free(msg);
10270}
10271
Johannes Berg947add32013-02-22 22:05:20 +010010272void cfg80211_ch_switch_notify(struct net_device *dev,
10273 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010274{
Johannes Berg947add32013-02-22 22:05:20 +010010275 struct wireless_dev *wdev = dev->ieee80211_ptr;
10276 struct wiphy *wiphy = wdev->wiphy;
10277 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10278
10279 trace_cfg80211_ch_switch_notify(dev, chandef);
10280
10281 wdev_lock(wdev);
10282
10283 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10284 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10285 goto out;
10286
10287 wdev->channel = chandef->chan;
10288 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10289out:
10290 wdev_unlock(wdev);
10291 return;
10292}
10293EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10294
10295void cfg80211_cqm_txe_notify(struct net_device *dev,
10296 const u8 *peer, u32 num_packets,
10297 u32 rate, u32 intvl, gfp_t gfp)
10298{
10299 struct wireless_dev *wdev = dev->ieee80211_ptr;
10300 struct wiphy *wiphy = wdev->wiphy;
10301 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010302 struct sk_buff *msg;
10303 struct nlattr *pinfoattr;
10304 void *hdr;
10305
10306 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10307 if (!msg)
10308 return;
10309
10310 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10311 if (!hdr) {
10312 nlmsg_free(msg);
10313 return;
10314 }
10315
10316 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010317 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010318 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10319 goto nla_put_failure;
10320
10321 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10322 if (!pinfoattr)
10323 goto nla_put_failure;
10324
10325 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10326 goto nla_put_failure;
10327
10328 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10329 goto nla_put_failure;
10330
10331 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10332 goto nla_put_failure;
10333
10334 nla_nest_end(msg, pinfoattr);
10335
10336 genlmsg_end(msg, hdr);
10337
10338 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10339 nl80211_mlme_mcgrp.id, gfp);
10340 return;
10341
10342 nla_put_failure:
10343 genlmsg_cancel(msg, hdr);
10344 nlmsg_free(msg);
10345}
Johannes Berg947add32013-02-22 22:05:20 +010010346EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010347
10348void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010349nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10350 struct cfg80211_chan_def *chandef,
10351 enum nl80211_radar_event event,
10352 struct net_device *netdev, gfp_t gfp)
10353{
10354 struct sk_buff *msg;
10355 void *hdr;
10356
10357 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10358 if (!msg)
10359 return;
10360
10361 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10362 if (!hdr) {
10363 nlmsg_free(msg);
10364 return;
10365 }
10366
10367 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10368 goto nla_put_failure;
10369
10370 /* NOP and radar events don't need a netdev parameter */
10371 if (netdev) {
10372 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10373
10374 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10375 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10376 goto nla_put_failure;
10377 }
10378
10379 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10380 goto nla_put_failure;
10381
10382 if (nl80211_send_chandef(msg, chandef))
10383 goto nla_put_failure;
10384
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010385 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010386
10387 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10388 nl80211_mlme_mcgrp.id, gfp);
10389 return;
10390
10391 nla_put_failure:
10392 genlmsg_cancel(msg, hdr);
10393 nlmsg_free(msg);
10394}
10395
Johannes Berg947add32013-02-22 22:05:20 +010010396void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10397 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010398{
Johannes Berg947add32013-02-22 22:05:20 +010010399 struct wireless_dev *wdev = dev->ieee80211_ptr;
10400 struct wiphy *wiphy = wdev->wiphy;
10401 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010402 struct sk_buff *msg;
10403 struct nlattr *pinfoattr;
10404 void *hdr;
10405
Johannes Berg947add32013-02-22 22:05:20 +010010406 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10407
Thomas Graf58050fc2012-06-28 03:57:45 +000010408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010409 if (!msg)
10410 return;
10411
10412 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10413 if (!hdr) {
10414 nlmsg_free(msg);
10415 return;
10416 }
10417
David S. Miller9360ffd2012-03-29 04:41:26 -040010418 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010419 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010420 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10421 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010422
10423 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10424 if (!pinfoattr)
10425 goto nla_put_failure;
10426
David S. Miller9360ffd2012-03-29 04:41:26 -040010427 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10428 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010429
10430 nla_nest_end(msg, pinfoattr);
10431
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010432 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010433
10434 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10435 nl80211_mlme_mcgrp.id, gfp);
10436 return;
10437
10438 nla_put_failure:
10439 genlmsg_cancel(msg, hdr);
10440 nlmsg_free(msg);
10441}
Johannes Berg947add32013-02-22 22:05:20 +010010442EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010443
Johannes Berg7f6cf312011-11-04 11:18:15 +010010444void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10445 u64 cookie, bool acked, gfp_t gfp)
10446{
10447 struct wireless_dev *wdev = dev->ieee80211_ptr;
10448 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10449 struct sk_buff *msg;
10450 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010451
Beni Lev4ee3e062012-08-27 12:49:39 +030010452 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10453
Thomas Graf58050fc2012-06-28 03:57:45 +000010454 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010455
Johannes Berg7f6cf312011-11-04 11:18:15 +010010456 if (!msg)
10457 return;
10458
10459 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10460 if (!hdr) {
10461 nlmsg_free(msg);
10462 return;
10463 }
10464
David S. Miller9360ffd2012-03-29 04:41:26 -040010465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10467 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10468 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10469 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10470 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010471
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010472 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010473
10474 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10475 nl80211_mlme_mcgrp.id, gfp);
10476 return;
10477
10478 nla_put_failure:
10479 genlmsg_cancel(msg, hdr);
10480 nlmsg_free(msg);
10481}
10482EXPORT_SYMBOL(cfg80211_probe_status);
10483
Johannes Berg5e7602302011-11-04 11:18:17 +010010484void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10485 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010486 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010487{
10488 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10489 struct sk_buff *msg;
10490 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010491 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010492
Beni Lev4ee3e062012-08-27 12:49:39 +030010493 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10494
Ben Greear37c73b52012-10-26 14:49:25 -070010495 spin_lock_bh(&rdev->beacon_registrations_lock);
10496 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10497 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10498 if (!msg) {
10499 spin_unlock_bh(&rdev->beacon_registrations_lock);
10500 return;
10501 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010502
Ben Greear37c73b52012-10-26 14:49:25 -070010503 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10504 if (!hdr)
10505 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010506
Ben Greear37c73b52012-10-26 14:49:25 -070010507 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10508 (freq &&
10509 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10510 (sig_dbm &&
10511 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10512 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10513 goto nla_put_failure;
10514
10515 genlmsg_end(msg, hdr);
10516
10517 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010518 }
Ben Greear37c73b52012-10-26 14:49:25 -070010519 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010520 return;
10521
10522 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010523 spin_unlock_bh(&rdev->beacon_registrations_lock);
10524 if (hdr)
10525 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010526 nlmsg_free(msg);
10527}
10528EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10529
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010530#ifdef CONFIG_PM
10531void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10532 struct cfg80211_wowlan_wakeup *wakeup,
10533 gfp_t gfp)
10534{
10535 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10536 struct sk_buff *msg;
10537 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010538 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010539
10540 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10541
10542 if (wakeup)
10543 size += wakeup->packet_present_len;
10544
10545 msg = nlmsg_new(size, gfp);
10546 if (!msg)
10547 return;
10548
10549 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10550 if (!hdr)
10551 goto free_msg;
10552
10553 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10554 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10555 goto free_msg;
10556
10557 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10558 wdev->netdev->ifindex))
10559 goto free_msg;
10560
10561 if (wakeup) {
10562 struct nlattr *reasons;
10563
10564 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10565
10566 if (wakeup->disconnect &&
10567 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10568 goto free_msg;
10569 if (wakeup->magic_pkt &&
10570 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10571 goto free_msg;
10572 if (wakeup->gtk_rekey_failure &&
10573 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10574 goto free_msg;
10575 if (wakeup->eap_identity_req &&
10576 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10577 goto free_msg;
10578 if (wakeup->four_way_handshake &&
10579 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10580 goto free_msg;
10581 if (wakeup->rfkill_release &&
10582 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10583 goto free_msg;
10584
10585 if (wakeup->pattern_idx >= 0 &&
10586 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10587 wakeup->pattern_idx))
10588 goto free_msg;
10589
Johannes Berg2a0e0472013-01-23 22:57:40 +010010590 if (wakeup->tcp_match)
10591 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10592
10593 if (wakeup->tcp_connlost)
10594 nla_put_flag(msg,
10595 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10596
10597 if (wakeup->tcp_nomoretokens)
10598 nla_put_flag(msg,
10599 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10600
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010601 if (wakeup->packet) {
10602 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10603 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10604
10605 if (!wakeup->packet_80211) {
10606 pkt_attr =
10607 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10608 len_attr =
10609 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10610 }
10611
10612 if (wakeup->packet_len &&
10613 nla_put_u32(msg, len_attr, wakeup->packet_len))
10614 goto free_msg;
10615
10616 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10617 wakeup->packet))
10618 goto free_msg;
10619 }
10620
10621 nla_nest_end(msg, reasons);
10622 }
10623
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010624 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010625
10626 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10627 nl80211_mlme_mcgrp.id, gfp);
10628 return;
10629
10630 free_msg:
10631 nlmsg_free(msg);
10632}
10633EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10634#endif
10635
Jouni Malinen3475b092012-11-16 22:49:57 +020010636void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10637 enum nl80211_tdls_operation oper,
10638 u16 reason_code, gfp_t gfp)
10639{
10640 struct wireless_dev *wdev = dev->ieee80211_ptr;
10641 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10642 struct sk_buff *msg;
10643 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010644
10645 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10646 reason_code);
10647
10648 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10649 if (!msg)
10650 return;
10651
10652 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10653 if (!hdr) {
10654 nlmsg_free(msg);
10655 return;
10656 }
10657
10658 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10659 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10660 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10661 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10662 (reason_code > 0 &&
10663 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10664 goto nla_put_failure;
10665
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010666 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010667
10668 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10669 nl80211_mlme_mcgrp.id, gfp);
10670 return;
10671
10672 nla_put_failure:
10673 genlmsg_cancel(msg, hdr);
10674 nlmsg_free(msg);
10675}
10676EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10677
Jouni Malinen026331c2010-02-15 12:53:10 +020010678static int nl80211_netlink_notify(struct notifier_block * nb,
10679 unsigned long state,
10680 void *_notify)
10681{
10682 struct netlink_notify *notify = _notify;
10683 struct cfg80211_registered_device *rdev;
10684 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010685 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010686
10687 if (state != NETLINK_URELEASE)
10688 return NOTIFY_DONE;
10689
10690 rcu_read_lock();
10691
Johannes Berg5e7602302011-11-04 11:18:17 +010010692 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010693 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010694 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010695
10696 spin_lock_bh(&rdev->beacon_registrations_lock);
10697 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10698 list) {
10699 if (reg->nlportid == notify->portid) {
10700 list_del(&reg->list);
10701 kfree(reg);
10702 break;
10703 }
10704 }
10705 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010706 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010707
10708 rcu_read_unlock();
10709
10710 return NOTIFY_DONE;
10711}
10712
10713static struct notifier_block nl80211_netlink_notifier = {
10714 .notifier_call = nl80211_netlink_notify,
10715};
10716
Jouni Malinen355199e2013-02-27 17:14:27 +020010717void cfg80211_ft_event(struct net_device *netdev,
10718 struct cfg80211_ft_event_params *ft_event)
10719{
10720 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10721 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10722 struct sk_buff *msg;
10723 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010724
10725 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10726
10727 if (!ft_event->target_ap)
10728 return;
10729
10730 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10731 if (!msg)
10732 return;
10733
10734 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10735 if (!hdr) {
10736 nlmsg_free(msg);
10737 return;
10738 }
10739
10740 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10741 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10742 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10743 if (ft_event->ies)
10744 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10745 if (ft_event->ric_ies)
10746 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10747 ft_event->ric_ies);
10748
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010749 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010750
10751 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10752 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10753}
10754EXPORT_SYMBOL(cfg80211_ft_event);
10755
Arend van Spriel5de17982013-04-18 15:49:00 +020010756void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10757{
10758 struct cfg80211_registered_device *rdev;
10759 struct sk_buff *msg;
10760 void *hdr;
10761 u32 nlportid;
10762
10763 rdev = wiphy_to_dev(wdev->wiphy);
10764 if (!rdev->crit_proto_nlportid)
10765 return;
10766
10767 nlportid = rdev->crit_proto_nlportid;
10768 rdev->crit_proto_nlportid = 0;
10769
10770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10771 if (!msg)
10772 return;
10773
10774 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10775 if (!hdr)
10776 goto nla_put_failure;
10777
10778 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10779 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10780 goto nla_put_failure;
10781
10782 genlmsg_end(msg, hdr);
10783
10784 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10785 return;
10786
10787 nla_put_failure:
10788 if (hdr)
10789 genlmsg_cancel(msg, hdr);
10790 nlmsg_free(msg);
10791
10792}
10793EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10794
Johannes Berg55682962007-09-20 13:09:35 -040010795/* initialisation/exit functions */
10796
10797int nl80211_init(void)
10798{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010799 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010800
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010801 err = genl_register_family_with_ops(&nl80211_fam,
10802 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010803 if (err)
10804 return err;
10805
Johannes Berg55682962007-09-20 13:09:35 -040010806 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10807 if (err)
10808 goto err_out;
10809
Johannes Berg2a519312009-02-10 21:25:55 +010010810 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10811 if (err)
10812 goto err_out;
10813
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010814 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10815 if (err)
10816 goto err_out;
10817
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010818 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10819 if (err)
10820 goto err_out;
10821
Johannes Bergaff89a92009-07-01 21:26:51 +020010822#ifdef CONFIG_NL80211_TESTMODE
10823 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10824 if (err)
10825 goto err_out;
10826#endif
10827
Jouni Malinen026331c2010-02-15 12:53:10 +020010828 err = netlink_register_notifier(&nl80211_netlink_notifier);
10829 if (err)
10830 goto err_out;
10831
Johannes Berg55682962007-09-20 13:09:35 -040010832 return 0;
10833 err_out:
10834 genl_unregister_family(&nl80211_fam);
10835 return err;
10836}
10837
10838void nl80211_exit(void)
10839{
Jouni Malinen026331c2010-02-15 12:53:10 +020010840 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010841 genl_unregister_family(&nl80211_fam);
10842}