blob: 0492478ab74e5d79719b0a3799054d3b36e6ae3b [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes 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 Malinen36aedc92008-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 Malinen36aedc92008-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
Simon Wunderlich803768f2013-06-28 10:39:58 +02006349 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6350 memcpy(&ibss.ht_capa_mask,
6351 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6352 sizeof(ibss.ht_capa_mask));
6353
6354 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6355 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6356 return -EINVAL;
6357 memcpy(&ibss.ht_capa,
6358 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6359 sizeof(ibss.ht_capa));
6360 }
6361
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006362 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6363 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6364 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6365 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006366
Johannes Berg4c476992010-10-04 21:36:35 +02006367 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306368 bool no_ht = false;
6369
Johannes Berg4c476992010-10-04 21:36:35 +02006370 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306371 info->attrs[NL80211_ATTR_KEYS],
6372 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006373 if (IS_ERR(connkeys))
6374 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306375
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006376 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6377 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306378 kfree(connkeys);
6379 return -EINVAL;
6380 }
Johannes Berg4c476992010-10-04 21:36:35 +02006381 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006382
Antonio Quartulli267335d2012-01-31 20:25:47 +01006383 ibss.control_port =
6384 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6385
Johannes Berg4c476992010-10-04 21:36:35 +02006386 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006387 if (err)
6388 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006389 return err;
6390}
6391
6392static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6393{
Johannes Berg4c476992010-10-04 21:36:35 +02006394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6395 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006396
Johannes Berg4c476992010-10-04 21:36:35 +02006397 if (!rdev->ops->leave_ibss)
6398 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006399
Johannes Berg4c476992010-10-04 21:36:35 +02006400 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6401 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006402
Johannes Berg4c476992010-10-04 21:36:35 +02006403 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006404}
6405
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006406static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6407{
6408 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6409 struct net_device *dev = info->user_ptr[1];
6410 int mcast_rate[IEEE80211_NUM_BANDS];
6411 u32 nla_rate;
6412 int err;
6413
6414 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6415 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6416 return -EOPNOTSUPP;
6417
6418 if (!rdev->ops->set_mcast_rate)
6419 return -EOPNOTSUPP;
6420
6421 memset(mcast_rate, 0, sizeof(mcast_rate));
6422
6423 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6424 return -EINVAL;
6425
6426 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6427 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6428 return -EINVAL;
6429
6430 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6431
6432 return err;
6433}
6434
6435
Johannes Bergaff89a92009-07-01 21:26:51 +02006436#ifdef CONFIG_NL80211_TESTMODE
6437static struct genl_multicast_group nl80211_testmode_mcgrp = {
6438 .name = "testmode",
6439};
6440
6441static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6442{
Johannes Berg4c476992010-10-04 21:36:35 +02006443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006444 int err;
6445
6446 if (!info->attrs[NL80211_ATTR_TESTDATA])
6447 return -EINVAL;
6448
Johannes Bergaff89a92009-07-01 21:26:51 +02006449 err = -EOPNOTSUPP;
6450 if (rdev->ops->testmode_cmd) {
6451 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006452 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006453 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6454 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6455 rdev->testmode_info = NULL;
6456 }
6457
Johannes Bergaff89a92009-07-01 21:26:51 +02006458 return err;
6459}
6460
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006461static int nl80211_testmode_dump(struct sk_buff *skb,
6462 struct netlink_callback *cb)
6463{
Johannes Berg00918d32011-12-13 17:22:05 +01006464 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006465 int err;
6466 long phy_idx;
6467 void *data = NULL;
6468 int data_len = 0;
6469
Johannes Berg5fe231e2013-05-08 21:45:15 +02006470 rtnl_lock();
6471
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006472 if (cb->args[0]) {
6473 /*
6474 * 0 is a valid index, but not valid for args[0],
6475 * so we need to offset by 1.
6476 */
6477 phy_idx = cb->args[0] - 1;
6478 } else {
6479 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6480 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6481 nl80211_policy);
6482 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006483 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006484
Johannes Berg2bd7e352012-06-15 14:23:16 +02006485 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6486 nl80211_fam.attrbuf);
6487 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006488 err = PTR_ERR(rdev);
6489 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006490 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006491 phy_idx = rdev->wiphy_idx;
6492 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006493
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006494 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6495 cb->args[1] =
6496 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6497 }
6498
6499 if (cb->args[1]) {
6500 data = nla_data((void *)cb->args[1]);
6501 data_len = nla_len((void *)cb->args[1]);
6502 }
6503
Johannes Berg00918d32011-12-13 17:22:05 +01006504 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6505 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006506 err = -ENOENT;
6507 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006508 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006509
Johannes Berg00918d32011-12-13 17:22:05 +01006510 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006511 err = -EOPNOTSUPP;
6512 goto out_err;
6513 }
6514
6515 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006516 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006517 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6518 NL80211_CMD_TESTMODE);
6519 struct nlattr *tmdata;
6520
David S. Miller9360ffd2012-03-29 04:41:26 -04006521 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006522 genlmsg_cancel(skb, hdr);
6523 break;
6524 }
6525
6526 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6527 if (!tmdata) {
6528 genlmsg_cancel(skb, hdr);
6529 break;
6530 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006531 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006532 nla_nest_end(skb, tmdata);
6533
6534 if (err == -ENOBUFS || err == -ENOENT) {
6535 genlmsg_cancel(skb, hdr);
6536 break;
6537 } else if (err) {
6538 genlmsg_cancel(skb, hdr);
6539 goto out_err;
6540 }
6541
6542 genlmsg_end(skb, hdr);
6543 }
6544
6545 err = skb->len;
6546 /* see above */
6547 cb->args[0] = phy_idx + 1;
6548 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006549 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006550 return err;
6551}
6552
Johannes Bergaff89a92009-07-01 21:26:51 +02006553static struct sk_buff *
6554__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006555 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006556{
6557 struct sk_buff *skb;
6558 void *hdr;
6559 struct nlattr *data;
6560
6561 skb = nlmsg_new(approxlen + 100, gfp);
6562 if (!skb)
6563 return NULL;
6564
Eric W. Biederman15e47302012-09-07 20:12:54 +00006565 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006566 if (!hdr) {
6567 kfree_skb(skb);
6568 return NULL;
6569 }
6570
David S. Miller9360ffd2012-03-29 04:41:26 -04006571 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6572 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006573 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6574
6575 ((void **)skb->cb)[0] = rdev;
6576 ((void **)skb->cb)[1] = hdr;
6577 ((void **)skb->cb)[2] = data;
6578
6579 return skb;
6580
6581 nla_put_failure:
6582 kfree_skb(skb);
6583 return NULL;
6584}
6585
6586struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6587 int approxlen)
6588{
6589 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6590
6591 if (WARN_ON(!rdev->testmode_info))
6592 return NULL;
6593
6594 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006595 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006596 rdev->testmode_info->snd_seq,
6597 GFP_KERNEL);
6598}
6599EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6600
6601int cfg80211_testmode_reply(struct sk_buff *skb)
6602{
6603 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6604 void *hdr = ((void **)skb->cb)[1];
6605 struct nlattr *data = ((void **)skb->cb)[2];
6606
6607 if (WARN_ON(!rdev->testmode_info)) {
6608 kfree_skb(skb);
6609 return -EINVAL;
6610 }
6611
6612 nla_nest_end(skb, data);
6613 genlmsg_end(skb, hdr);
6614 return genlmsg_reply(skb, rdev->testmode_info);
6615}
6616EXPORT_SYMBOL(cfg80211_testmode_reply);
6617
6618struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6619 int approxlen, gfp_t gfp)
6620{
6621 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6622
6623 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6624}
6625EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6626
6627void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6628{
6629 void *hdr = ((void **)skb->cb)[1];
6630 struct nlattr *data = ((void **)skb->cb)[2];
6631
6632 nla_nest_end(skb, data);
6633 genlmsg_end(skb, hdr);
6634 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6635}
6636EXPORT_SYMBOL(cfg80211_testmode_event);
6637#endif
6638
Samuel Ortizb23aa672009-07-01 21:26:54 +02006639static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6640{
Johannes Berg4c476992010-10-04 21:36:35 +02006641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6642 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006643 struct cfg80211_connect_params connect;
6644 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006645 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006646 int err;
6647
6648 memset(&connect, 0, sizeof(connect));
6649
6650 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6651 return -EINVAL;
6652
6653 if (!info->attrs[NL80211_ATTR_SSID] ||
6654 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6655 return -EINVAL;
6656
6657 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6658 connect.auth_type =
6659 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006660 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6661 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006662 return -EINVAL;
6663 } else
6664 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6665
6666 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6667
Johannes Bergc0692b82010-08-27 14:26:53 +03006668 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006669 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006670 if (err)
6671 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006672
Johannes Berg074ac8d2010-09-16 14:58:22 +02006673 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006674 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6675 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006676
Johannes Berg79c97e92009-07-07 03:56:12 +02006677 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006678
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306679 connect.bg_scan_period = -1;
6680 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6681 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6682 connect.bg_scan_period =
6683 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6684 }
6685
Samuel Ortizb23aa672009-07-01 21:26:54 +02006686 if (info->attrs[NL80211_ATTR_MAC])
6687 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6688 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6689 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6690
6691 if (info->attrs[NL80211_ATTR_IE]) {
6692 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6693 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6694 }
6695
Jouni Malinencee00a92013-01-15 17:15:57 +02006696 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6697 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6698 if (connect.mfp != NL80211_MFP_REQUIRED &&
6699 connect.mfp != NL80211_MFP_NO)
6700 return -EINVAL;
6701 } else {
6702 connect.mfp = NL80211_MFP_NO;
6703 }
6704
Samuel Ortizb23aa672009-07-01 21:26:54 +02006705 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6706 connect.channel =
6707 ieee80211_get_channel(wiphy,
6708 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6709 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006710 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6711 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006712 }
6713
Johannes Bergfffd0932009-07-08 14:22:54 +02006714 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6715 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306716 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006717 if (IS_ERR(connkeys))
6718 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006719 }
6720
Ben Greear7e7c8922011-11-18 11:31:59 -08006721 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6722 connect.flags |= ASSOC_REQ_DISABLE_HT;
6723
6724 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6725 memcpy(&connect.ht_capa_mask,
6726 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6727 sizeof(connect.ht_capa_mask));
6728
6729 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006730 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6731 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006732 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006733 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006734 memcpy(&connect.ht_capa,
6735 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6736 sizeof(connect.ht_capa));
6737 }
6738
Johannes Bergee2aca32013-02-21 17:36:01 +01006739 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6740 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6741
6742 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6743 memcpy(&connect.vht_capa_mask,
6744 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6745 sizeof(connect.vht_capa_mask));
6746
6747 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6748 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6749 kfree(connkeys);
6750 return -EINVAL;
6751 }
6752 memcpy(&connect.vht_capa,
6753 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6754 sizeof(connect.vht_capa));
6755 }
6756
Johannes Berg83739b02013-05-15 17:44:01 +02006757 wdev_lock(dev->ieee80211_ptr);
6758 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6759 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006760 if (err)
6761 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006762 return err;
6763}
6764
6765static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6766{
Johannes Berg4c476992010-10-04 21:36:35 +02006767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6768 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006769 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006770 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006771
6772 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6773 reason = WLAN_REASON_DEAUTH_LEAVING;
6774 else
6775 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6776
6777 if (reason == 0)
6778 return -EINVAL;
6779
Johannes Berg074ac8d2010-09-16 14:58:22 +02006780 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006781 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6782 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006783
Johannes Berg83739b02013-05-15 17:44:01 +02006784 wdev_lock(dev->ieee80211_ptr);
6785 ret = cfg80211_disconnect(rdev, dev, reason, true);
6786 wdev_unlock(dev->ieee80211_ptr);
6787 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006788}
6789
Johannes Berg463d0182009-07-14 00:33:35 +02006790static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6791{
Johannes Berg4c476992010-10-04 21:36:35 +02006792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006793 struct net *net;
6794 int err;
6795 u32 pid;
6796
6797 if (!info->attrs[NL80211_ATTR_PID])
6798 return -EINVAL;
6799
6800 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6801
Johannes Berg463d0182009-07-14 00:33:35 +02006802 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006803 if (IS_ERR(net))
6804 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006805
6806 err = 0;
6807
6808 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006809 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6810 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006811
Johannes Berg463d0182009-07-14 00:33:35 +02006812 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006813 return err;
6814}
6815
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006816static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6817{
Johannes Berg4c476992010-10-04 21:36:35 +02006818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006819 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6820 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006821 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006822 struct cfg80211_pmksa pmksa;
6823
6824 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6825
6826 if (!info->attrs[NL80211_ATTR_MAC])
6827 return -EINVAL;
6828
6829 if (!info->attrs[NL80211_ATTR_PMKID])
6830 return -EINVAL;
6831
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006832 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6833 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6834
Johannes Berg074ac8d2010-09-16 14:58:22 +02006835 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006836 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6837 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006838
6839 switch (info->genlhdr->cmd) {
6840 case NL80211_CMD_SET_PMKSA:
6841 rdev_ops = rdev->ops->set_pmksa;
6842 break;
6843 case NL80211_CMD_DEL_PMKSA:
6844 rdev_ops = rdev->ops->del_pmksa;
6845 break;
6846 default:
6847 WARN_ON(1);
6848 break;
6849 }
6850
Johannes Berg4c476992010-10-04 21:36:35 +02006851 if (!rdev_ops)
6852 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006853
Johannes Berg4c476992010-10-04 21:36:35 +02006854 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006855}
6856
6857static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6858{
Johannes Berg4c476992010-10-04 21:36:35 +02006859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6860 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006861
Johannes Berg074ac8d2010-09-16 14:58:22 +02006862 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006863 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6864 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006865
Johannes Berg4c476992010-10-04 21:36:35 +02006866 if (!rdev->ops->flush_pmksa)
6867 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006868
Hila Gonene35e4d22012-06-27 17:19:42 +03006869 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006870}
6871
Arik Nemtsov109086c2011-09-28 14:12:50 +03006872static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6873{
6874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6875 struct net_device *dev = info->user_ptr[1];
6876 u8 action_code, dialog_token;
6877 u16 status_code;
6878 u8 *peer;
6879
6880 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6881 !rdev->ops->tdls_mgmt)
6882 return -EOPNOTSUPP;
6883
6884 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6885 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6886 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6887 !info->attrs[NL80211_ATTR_IE] ||
6888 !info->attrs[NL80211_ATTR_MAC])
6889 return -EINVAL;
6890
6891 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6892 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6893 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6894 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6895
Hila Gonene35e4d22012-06-27 17:19:42 +03006896 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6897 dialog_token, status_code,
6898 nla_data(info->attrs[NL80211_ATTR_IE]),
6899 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006900}
6901
6902static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6903{
6904 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6905 struct net_device *dev = info->user_ptr[1];
6906 enum nl80211_tdls_operation operation;
6907 u8 *peer;
6908
6909 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6910 !rdev->ops->tdls_oper)
6911 return -EOPNOTSUPP;
6912
6913 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6914 !info->attrs[NL80211_ATTR_MAC])
6915 return -EINVAL;
6916
6917 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6918 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6919
Hila Gonene35e4d22012-06-27 17:19:42 +03006920 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006921}
6922
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006923static int nl80211_remain_on_channel(struct sk_buff *skb,
6924 struct genl_info *info)
6925{
Johannes Berg4c476992010-10-04 21:36:35 +02006926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006927 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006928 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006929 struct sk_buff *msg;
6930 void *hdr;
6931 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006932 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006933 int err;
6934
6935 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6936 !info->attrs[NL80211_ATTR_DURATION])
6937 return -EINVAL;
6938
6939 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6940
Johannes Berg7c4ef712011-11-18 15:33:48 +01006941 if (!rdev->ops->remain_on_channel ||
6942 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006943 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006944
Johannes Bergebf348f2012-06-01 12:50:54 +02006945 /*
6946 * We should be on that channel for at least a minimum amount of
6947 * time (10ms) but no longer than the driver supports.
6948 */
6949 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6950 duration > rdev->wiphy.max_remain_on_channel_duration)
6951 return -EINVAL;
6952
Johannes Berg683b6d32012-11-08 21:25:48 +01006953 err = nl80211_parse_chandef(rdev, info, &chandef);
6954 if (err)
6955 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006956
6957 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006958 if (!msg)
6959 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006960
Eric W. Biederman15e47302012-09-07 20:12:54 +00006961 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006962 NL80211_CMD_REMAIN_ON_CHANNEL);
6963
6964 if (IS_ERR(hdr)) {
6965 err = PTR_ERR(hdr);
6966 goto free_msg;
6967 }
6968
Johannes Berg683b6d32012-11-08 21:25:48 +01006969 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
6970 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006971
6972 if (err)
6973 goto free_msg;
6974
David S. Miller9360ffd2012-03-29 04:41:26 -04006975 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
6976 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006977
6978 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006979
6980 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006981
6982 nla_put_failure:
6983 err = -ENOBUFS;
6984 free_msg:
6985 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006986 return err;
6987}
6988
6989static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
6990 struct genl_info *info)
6991{
Johannes Berg4c476992010-10-04 21:36:35 +02006992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006993 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006994 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006995
6996 if (!info->attrs[NL80211_ATTR_COOKIE])
6997 return -EINVAL;
6998
Johannes Berg4c476992010-10-04 21:36:35 +02006999 if (!rdev->ops->cancel_remain_on_channel)
7000 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007001
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007002 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7003
Hila Gonene35e4d22012-06-27 17:19:42 +03007004 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007005}
7006
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007007static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7008 u8 *rates, u8 rates_len)
7009{
7010 u8 i;
7011 u32 mask = 0;
7012
7013 for (i = 0; i < rates_len; i++) {
7014 int rate = (rates[i] & 0x7f) * 5;
7015 int ridx;
7016 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7017 struct ieee80211_rate *srate =
7018 &sband->bitrates[ridx];
7019 if (rate == srate->bitrate) {
7020 mask |= 1 << ridx;
7021 break;
7022 }
7023 }
7024 if (ridx == sband->n_bitrates)
7025 return 0; /* rate not found */
7026 }
7027
7028 return mask;
7029}
7030
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007031static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7032 u8 *rates, u8 rates_len,
7033 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7034{
7035 u8 i;
7036
7037 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7038
7039 for (i = 0; i < rates_len; i++) {
7040 int ridx, rbit;
7041
7042 ridx = rates[i] / 8;
7043 rbit = BIT(rates[i] % 8);
7044
7045 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007046 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007047 return false;
7048
7049 /* check availability */
7050 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7051 mcs[ridx] |= rbit;
7052 else
7053 return false;
7054 }
7055
7056 return true;
7057}
7058
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007059static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007060 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7061 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007062 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7063 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007064};
7065
7066static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7067 struct genl_info *info)
7068{
7069 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007070 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007071 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007072 int rem, i;
7073 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007074 struct nlattr *tx_rates;
7075 struct ieee80211_supported_band *sband;
7076
7077 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7078 return -EINVAL;
7079
Johannes Berg4c476992010-10-04 21:36:35 +02007080 if (!rdev->ops->set_bitrate_mask)
7081 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007082
7083 memset(&mask, 0, sizeof(mask));
7084 /* Default to all rates enabled */
7085 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7086 sband = rdev->wiphy.bands[i];
7087 mask.control[i].legacy =
7088 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007089 if (sband)
7090 memcpy(mask.control[i].mcs,
7091 sband->ht_cap.mcs.rx_mask,
7092 sizeof(mask.control[i].mcs));
7093 else
7094 memset(mask.control[i].mcs, 0,
7095 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007096 }
7097
7098 /*
7099 * The nested attribute uses enum nl80211_band as the index. This maps
7100 * directly to the enum ieee80211_band values used in cfg80211.
7101 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007102 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007103 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7104 {
7105 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007106 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7107 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007108 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007109 if (sband == NULL)
7110 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007111 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7112 nla_len(tx_rates), nl80211_txattr_policy);
7113 if (tb[NL80211_TXRATE_LEGACY]) {
7114 mask.control[band].legacy = rateset_to_mask(
7115 sband,
7116 nla_data(tb[NL80211_TXRATE_LEGACY]),
7117 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307118 if ((mask.control[band].legacy == 0) &&
7119 nla_len(tb[NL80211_TXRATE_LEGACY]))
7120 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007121 }
7122 if (tb[NL80211_TXRATE_MCS]) {
7123 if (!ht_rateset_to_mask(
7124 sband,
7125 nla_data(tb[NL80211_TXRATE_MCS]),
7126 nla_len(tb[NL80211_TXRATE_MCS]),
7127 mask.control[band].mcs))
7128 return -EINVAL;
7129 }
7130
7131 if (mask.control[band].legacy == 0) {
7132 /* don't allow empty legacy rates if HT
7133 * is not even supported. */
7134 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7135 return -EINVAL;
7136
7137 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7138 if (mask.control[band].mcs[i])
7139 break;
7140
7141 /* legacy and mcs rates may not be both empty */
7142 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007143 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007144 }
7145 }
7146
Hila Gonene35e4d22012-06-27 17:19:42 +03007147 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007148}
7149
Johannes Berg2e161f72010-08-12 15:38:38 +02007150static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007151{
Johannes Berg4c476992010-10-04 21:36:35 +02007152 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007153 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007154 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007155
7156 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7157 return -EINVAL;
7158
Johannes Berg2e161f72010-08-12 15:38:38 +02007159 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7160 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007161
Johannes Berg71bbc992012-06-15 15:30:18 +02007162 switch (wdev->iftype) {
7163 case NL80211_IFTYPE_STATION:
7164 case NL80211_IFTYPE_ADHOC:
7165 case NL80211_IFTYPE_P2P_CLIENT:
7166 case NL80211_IFTYPE_AP:
7167 case NL80211_IFTYPE_AP_VLAN:
7168 case NL80211_IFTYPE_MESH_POINT:
7169 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007170 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007171 break;
7172 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007173 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007174 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007175
7176 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007177 if (!rdev->ops->mgmt_tx)
7178 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007179
Eric W. Biederman15e47302012-09-07 20:12:54 +00007180 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007181 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7182 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007183}
7184
Johannes Berg2e161f72010-08-12 15:38:38 +02007185static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007186{
Johannes Berg4c476992010-10-04 21:36:35 +02007187 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007188 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007189 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007190 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007191 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007192 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007193 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007194 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007195 bool offchan, no_cck, dont_wait_for_ack;
7196
7197 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007198
Johannes Berg683b6d32012-11-08 21:25:48 +01007199 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007200 return -EINVAL;
7201
Johannes Berg4c476992010-10-04 21:36:35 +02007202 if (!rdev->ops->mgmt_tx)
7203 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007204
Johannes Berg71bbc992012-06-15 15:30:18 +02007205 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007206 case NL80211_IFTYPE_P2P_DEVICE:
7207 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7208 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007209 case NL80211_IFTYPE_STATION:
7210 case NL80211_IFTYPE_ADHOC:
7211 case NL80211_IFTYPE_P2P_CLIENT:
7212 case NL80211_IFTYPE_AP:
7213 case NL80211_IFTYPE_AP_VLAN:
7214 case NL80211_IFTYPE_MESH_POINT:
7215 case NL80211_IFTYPE_P2P_GO:
7216 break;
7217 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007218 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007219 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007220
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007221 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007222 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007223 return -EINVAL;
7224 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007225
7226 /*
7227 * We should wait on the channel for at least a minimum amount
7228 * of time (10ms) but no longer than the driver supports.
7229 */
7230 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7231 wait > rdev->wiphy.max_remain_on_channel_duration)
7232 return -EINVAL;
7233
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007234 }
7235
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007236 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7237
Johannes Berg7c4ef712011-11-18 15:33:48 +01007238 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7239 return -EINVAL;
7240
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307241 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7242
Antonio Quartulliea141b752013-06-11 14:20:03 +02007243 /* get the channel if any has been specified, otherwise pass NULL to
7244 * the driver. The latter will use the current one
7245 */
7246 chandef.chan = NULL;
7247 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7248 err = nl80211_parse_chandef(rdev, info, &chandef);
7249 if (err)
7250 return err;
7251 }
7252
7253 if (!chandef.chan && offchan)
7254 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007255
Johannes Berge247bd902011-11-04 11:18:21 +01007256 if (!dont_wait_for_ack) {
7257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7258 if (!msg)
7259 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007260
Eric W. Biederman15e47302012-09-07 20:12:54 +00007261 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007262 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007263
Johannes Berge247bd902011-11-04 11:18:21 +01007264 if (IS_ERR(hdr)) {
7265 err = PTR_ERR(hdr);
7266 goto free_msg;
7267 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007268 }
Johannes Berge247bd902011-11-04 11:18:21 +01007269
Johannes Berg683b6d32012-11-08 21:25:48 +01007270 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007271 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7272 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007273 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007274 if (err)
7275 goto free_msg;
7276
Johannes Berge247bd902011-11-04 11:18:21 +01007277 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007278 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7279 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007280
Johannes Berge247bd902011-11-04 11:18:21 +01007281 genlmsg_end(msg, hdr);
7282 return genlmsg_reply(msg, info);
7283 }
7284
7285 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007286
7287 nla_put_failure:
7288 err = -ENOBUFS;
7289 free_msg:
7290 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007291 return err;
7292}
7293
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007294static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7295{
7296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007297 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007298 u64 cookie;
7299
7300 if (!info->attrs[NL80211_ATTR_COOKIE])
7301 return -EINVAL;
7302
7303 if (!rdev->ops->mgmt_tx_cancel_wait)
7304 return -EOPNOTSUPP;
7305
Johannes Berg71bbc992012-06-15 15:30:18 +02007306 switch (wdev->iftype) {
7307 case NL80211_IFTYPE_STATION:
7308 case NL80211_IFTYPE_ADHOC:
7309 case NL80211_IFTYPE_P2P_CLIENT:
7310 case NL80211_IFTYPE_AP:
7311 case NL80211_IFTYPE_AP_VLAN:
7312 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007313 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007314 break;
7315 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007316 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007317 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007318
7319 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7320
Hila Gonene35e4d22012-06-27 17:19:42 +03007321 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007322}
7323
Kalle Valoffb9eb32010-02-17 17:58:10 +02007324static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7325{
Johannes Berg4c476992010-10-04 21:36:35 +02007326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007327 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007328 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007329 u8 ps_state;
7330 bool state;
7331 int err;
7332
Johannes Berg4c476992010-10-04 21:36:35 +02007333 if (!info->attrs[NL80211_ATTR_PS_STATE])
7334 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007335
7336 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7337
Johannes Berg4c476992010-10-04 21:36:35 +02007338 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7339 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007340
7341 wdev = dev->ieee80211_ptr;
7342
Johannes Berg4c476992010-10-04 21:36:35 +02007343 if (!rdev->ops->set_power_mgmt)
7344 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007345
7346 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7347
7348 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007349 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007350
Hila Gonene35e4d22012-06-27 17:19:42 +03007351 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007352 if (!err)
7353 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007354 return err;
7355}
7356
7357static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7358{
Johannes Berg4c476992010-10-04 21:36:35 +02007359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007360 enum nl80211_ps_state ps_state;
7361 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007362 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007363 struct sk_buff *msg;
7364 void *hdr;
7365 int err;
7366
Kalle Valoffb9eb32010-02-17 17:58:10 +02007367 wdev = dev->ieee80211_ptr;
7368
Johannes Berg4c476992010-10-04 21:36:35 +02007369 if (!rdev->ops->set_power_mgmt)
7370 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007371
7372 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007373 if (!msg)
7374 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007375
Eric W. Biederman15e47302012-09-07 20:12:54 +00007376 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007377 NL80211_CMD_GET_POWER_SAVE);
7378 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007379 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007380 goto free_msg;
7381 }
7382
7383 if (wdev->ps)
7384 ps_state = NL80211_PS_ENABLED;
7385 else
7386 ps_state = NL80211_PS_DISABLED;
7387
David S. Miller9360ffd2012-03-29 04:41:26 -04007388 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7389 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007390
7391 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007392 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007393
Johannes Berg4c476992010-10-04 21:36:35 +02007394 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007395 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007396 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007397 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007398 return err;
7399}
7400
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007401static struct nla_policy
7402nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7403 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7404 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7405 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007406 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7407 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7408 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007409};
7410
Thomas Pedersen84f10702012-07-12 16:17:33 -07007411static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007412 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007413{
7414 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7415 struct wireless_dev *wdev;
7416 struct net_device *dev = info->user_ptr[1];
7417
Johannes Bergd9d8b012012-11-26 12:51:52 +01007418 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007419 return -EINVAL;
7420
7421 wdev = dev->ieee80211_ptr;
7422
7423 if (!rdev->ops->set_cqm_txe_config)
7424 return -EOPNOTSUPP;
7425
7426 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7427 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7428 return -EOPNOTSUPP;
7429
Hila Gonene35e4d22012-06-27 17:19:42 +03007430 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007431}
7432
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007433static int nl80211_set_cqm_rssi(struct genl_info *info,
7434 s32 threshold, u32 hysteresis)
7435{
Johannes Berg4c476992010-10-04 21:36:35 +02007436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007437 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007438 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007439
7440 if (threshold > 0)
7441 return -EINVAL;
7442
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007443 wdev = dev->ieee80211_ptr;
7444
Johannes Berg4c476992010-10-04 21:36:35 +02007445 if (!rdev->ops->set_cqm_rssi_config)
7446 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007447
Johannes Berg074ac8d2010-09-16 14:58:22 +02007448 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007449 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7450 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007451
Hila Gonene35e4d22012-06-27 17:19:42 +03007452 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007453}
7454
7455static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7456{
7457 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7458 struct nlattr *cqm;
7459 int err;
7460
7461 cqm = info->attrs[NL80211_ATTR_CQM];
7462 if (!cqm) {
7463 err = -EINVAL;
7464 goto out;
7465 }
7466
7467 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7468 nl80211_attr_cqm_policy);
7469 if (err)
7470 goto out;
7471
7472 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7473 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7474 s32 threshold;
7475 u32 hysteresis;
7476 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7477 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7478 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007479 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7480 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7481 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7482 u32 rate, pkts, intvl;
7483 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7484 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7485 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7486 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007487 } else
7488 err = -EINVAL;
7489
7490out:
7491 return err;
7492}
7493
Johannes Berg29cbe682010-12-03 09:20:44 +01007494static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7495{
7496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7497 struct net_device *dev = info->user_ptr[1];
7498 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007499 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007500 int err;
7501
7502 /* start with default */
7503 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007504 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007505
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007506 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007507 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007508 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007509 if (err)
7510 return err;
7511 }
7512
7513 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7514 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7515 return -EINVAL;
7516
Javier Cardonac80d5452010-12-16 17:37:49 -08007517 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7518 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7519
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007520 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7521 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7522 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7523 return -EINVAL;
7524
Marco Porsch9bdbf042013-01-07 16:04:51 +01007525 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7526 setup.beacon_interval =
7527 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7528 if (setup.beacon_interval < 10 ||
7529 setup.beacon_interval > 10000)
7530 return -EINVAL;
7531 }
7532
7533 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7534 setup.dtim_period =
7535 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7536 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7537 return -EINVAL;
7538 }
7539
Javier Cardonac80d5452010-12-16 17:37:49 -08007540 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7541 /* parse additional setup parameters if given */
7542 err = nl80211_parse_mesh_setup(info, &setup);
7543 if (err)
7544 return err;
7545 }
7546
Thomas Pedersend37bb182013-03-04 13:06:13 -08007547 if (setup.user_mpm)
7548 cfg.auto_open_plinks = false;
7549
Johannes Bergcc1d2802012-05-16 23:50:20 +02007550 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007551 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7552 if (err)
7553 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007554 } else {
7555 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007556 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007557 }
7558
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007559 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7560 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7561 int n_rates =
7562 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7563 struct ieee80211_supported_band *sband;
7564
7565 if (!setup.chandef.chan)
7566 return -EINVAL;
7567
7568 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7569
7570 err = ieee80211_get_ratemask(sband, rates, n_rates,
7571 &setup.basic_rates);
7572 if (err)
7573 return err;
7574 }
7575
Javier Cardonac80d5452010-12-16 17:37:49 -08007576 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007577}
7578
7579static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7580{
7581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7582 struct net_device *dev = info->user_ptr[1];
7583
7584 return cfg80211_leave_mesh(rdev, dev);
7585}
7586
Johannes Bergdfb89c52012-06-27 09:23:48 +02007587#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007588static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7589 struct cfg80211_registered_device *rdev)
7590{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007591 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007592 struct nlattr *nl_pats, *nl_pat;
7593 int i, pat_len;
7594
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007595 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007596 return 0;
7597
7598 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7599 if (!nl_pats)
7600 return -ENOBUFS;
7601
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007602 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007603 nl_pat = nla_nest_start(msg, i + 1);
7604 if (!nl_pat)
7605 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007606 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007607 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007608 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007609 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7610 wowlan->patterns[i].pattern) ||
7611 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007612 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007613 return -ENOBUFS;
7614 nla_nest_end(msg, nl_pat);
7615 }
7616 nla_nest_end(msg, nl_pats);
7617
7618 return 0;
7619}
7620
Johannes Berg2a0e0472013-01-23 22:57:40 +01007621static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7622 struct cfg80211_wowlan_tcp *tcp)
7623{
7624 struct nlattr *nl_tcp;
7625
7626 if (!tcp)
7627 return 0;
7628
7629 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7630 if (!nl_tcp)
7631 return -ENOBUFS;
7632
7633 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7634 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7635 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7636 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7637 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7638 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7639 tcp->payload_len, tcp->payload) ||
7640 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7641 tcp->data_interval) ||
7642 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7643 tcp->wake_len, tcp->wake_data) ||
7644 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7645 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7646 return -ENOBUFS;
7647
7648 if (tcp->payload_seq.len &&
7649 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7650 sizeof(tcp->payload_seq), &tcp->payload_seq))
7651 return -ENOBUFS;
7652
7653 if (tcp->payload_tok.len &&
7654 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7655 sizeof(tcp->payload_tok) + tcp->tokens_size,
7656 &tcp->payload_tok))
7657 return -ENOBUFS;
7658
Johannes Berge248ad32013-05-16 10:24:28 +02007659 nla_nest_end(msg, nl_tcp);
7660
Johannes Berg2a0e0472013-01-23 22:57:40 +01007661 return 0;
7662}
7663
Johannes Bergff1b6e62011-05-04 15:37:28 +02007664static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7665{
7666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7667 struct sk_buff *msg;
7668 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007669 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007670
Johannes Berg964dc9e2013-06-03 17:25:34 +02007671 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007672 return -EOPNOTSUPP;
7673
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007674 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007675 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007676 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7677 rdev->wiphy.wowlan_config->tcp->payload_len +
7678 rdev->wiphy.wowlan_config->tcp->wake_len +
7679 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007680 }
7681
7682 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007683 if (!msg)
7684 return -ENOMEM;
7685
Eric W. Biederman15e47302012-09-07 20:12:54 +00007686 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007687 NL80211_CMD_GET_WOWLAN);
7688 if (!hdr)
7689 goto nla_put_failure;
7690
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007691 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007692 struct nlattr *nl_wowlan;
7693
7694 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7695 if (!nl_wowlan)
7696 goto nla_put_failure;
7697
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007698 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007699 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007700 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007701 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007702 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007703 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007704 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007705 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007706 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007707 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007708 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007709 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007710 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007711 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7712 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007713
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007714 if (nl80211_send_wowlan_patterns(msg, rdev))
7715 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007716
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007717 if (nl80211_send_wowlan_tcp(msg,
7718 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007719 goto nla_put_failure;
7720
Johannes Bergff1b6e62011-05-04 15:37:28 +02007721 nla_nest_end(msg, nl_wowlan);
7722 }
7723
7724 genlmsg_end(msg, hdr);
7725 return genlmsg_reply(msg, info);
7726
7727nla_put_failure:
7728 nlmsg_free(msg);
7729 return -ENOBUFS;
7730}
7731
Johannes Berg2a0e0472013-01-23 22:57:40 +01007732static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7733 struct nlattr *attr,
7734 struct cfg80211_wowlan *trig)
7735{
7736 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7737 struct cfg80211_wowlan_tcp *cfg;
7738 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7739 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7740 u32 size;
7741 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7742 int err, port;
7743
Johannes Berg964dc9e2013-06-03 17:25:34 +02007744 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007745 return -EINVAL;
7746
7747 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7748 nla_data(attr), nla_len(attr),
7749 nl80211_wowlan_tcp_policy);
7750 if (err)
7751 return err;
7752
7753 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7754 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7755 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7756 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7757 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7758 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7759 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7760 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7761 return -EINVAL;
7762
7763 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007764 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007765 return -EINVAL;
7766
7767 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007768 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007769 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007770 return -EINVAL;
7771
7772 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007773 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007774 return -EINVAL;
7775
7776 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7777 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7778 return -EINVAL;
7779
7780 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7781 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7782
7783 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7784 tokens_size = tokln - sizeof(*tok);
7785
7786 if (!tok->len || tokens_size % tok->len)
7787 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007788 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007789 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007790 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007791 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007792 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007793 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007794 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007795 return -EINVAL;
7796 if (tok->offset + tok->len > data_size)
7797 return -EINVAL;
7798 }
7799
7800 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7801 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007802 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007803 return -EINVAL;
7804 if (seq->len == 0 || seq->len > 4)
7805 return -EINVAL;
7806 if (seq->len + seq->offset > data_size)
7807 return -EINVAL;
7808 }
7809
7810 size = sizeof(*cfg);
7811 size += data_size;
7812 size += wake_size + wake_mask_size;
7813 size += tokens_size;
7814
7815 cfg = kzalloc(size, GFP_KERNEL);
7816 if (!cfg)
7817 return -ENOMEM;
7818 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7819 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7820 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7821 ETH_ALEN);
7822 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7823 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7824 else
7825 port = 0;
7826#ifdef CONFIG_INET
7827 /* allocate a socket and port for it and use it */
7828 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7829 IPPROTO_TCP, &cfg->sock, 1);
7830 if (err) {
7831 kfree(cfg);
7832 return err;
7833 }
7834 if (inet_csk_get_port(cfg->sock->sk, port)) {
7835 sock_release(cfg->sock);
7836 kfree(cfg);
7837 return -EADDRINUSE;
7838 }
7839 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7840#else
7841 if (!port) {
7842 kfree(cfg);
7843 return -EINVAL;
7844 }
7845 cfg->src_port = port;
7846#endif
7847
7848 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7849 cfg->payload_len = data_size;
7850 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7851 memcpy((void *)cfg->payload,
7852 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7853 data_size);
7854 if (seq)
7855 cfg->payload_seq = *seq;
7856 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7857 cfg->wake_len = wake_size;
7858 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7859 memcpy((void *)cfg->wake_data,
7860 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7861 wake_size);
7862 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7863 data_size + wake_size;
7864 memcpy((void *)cfg->wake_mask,
7865 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7866 wake_mask_size);
7867 if (tok) {
7868 cfg->tokens_size = tokens_size;
7869 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7870 }
7871
7872 trig->tcp = cfg;
7873
7874 return 0;
7875}
7876
Johannes Bergff1b6e62011-05-04 15:37:28 +02007877static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7878{
7879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7880 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007881 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007882 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007883 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007884 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007885 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007886
Johannes Berg964dc9e2013-06-03 17:25:34 +02007887 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007888 return -EOPNOTSUPP;
7889
Johannes Bergae33bd82012-07-12 16:25:02 +02007890 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7891 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007892 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007893 goto set_wakeup;
7894 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007895
7896 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7897 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7898 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7899 nl80211_wowlan_policy);
7900 if (err)
7901 return err;
7902
7903 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7904 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7905 return -EINVAL;
7906 new_triggers.any = true;
7907 }
7908
7909 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7910 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7911 return -EINVAL;
7912 new_triggers.disconnect = true;
7913 }
7914
7915 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7916 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7917 return -EINVAL;
7918 new_triggers.magic_pkt = true;
7919 }
7920
Johannes Berg77dbbb12011-07-13 10:48:55 +02007921 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7922 return -EINVAL;
7923
7924 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7925 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7926 return -EINVAL;
7927 new_triggers.gtk_rekey_failure = true;
7928 }
7929
7930 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7931 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7932 return -EINVAL;
7933 new_triggers.eap_identity_req = true;
7934 }
7935
7936 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7937 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7938 return -EINVAL;
7939 new_triggers.four_way_handshake = true;
7940 }
7941
7942 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7943 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7944 return -EINVAL;
7945 new_triggers.rfkill_release = true;
7946 }
7947
Johannes Bergff1b6e62011-05-04 15:37:28 +02007948 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7949 struct nlattr *pat;
7950 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007951 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007952 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007953
7954 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7955 rem)
7956 n_patterns++;
7957 if (n_patterns > wowlan->n_patterns)
7958 return -EINVAL;
7959
7960 new_triggers.patterns = kcalloc(n_patterns,
7961 sizeof(new_triggers.patterns[0]),
7962 GFP_KERNEL);
7963 if (!new_triggers.patterns)
7964 return -ENOMEM;
7965
7966 new_triggers.n_patterns = n_patterns;
7967 i = 0;
7968
7969 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7970 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007971 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
7972 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007973 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007974 if (!pat_tb[NL80211_PKTPAT_MASK] ||
7975 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02007976 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007977 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007978 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007979 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007980 goto error;
7981 if (pat_len > wowlan->pattern_max_len ||
7982 pat_len < wowlan->pattern_min_len)
7983 goto error;
7984
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007985 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007986 pkt_offset = 0;
7987 else
7988 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007989 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007990 if (pkt_offset > wowlan->max_pkt_offset)
7991 goto error;
7992 new_triggers.patterns[i].pkt_offset = pkt_offset;
7993
Johannes Bergff1b6e62011-05-04 15:37:28 +02007994 new_triggers.patterns[i].mask =
7995 kmalloc(mask_len + pat_len, GFP_KERNEL);
7996 if (!new_triggers.patterns[i].mask) {
7997 err = -ENOMEM;
7998 goto error;
7999 }
8000 new_triggers.patterns[i].pattern =
8001 new_triggers.patterns[i].mask + mask_len;
8002 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008003 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008004 mask_len);
8005 new_triggers.patterns[i].pattern_len = pat_len;
8006 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008007 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008008 pat_len);
8009 i++;
8010 }
8011 }
8012
Johannes Berg2a0e0472013-01-23 22:57:40 +01008013 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8014 err = nl80211_parse_wowlan_tcp(
8015 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8016 &new_triggers);
8017 if (err)
8018 goto error;
8019 }
8020
Johannes Bergae33bd82012-07-12 16:25:02 +02008021 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8022 if (!ntrig) {
8023 err = -ENOMEM;
8024 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008025 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008026 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008027 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008028
Johannes Bergae33bd82012-07-12 16:25:02 +02008029 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008030 if (rdev->ops->set_wakeup &&
8031 prev_enabled != !!rdev->wiphy.wowlan_config)
8032 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008033
Johannes Bergff1b6e62011-05-04 15:37:28 +02008034 return 0;
8035 error:
8036 for (i = 0; i < new_triggers.n_patterns; i++)
8037 kfree(new_triggers.patterns[i].mask);
8038 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008039 if (new_triggers.tcp && new_triggers.tcp->sock)
8040 sock_release(new_triggers.tcp->sock);
8041 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008042 return err;
8043}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008044#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008045
Johannes Berge5497d72011-07-05 16:35:40 +02008046static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8047{
8048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8049 struct net_device *dev = info->user_ptr[1];
8050 struct wireless_dev *wdev = dev->ieee80211_ptr;
8051 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8052 struct cfg80211_gtk_rekey_data rekey_data;
8053 int err;
8054
8055 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8056 return -EINVAL;
8057
8058 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8059 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8060 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8061 nl80211_rekey_policy);
8062 if (err)
8063 return err;
8064
8065 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8066 return -ERANGE;
8067 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8068 return -ERANGE;
8069 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8070 return -ERANGE;
8071
8072 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8073 NL80211_KEK_LEN);
8074 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8075 NL80211_KCK_LEN);
8076 memcpy(rekey_data.replay_ctr,
8077 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8078 NL80211_REPLAY_CTR_LEN);
8079
8080 wdev_lock(wdev);
8081 if (!wdev->current_bss) {
8082 err = -ENOTCONN;
8083 goto out;
8084 }
8085
8086 if (!rdev->ops->set_rekey_data) {
8087 err = -EOPNOTSUPP;
8088 goto out;
8089 }
8090
Hila Gonene35e4d22012-06-27 17:19:42 +03008091 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008092 out:
8093 wdev_unlock(wdev);
8094 return err;
8095}
8096
Johannes Berg28946da2011-11-04 11:18:12 +01008097static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8098 struct genl_info *info)
8099{
8100 struct net_device *dev = info->user_ptr[1];
8101 struct wireless_dev *wdev = dev->ieee80211_ptr;
8102
8103 if (wdev->iftype != NL80211_IFTYPE_AP &&
8104 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8105 return -EINVAL;
8106
Eric W. Biederman15e47302012-09-07 20:12:54 +00008107 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008108 return -EBUSY;
8109
Eric W. Biederman15e47302012-09-07 20:12:54 +00008110 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008111 return 0;
8112}
8113
Johannes Berg7f6cf312011-11-04 11:18:15 +01008114static int nl80211_probe_client(struct sk_buff *skb,
8115 struct genl_info *info)
8116{
8117 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8118 struct net_device *dev = info->user_ptr[1];
8119 struct wireless_dev *wdev = dev->ieee80211_ptr;
8120 struct sk_buff *msg;
8121 void *hdr;
8122 const u8 *addr;
8123 u64 cookie;
8124 int err;
8125
8126 if (wdev->iftype != NL80211_IFTYPE_AP &&
8127 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8128 return -EOPNOTSUPP;
8129
8130 if (!info->attrs[NL80211_ATTR_MAC])
8131 return -EINVAL;
8132
8133 if (!rdev->ops->probe_client)
8134 return -EOPNOTSUPP;
8135
8136 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8137 if (!msg)
8138 return -ENOMEM;
8139
Eric W. Biederman15e47302012-09-07 20:12:54 +00008140 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008141 NL80211_CMD_PROBE_CLIENT);
8142
8143 if (IS_ERR(hdr)) {
8144 err = PTR_ERR(hdr);
8145 goto free_msg;
8146 }
8147
8148 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8149
Hila Gonene35e4d22012-06-27 17:19:42 +03008150 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008151 if (err)
8152 goto free_msg;
8153
David S. Miller9360ffd2012-03-29 04:41:26 -04008154 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8155 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008156
8157 genlmsg_end(msg, hdr);
8158
8159 return genlmsg_reply(msg, info);
8160
8161 nla_put_failure:
8162 err = -ENOBUFS;
8163 free_msg:
8164 nlmsg_free(msg);
8165 return err;
8166}
8167
Johannes Berg5e760232011-11-04 11:18:17 +01008168static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8169{
8170 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008171 struct cfg80211_beacon_registration *reg, *nreg;
8172 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008173
8174 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8175 return -EOPNOTSUPP;
8176
Ben Greear37c73b52012-10-26 14:49:25 -07008177 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8178 if (!nreg)
8179 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008180
Ben Greear37c73b52012-10-26 14:49:25 -07008181 /* First, check if already registered. */
8182 spin_lock_bh(&rdev->beacon_registrations_lock);
8183 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8184 if (reg->nlportid == info->snd_portid) {
8185 rv = -EALREADY;
8186 goto out_err;
8187 }
8188 }
8189 /* Add it to the list */
8190 nreg->nlportid = info->snd_portid;
8191 list_add(&nreg->list, &rdev->beacon_registrations);
8192
8193 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008194
8195 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008196out_err:
8197 spin_unlock_bh(&rdev->beacon_registrations_lock);
8198 kfree(nreg);
8199 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008200}
8201
Johannes Berg98104fde2012-06-16 00:19:54 +02008202static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8203{
8204 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8205 struct wireless_dev *wdev = info->user_ptr[1];
8206 int err;
8207
8208 if (!rdev->ops->start_p2p_device)
8209 return -EOPNOTSUPP;
8210
8211 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8212 return -EOPNOTSUPP;
8213
8214 if (wdev->p2p_started)
8215 return 0;
8216
Johannes Berg98104fde2012-06-16 00:19:54 +02008217 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008218 if (err)
8219 return err;
8220
Johannes Bergeeb126e2012-10-23 15:16:50 +02008221 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008222 if (err)
8223 return err;
8224
8225 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008226 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008227
8228 return 0;
8229}
8230
8231static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8232{
8233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8234 struct wireless_dev *wdev = info->user_ptr[1];
8235
8236 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8237 return -EOPNOTSUPP;
8238
8239 if (!rdev->ops->stop_p2p_device)
8240 return -EOPNOTSUPP;
8241
Johannes Bergf9f47522013-03-19 15:04:07 +01008242 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008243
8244 return 0;
8245}
8246
Johannes Berg3713b4e2013-02-14 16:19:38 +01008247static int nl80211_get_protocol_features(struct sk_buff *skb,
8248 struct genl_info *info)
8249{
8250 void *hdr;
8251 struct sk_buff *msg;
8252
8253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8254 if (!msg)
8255 return -ENOMEM;
8256
8257 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8258 NL80211_CMD_GET_PROTOCOL_FEATURES);
8259 if (!hdr)
8260 goto nla_put_failure;
8261
8262 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8263 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8264 goto nla_put_failure;
8265
8266 genlmsg_end(msg, hdr);
8267 return genlmsg_reply(msg, info);
8268
8269 nla_put_failure:
8270 kfree_skb(msg);
8271 return -ENOBUFS;
8272}
8273
Jouni Malinen355199e2013-02-27 17:14:27 +02008274static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8275{
8276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8277 struct cfg80211_update_ft_ies_params ft_params;
8278 struct net_device *dev = info->user_ptr[1];
8279
8280 if (!rdev->ops->update_ft_ies)
8281 return -EOPNOTSUPP;
8282
8283 if (!info->attrs[NL80211_ATTR_MDID] ||
8284 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8285 return -EINVAL;
8286
8287 memset(&ft_params, 0, sizeof(ft_params));
8288 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8289 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8290 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8291
8292 return rdev_update_ft_ies(rdev, dev, &ft_params);
8293}
8294
Arend van Spriel5de17982013-04-18 15:49:00 +02008295static int nl80211_crit_protocol_start(struct sk_buff *skb,
8296 struct genl_info *info)
8297{
8298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8299 struct wireless_dev *wdev = info->user_ptr[1];
8300 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8301 u16 duration;
8302 int ret;
8303
8304 if (!rdev->ops->crit_proto_start)
8305 return -EOPNOTSUPP;
8306
8307 if (WARN_ON(!rdev->ops->crit_proto_stop))
8308 return -EINVAL;
8309
8310 if (rdev->crit_proto_nlportid)
8311 return -EBUSY;
8312
8313 /* determine protocol if provided */
8314 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8315 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8316
8317 if (proto >= NUM_NL80211_CRIT_PROTO)
8318 return -EINVAL;
8319
8320 /* timeout must be provided */
8321 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8322 return -EINVAL;
8323
8324 duration =
8325 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8326
8327 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8328 return -ERANGE;
8329
8330 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8331 if (!ret)
8332 rdev->crit_proto_nlportid = info->snd_portid;
8333
8334 return ret;
8335}
8336
8337static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8338 struct genl_info *info)
8339{
8340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8341 struct wireless_dev *wdev = info->user_ptr[1];
8342
8343 if (!rdev->ops->crit_proto_stop)
8344 return -EOPNOTSUPP;
8345
8346 if (rdev->crit_proto_nlportid) {
8347 rdev->crit_proto_nlportid = 0;
8348 rdev_crit_proto_stop(rdev, wdev);
8349 }
8350 return 0;
8351}
8352
Johannes Berg4c476992010-10-04 21:36:35 +02008353#define NL80211_FLAG_NEED_WIPHY 0x01
8354#define NL80211_FLAG_NEED_NETDEV 0x02
8355#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008356#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8357#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8358 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008359#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008360/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008361#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8362 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008363
8364static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8365 struct genl_info *info)
8366{
8367 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008368 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008369 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008370 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8371
8372 if (rtnl)
8373 rtnl_lock();
8374
8375 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008376 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008377 if (IS_ERR(rdev)) {
8378 if (rtnl)
8379 rtnl_unlock();
8380 return PTR_ERR(rdev);
8381 }
8382 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008383 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8384 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008385 ASSERT_RTNL();
8386
Johannes Berg89a54e42012-06-15 14:33:17 +02008387 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8388 info->attrs);
8389 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008390 if (rtnl)
8391 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008392 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008393 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008394
Johannes Berg89a54e42012-06-15 14:33:17 +02008395 dev = wdev->netdev;
8396 rdev = wiphy_to_dev(wdev->wiphy);
8397
Johannes Berg1bf614e2012-06-15 15:23:36 +02008398 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8399 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008400 if (rtnl)
8401 rtnl_unlock();
8402 return -EINVAL;
8403 }
8404
8405 info->user_ptr[1] = dev;
8406 } else {
8407 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008408 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008409
Johannes Berg1bf614e2012-06-15 15:23:36 +02008410 if (dev) {
8411 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8412 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008413 if (rtnl)
8414 rtnl_unlock();
8415 return -ENETDOWN;
8416 }
8417
8418 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008419 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8420 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008421 if (rtnl)
8422 rtnl_unlock();
8423 return -ENETDOWN;
8424 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008425 }
8426
Johannes Berg4c476992010-10-04 21:36:35 +02008427 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008428 }
8429
8430 return 0;
8431}
8432
8433static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8434 struct genl_info *info)
8435{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008436 if (info->user_ptr[1]) {
8437 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8438 struct wireless_dev *wdev = info->user_ptr[1];
8439
8440 if (wdev->netdev)
8441 dev_put(wdev->netdev);
8442 } else {
8443 dev_put(info->user_ptr[1]);
8444 }
8445 }
Johannes Berg4c476992010-10-04 21:36:35 +02008446 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8447 rtnl_unlock();
8448}
8449
Johannes Berg55682962007-09-20 13:09:35 -04008450static struct genl_ops nl80211_ops[] = {
8451 {
8452 .cmd = NL80211_CMD_GET_WIPHY,
8453 .doit = nl80211_get_wiphy,
8454 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008455 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008456 .policy = nl80211_policy,
8457 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008458 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8459 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008460 },
8461 {
8462 .cmd = NL80211_CMD_SET_WIPHY,
8463 .doit = nl80211_set_wiphy,
8464 .policy = nl80211_policy,
8465 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008466 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008467 },
8468 {
8469 .cmd = NL80211_CMD_GET_INTERFACE,
8470 .doit = nl80211_get_interface,
8471 .dumpit = nl80211_dump_interface,
8472 .policy = nl80211_policy,
8473 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008474 .internal_flags = NL80211_FLAG_NEED_WDEV |
8475 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008476 },
8477 {
8478 .cmd = NL80211_CMD_SET_INTERFACE,
8479 .doit = nl80211_set_interface,
8480 .policy = nl80211_policy,
8481 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008482 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8483 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008484 },
8485 {
8486 .cmd = NL80211_CMD_NEW_INTERFACE,
8487 .doit = nl80211_new_interface,
8488 .policy = nl80211_policy,
8489 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008490 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8491 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008492 },
8493 {
8494 .cmd = NL80211_CMD_DEL_INTERFACE,
8495 .doit = nl80211_del_interface,
8496 .policy = nl80211_policy,
8497 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008498 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008499 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008500 },
Johannes Berg41ade002007-12-19 02:03:29 +01008501 {
8502 .cmd = NL80211_CMD_GET_KEY,
8503 .doit = nl80211_get_key,
8504 .policy = nl80211_policy,
8505 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008507 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008508 },
8509 {
8510 .cmd = NL80211_CMD_SET_KEY,
8511 .doit = nl80211_set_key,
8512 .policy = nl80211_policy,
8513 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008514 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008515 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008516 },
8517 {
8518 .cmd = NL80211_CMD_NEW_KEY,
8519 .doit = nl80211_new_key,
8520 .policy = nl80211_policy,
8521 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008523 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008524 },
8525 {
8526 .cmd = NL80211_CMD_DEL_KEY,
8527 .doit = nl80211_del_key,
8528 .policy = nl80211_policy,
8529 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008531 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008532 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008533 {
8534 .cmd = NL80211_CMD_SET_BEACON,
8535 .policy = nl80211_policy,
8536 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008537 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008539 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008540 },
8541 {
Johannes Berg88600202012-02-13 15:17:18 +01008542 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008543 .policy = nl80211_policy,
8544 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008545 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008547 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008548 },
8549 {
Johannes Berg88600202012-02-13 15:17:18 +01008550 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008551 .policy = nl80211_policy,
8552 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008553 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008555 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008556 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008557 {
8558 .cmd = NL80211_CMD_GET_STATION,
8559 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008560 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008561 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008562 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8563 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008564 },
8565 {
8566 .cmd = NL80211_CMD_SET_STATION,
8567 .doit = nl80211_set_station,
8568 .policy = nl80211_policy,
8569 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008570 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008571 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008572 },
8573 {
8574 .cmd = NL80211_CMD_NEW_STATION,
8575 .doit = nl80211_new_station,
8576 .policy = nl80211_policy,
8577 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008578 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008579 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008580 },
8581 {
8582 .cmd = NL80211_CMD_DEL_STATION,
8583 .doit = nl80211_del_station,
8584 .policy = nl80211_policy,
8585 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008587 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008588 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008589 {
8590 .cmd = NL80211_CMD_GET_MPATH,
8591 .doit = nl80211_get_mpath,
8592 .dumpit = nl80211_dump_mpath,
8593 .policy = nl80211_policy,
8594 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008595 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008596 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008597 },
8598 {
8599 .cmd = NL80211_CMD_SET_MPATH,
8600 .doit = nl80211_set_mpath,
8601 .policy = nl80211_policy,
8602 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008604 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008605 },
8606 {
8607 .cmd = NL80211_CMD_NEW_MPATH,
8608 .doit = nl80211_new_mpath,
8609 .policy = nl80211_policy,
8610 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008612 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008613 },
8614 {
8615 .cmd = NL80211_CMD_DEL_MPATH,
8616 .doit = nl80211_del_mpath,
8617 .policy = nl80211_policy,
8618 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008620 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008621 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008622 {
8623 .cmd = NL80211_CMD_SET_BSS,
8624 .doit = nl80211_set_bss,
8625 .policy = nl80211_policy,
8626 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008628 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008629 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008630 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008631 .cmd = NL80211_CMD_GET_REG,
8632 .doit = nl80211_get_reg,
8633 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008634 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008635 /* can be retrieved by unprivileged users */
8636 },
8637 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008638 .cmd = NL80211_CMD_SET_REG,
8639 .doit = nl80211_set_reg,
8640 .policy = nl80211_policy,
8641 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008642 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008643 },
8644 {
8645 .cmd = NL80211_CMD_REQ_SET_REG,
8646 .doit = nl80211_req_set_reg,
8647 .policy = nl80211_policy,
8648 .flags = GENL_ADMIN_PERM,
8649 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008650 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008651 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8652 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008653 .policy = nl80211_policy,
8654 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008656 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008657 },
8658 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008659 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8660 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008661 .policy = nl80211_policy,
8662 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008664 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008665 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008666 {
Johannes Berg2a519312009-02-10 21:25:55 +01008667 .cmd = NL80211_CMD_TRIGGER_SCAN,
8668 .doit = nl80211_trigger_scan,
8669 .policy = nl80211_policy,
8670 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008671 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008672 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008673 },
8674 {
8675 .cmd = NL80211_CMD_GET_SCAN,
8676 .policy = nl80211_policy,
8677 .dumpit = nl80211_dump_scan,
8678 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008679 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008680 .cmd = NL80211_CMD_START_SCHED_SCAN,
8681 .doit = nl80211_start_sched_scan,
8682 .policy = nl80211_policy,
8683 .flags = GENL_ADMIN_PERM,
8684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8685 NL80211_FLAG_NEED_RTNL,
8686 },
8687 {
8688 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8689 .doit = nl80211_stop_sched_scan,
8690 .policy = nl80211_policy,
8691 .flags = GENL_ADMIN_PERM,
8692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8693 NL80211_FLAG_NEED_RTNL,
8694 },
8695 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008696 .cmd = NL80211_CMD_AUTHENTICATE,
8697 .doit = nl80211_authenticate,
8698 .policy = nl80211_policy,
8699 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008700 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008701 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008702 },
8703 {
8704 .cmd = NL80211_CMD_ASSOCIATE,
8705 .doit = nl80211_associate,
8706 .policy = nl80211_policy,
8707 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008708 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008709 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008710 },
8711 {
8712 .cmd = NL80211_CMD_DEAUTHENTICATE,
8713 .doit = nl80211_deauthenticate,
8714 .policy = nl80211_policy,
8715 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008716 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008717 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008718 },
8719 {
8720 .cmd = NL80211_CMD_DISASSOCIATE,
8721 .doit = nl80211_disassociate,
8722 .policy = nl80211_policy,
8723 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008724 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008725 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008726 },
Johannes Berg04a773a2009-04-19 21:24:32 +02008727 {
8728 .cmd = NL80211_CMD_JOIN_IBSS,
8729 .doit = nl80211_join_ibss,
8730 .policy = nl80211_policy,
8731 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008732 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008733 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008734 },
8735 {
8736 .cmd = NL80211_CMD_LEAVE_IBSS,
8737 .doit = nl80211_leave_ibss,
8738 .policy = nl80211_policy,
8739 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008740 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008741 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02008742 },
Johannes Bergaff89a92009-07-01 21:26:51 +02008743#ifdef CONFIG_NL80211_TESTMODE
8744 {
8745 .cmd = NL80211_CMD_TESTMODE,
8746 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07008747 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02008748 .policy = nl80211_policy,
8749 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008750 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8751 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02008752 },
8753#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02008754 {
8755 .cmd = NL80211_CMD_CONNECT,
8756 .doit = nl80211_connect,
8757 .policy = nl80211_policy,
8758 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008759 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008760 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008761 },
8762 {
8763 .cmd = NL80211_CMD_DISCONNECT,
8764 .doit = nl80211_disconnect,
8765 .policy = nl80211_policy,
8766 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008768 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02008769 },
Johannes Berg463d0182009-07-14 00:33:35 +02008770 {
8771 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
8772 .doit = nl80211_wiphy_netns,
8773 .policy = nl80211_policy,
8774 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008775 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8776 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02008777 },
Holger Schurig61fa7132009-11-11 12:25:40 +01008778 {
8779 .cmd = NL80211_CMD_GET_SURVEY,
8780 .policy = nl80211_policy,
8781 .dumpit = nl80211_dump_survey,
8782 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008783 {
8784 .cmd = NL80211_CMD_SET_PMKSA,
8785 .doit = nl80211_setdel_pmksa,
8786 .policy = nl80211_policy,
8787 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008788 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008789 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008790 },
8791 {
8792 .cmd = NL80211_CMD_DEL_PMKSA,
8793 .doit = nl80211_setdel_pmksa,
8794 .policy = nl80211_policy,
8795 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008797 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008798 },
8799 {
8800 .cmd = NL80211_CMD_FLUSH_PMKSA,
8801 .doit = nl80211_flush_pmksa,
8802 .policy = nl80211_policy,
8803 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008805 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008806 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008807 {
8808 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
8809 .doit = nl80211_remain_on_channel,
8810 .policy = nl80211_policy,
8811 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008812 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008813 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008814 },
8815 {
8816 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
8817 .doit = nl80211_cancel_remain_on_channel,
8818 .policy = nl80211_policy,
8819 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008820 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008821 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008822 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008823 {
8824 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
8825 .doit = nl80211_set_tx_bitrate_mask,
8826 .policy = nl80211_policy,
8827 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008828 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8829 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008830 },
Jouni Malinen026331c2010-02-15 12:53:10 +02008831 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008832 .cmd = NL80211_CMD_REGISTER_FRAME,
8833 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008834 .policy = nl80211_policy,
8835 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008836 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008837 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008838 },
8839 {
Johannes Berg2e161f72010-08-12 15:38:38 +02008840 .cmd = NL80211_CMD_FRAME,
8841 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02008842 .policy = nl80211_policy,
8843 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008844 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008845 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02008846 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02008847 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008848 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
8849 .doit = nl80211_tx_mgmt_cancel_wait,
8850 .policy = nl80211_policy,
8851 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02008852 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008853 NL80211_FLAG_NEED_RTNL,
8854 },
8855 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02008856 .cmd = NL80211_CMD_SET_POWER_SAVE,
8857 .doit = nl80211_set_power_save,
8858 .policy = nl80211_policy,
8859 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008860 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8861 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008862 },
8863 {
8864 .cmd = NL80211_CMD_GET_POWER_SAVE,
8865 .doit = nl80211_get_power_save,
8866 .policy = nl80211_policy,
8867 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02008868 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8869 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008870 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008871 {
8872 .cmd = NL80211_CMD_SET_CQM,
8873 .doit = nl80211_set_cqm,
8874 .policy = nl80211_policy,
8875 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008876 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8877 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008878 },
Johannes Bergf444de02010-05-05 15:25:02 +02008879 {
8880 .cmd = NL80211_CMD_SET_CHANNEL,
8881 .doit = nl80211_set_channel,
8882 .policy = nl80211_policy,
8883 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008884 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8885 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02008886 },
Bill Jordane8347eb2010-10-01 13:54:28 -04008887 {
8888 .cmd = NL80211_CMD_SET_WDS_PEER,
8889 .doit = nl80211_set_wds_peer,
8890 .policy = nl80211_policy,
8891 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02008892 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8893 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04008894 },
Johannes Berg29cbe682010-12-03 09:20:44 +01008895 {
8896 .cmd = NL80211_CMD_JOIN_MESH,
8897 .doit = nl80211_join_mesh,
8898 .policy = nl80211_policy,
8899 .flags = GENL_ADMIN_PERM,
8900 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8901 NL80211_FLAG_NEED_RTNL,
8902 },
8903 {
8904 .cmd = NL80211_CMD_LEAVE_MESH,
8905 .doit = nl80211_leave_mesh,
8906 .policy = nl80211_policy,
8907 .flags = GENL_ADMIN_PERM,
8908 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8909 NL80211_FLAG_NEED_RTNL,
8910 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008911#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02008912 {
8913 .cmd = NL80211_CMD_GET_WOWLAN,
8914 .doit = nl80211_get_wowlan,
8915 .policy = nl80211_policy,
8916 /* can be retrieved by unprivileged users */
8917 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8918 NL80211_FLAG_NEED_RTNL,
8919 },
8920 {
8921 .cmd = NL80211_CMD_SET_WOWLAN,
8922 .doit = nl80211_set_wowlan,
8923 .policy = nl80211_policy,
8924 .flags = GENL_ADMIN_PERM,
8925 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8926 NL80211_FLAG_NEED_RTNL,
8927 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02008928#endif
Johannes Berge5497d72011-07-05 16:35:40 +02008929 {
8930 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
8931 .doit = nl80211_set_rekey_data,
8932 .policy = nl80211_policy,
8933 .flags = GENL_ADMIN_PERM,
8934 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8935 NL80211_FLAG_NEED_RTNL,
8936 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03008937 {
8938 .cmd = NL80211_CMD_TDLS_MGMT,
8939 .doit = nl80211_tdls_mgmt,
8940 .policy = nl80211_policy,
8941 .flags = GENL_ADMIN_PERM,
8942 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8943 NL80211_FLAG_NEED_RTNL,
8944 },
8945 {
8946 .cmd = NL80211_CMD_TDLS_OPER,
8947 .doit = nl80211_tdls_oper,
8948 .policy = nl80211_policy,
8949 .flags = GENL_ADMIN_PERM,
8950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8951 NL80211_FLAG_NEED_RTNL,
8952 },
Johannes Berg28946da2011-11-04 11:18:12 +01008953 {
8954 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
8955 .doit = nl80211_register_unexpected_frame,
8956 .policy = nl80211_policy,
8957 .flags = GENL_ADMIN_PERM,
8958 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8959 NL80211_FLAG_NEED_RTNL,
8960 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01008961 {
8962 .cmd = NL80211_CMD_PROBE_CLIENT,
8963 .doit = nl80211_probe_client,
8964 .policy = nl80211_policy,
8965 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008966 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01008967 NL80211_FLAG_NEED_RTNL,
8968 },
Johannes Berg5e760232011-11-04 11:18:17 +01008969 {
8970 .cmd = NL80211_CMD_REGISTER_BEACONS,
8971 .doit = nl80211_register_beacons,
8972 .policy = nl80211_policy,
8973 .flags = GENL_ADMIN_PERM,
8974 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8975 NL80211_FLAG_NEED_RTNL,
8976 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01008977 {
8978 .cmd = NL80211_CMD_SET_NOACK_MAP,
8979 .doit = nl80211_set_noack_map,
8980 .policy = nl80211_policy,
8981 .flags = GENL_ADMIN_PERM,
8982 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8983 NL80211_FLAG_NEED_RTNL,
8984 },
Johannes Berg98104fde2012-06-16 00:19:54 +02008985 {
8986 .cmd = NL80211_CMD_START_P2P_DEVICE,
8987 .doit = nl80211_start_p2p_device,
8988 .policy = nl80211_policy,
8989 .flags = GENL_ADMIN_PERM,
8990 .internal_flags = NL80211_FLAG_NEED_WDEV |
8991 NL80211_FLAG_NEED_RTNL,
8992 },
8993 {
8994 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
8995 .doit = nl80211_stop_p2p_device,
8996 .policy = nl80211_policy,
8997 .flags = GENL_ADMIN_PERM,
8998 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
8999 NL80211_FLAG_NEED_RTNL,
9000 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009001 {
9002 .cmd = NL80211_CMD_SET_MCAST_RATE,
9003 .doit = nl80211_set_mcast_rate,
9004 .policy = nl80211_policy,
9005 .flags = GENL_ADMIN_PERM,
9006 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9007 NL80211_FLAG_NEED_RTNL,
9008 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309009 {
9010 .cmd = NL80211_CMD_SET_MAC_ACL,
9011 .doit = nl80211_set_mac_acl,
9012 .policy = nl80211_policy,
9013 .flags = GENL_ADMIN_PERM,
9014 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9015 NL80211_FLAG_NEED_RTNL,
9016 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009017 {
9018 .cmd = NL80211_CMD_RADAR_DETECT,
9019 .doit = nl80211_start_radar_detection,
9020 .policy = nl80211_policy,
9021 .flags = GENL_ADMIN_PERM,
9022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9023 NL80211_FLAG_NEED_RTNL,
9024 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009025 {
9026 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9027 .doit = nl80211_get_protocol_features,
9028 .policy = nl80211_policy,
9029 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009030 {
9031 .cmd = NL80211_CMD_UPDATE_FT_IES,
9032 .doit = nl80211_update_ft_ies,
9033 .policy = nl80211_policy,
9034 .flags = GENL_ADMIN_PERM,
9035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9036 NL80211_FLAG_NEED_RTNL,
9037 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009038 {
9039 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9040 .doit = nl80211_crit_protocol_start,
9041 .policy = nl80211_policy,
9042 .flags = GENL_ADMIN_PERM,
9043 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9044 NL80211_FLAG_NEED_RTNL,
9045 },
9046 {
9047 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9048 .doit = nl80211_crit_protocol_stop,
9049 .policy = nl80211_policy,
9050 .flags = GENL_ADMIN_PERM,
9051 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9052 NL80211_FLAG_NEED_RTNL,
9053 }
Johannes Berg55682962007-09-20 13:09:35 -04009054};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009055
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009056static struct genl_multicast_group nl80211_mlme_mcgrp = {
9057 .name = "mlme",
9058};
Johannes Berg55682962007-09-20 13:09:35 -04009059
9060/* multicast groups */
9061static struct genl_multicast_group nl80211_config_mcgrp = {
9062 .name = "config",
9063};
Johannes Berg2a519312009-02-10 21:25:55 +01009064static struct genl_multicast_group nl80211_scan_mcgrp = {
9065 .name = "scan",
9066};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009067static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9068 .name = "regulatory",
9069};
Johannes Berg55682962007-09-20 13:09:35 -04009070
9071/* notification functions */
9072
9073void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9074{
9075 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009076 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009077
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009078 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009079 if (!msg)
9080 return;
9081
Johannes Berg86e8cf92013-06-19 10:57:22 +02009082 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009083 nlmsg_free(msg);
9084 return;
9085 }
9086
Johannes Berg463d0182009-07-14 00:33:35 +02009087 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9088 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009089}
9090
Johannes Berg362a4152009-05-24 16:43:15 +02009091static int nl80211_add_scan_req(struct sk_buff *msg,
9092 struct cfg80211_registered_device *rdev)
9093{
9094 struct cfg80211_scan_request *req = rdev->scan_req;
9095 struct nlattr *nest;
9096 int i;
9097
9098 if (WARN_ON(!req))
9099 return 0;
9100
9101 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9102 if (!nest)
9103 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009104 for (i = 0; i < req->n_ssids; i++) {
9105 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9106 goto nla_put_failure;
9107 }
Johannes Berg362a4152009-05-24 16:43:15 +02009108 nla_nest_end(msg, nest);
9109
9110 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9111 if (!nest)
9112 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009113 for (i = 0; i < req->n_channels; i++) {
9114 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9115 goto nla_put_failure;
9116 }
Johannes Berg362a4152009-05-24 16:43:15 +02009117 nla_nest_end(msg, nest);
9118
David S. Miller9360ffd2012-03-29 04:41:26 -04009119 if (req->ie &&
9120 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9121 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009122
Sam Lefflered4737712012-10-11 21:03:31 -07009123 if (req->flags)
9124 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9125
Johannes Berg362a4152009-05-24 16:43:15 +02009126 return 0;
9127 nla_put_failure:
9128 return -ENOBUFS;
9129}
9130
Johannes Berga538e2d2009-06-16 19:56:42 +02009131static int nl80211_send_scan_msg(struct sk_buff *msg,
9132 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009133 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009134 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009135 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009136{
9137 void *hdr;
9138
Eric W. Biederman15e47302012-09-07 20:12:54 +00009139 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009140 if (!hdr)
9141 return -1;
9142
David S. Miller9360ffd2012-03-29 04:41:26 -04009143 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009144 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9145 wdev->netdev->ifindex)) ||
9146 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009147 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009148
Johannes Berg362a4152009-05-24 16:43:15 +02009149 /* ignore errors and send incomplete event anyway */
9150 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009151
9152 return genlmsg_end(msg, hdr);
9153
9154 nla_put_failure:
9155 genlmsg_cancel(msg, hdr);
9156 return -EMSGSIZE;
9157}
9158
Luciano Coelho807f8a82011-05-11 17:09:35 +03009159static int
9160nl80211_send_sched_scan_msg(struct sk_buff *msg,
9161 struct cfg80211_registered_device *rdev,
9162 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009163 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009164{
9165 void *hdr;
9166
Eric W. Biederman15e47302012-09-07 20:12:54 +00009167 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009168 if (!hdr)
9169 return -1;
9170
David S. Miller9360ffd2012-03-29 04:41:26 -04009171 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9172 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9173 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009174
9175 return genlmsg_end(msg, hdr);
9176
9177 nla_put_failure:
9178 genlmsg_cancel(msg, hdr);
9179 return -EMSGSIZE;
9180}
9181
Johannes Berga538e2d2009-06-16 19:56:42 +02009182void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009183 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009184{
9185 struct sk_buff *msg;
9186
Thomas Graf58050fc2012-06-28 03:57:45 +00009187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009188 if (!msg)
9189 return;
9190
Johannes Bergfd014282012-06-18 19:17:03 +02009191 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009192 NL80211_CMD_TRIGGER_SCAN) < 0) {
9193 nlmsg_free(msg);
9194 return;
9195 }
9196
Johannes Berg463d0182009-07-14 00:33:35 +02009197 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9198 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009199}
9200
Johannes Berg2a519312009-02-10 21:25:55 +01009201void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009202 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009203{
9204 struct sk_buff *msg;
9205
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009206 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009207 if (!msg)
9208 return;
9209
Johannes Bergfd014282012-06-18 19:17:03 +02009210 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009211 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009212 nlmsg_free(msg);
9213 return;
9214 }
9215
Johannes Berg463d0182009-07-14 00:33:35 +02009216 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9217 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009218}
9219
9220void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009221 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009222{
9223 struct sk_buff *msg;
9224
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009225 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009226 if (!msg)
9227 return;
9228
Johannes Bergfd014282012-06-18 19:17:03 +02009229 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009230 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009231 nlmsg_free(msg);
9232 return;
9233 }
9234
Johannes Berg463d0182009-07-14 00:33:35 +02009235 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9236 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009237}
9238
Luciano Coelho807f8a82011-05-11 17:09:35 +03009239void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9240 struct net_device *netdev)
9241{
9242 struct sk_buff *msg;
9243
9244 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9245 if (!msg)
9246 return;
9247
9248 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9249 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9250 nlmsg_free(msg);
9251 return;
9252 }
9253
9254 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9255 nl80211_scan_mcgrp.id, GFP_KERNEL);
9256}
9257
9258void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9259 struct net_device *netdev, u32 cmd)
9260{
9261 struct sk_buff *msg;
9262
Thomas Graf58050fc2012-06-28 03:57:45 +00009263 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009264 if (!msg)
9265 return;
9266
9267 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9268 nlmsg_free(msg);
9269 return;
9270 }
9271
9272 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9273 nl80211_scan_mcgrp.id, GFP_KERNEL);
9274}
9275
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009276/*
9277 * This can happen on global regulatory changes or device specific settings
9278 * based on custom world regulatory domains.
9279 */
9280void nl80211_send_reg_change_event(struct regulatory_request *request)
9281{
9282 struct sk_buff *msg;
9283 void *hdr;
9284
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009285 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009286 if (!msg)
9287 return;
9288
9289 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9290 if (!hdr) {
9291 nlmsg_free(msg);
9292 return;
9293 }
9294
9295 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009296 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9297 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009298
David S. Miller9360ffd2012-03-29 04:41:26 -04009299 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9300 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9301 NL80211_REGDOM_TYPE_WORLD))
9302 goto nla_put_failure;
9303 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9304 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9305 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9306 goto nla_put_failure;
9307 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9308 request->intersect) {
9309 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9310 NL80211_REGDOM_TYPE_INTERSECTION))
9311 goto nla_put_failure;
9312 } else {
9313 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9314 NL80211_REGDOM_TYPE_COUNTRY) ||
9315 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9316 request->alpha2))
9317 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009318 }
9319
Johannes Bergf4173762012-12-03 18:23:37 +01009320 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009321 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9322 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009323
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009324 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009325
Johannes Bergbc43b282009-07-25 10:54:13 +02009326 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009327 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009328 GFP_ATOMIC);
9329 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009330
9331 return;
9332
9333nla_put_failure:
9334 genlmsg_cancel(msg, hdr);
9335 nlmsg_free(msg);
9336}
9337
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009338static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9339 struct net_device *netdev,
9340 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009341 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009342{
9343 struct sk_buff *msg;
9344 void *hdr;
9345
Johannes Berge6d6e342009-07-01 21:26:47 +02009346 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009347 if (!msg)
9348 return;
9349
9350 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9351 if (!hdr) {
9352 nlmsg_free(msg);
9353 return;
9354 }
9355
David S. Miller9360ffd2012-03-29 04:41:26 -04009356 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9357 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9358 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9359 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009360
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009361 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009362
Johannes Berg463d0182009-07-14 00:33:35 +02009363 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9364 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009365 return;
9366
9367 nla_put_failure:
9368 genlmsg_cancel(msg, hdr);
9369 nlmsg_free(msg);
9370}
9371
9372void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009373 struct net_device *netdev, const u8 *buf,
9374 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009375{
9376 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009377 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009378}
9379
9380void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9381 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009382 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009383{
Johannes Berge6d6e342009-07-01 21:26:47 +02009384 nl80211_send_mlme_event(rdev, netdev, buf, len,
9385 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009386}
9387
Jouni Malinen53b46b82009-03-27 20:53:56 +02009388void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009389 struct net_device *netdev, const u8 *buf,
9390 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009391{
9392 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009393 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009394}
9395
Jouni Malinen53b46b82009-03-27 20:53:56 +02009396void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9397 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009398 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009399{
9400 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009401 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009402}
9403
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009404void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9405 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009406{
Johannes Berg947add32013-02-22 22:05:20 +01009407 struct wireless_dev *wdev = dev->ieee80211_ptr;
9408 struct wiphy *wiphy = wdev->wiphy;
9409 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009410 const struct ieee80211_mgmt *mgmt = (void *)buf;
9411 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009412
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009413 if (WARN_ON(len < 2))
9414 return;
9415
9416 if (ieee80211_is_deauth(mgmt->frame_control))
9417 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9418 else
9419 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9420
9421 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9422 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009423}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009424EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009425
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009426static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9427 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009428 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009429{
9430 struct sk_buff *msg;
9431 void *hdr;
9432
Johannes Berge6d6e342009-07-01 21:26:47 +02009433 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009434 if (!msg)
9435 return;
9436
9437 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9438 if (!hdr) {
9439 nlmsg_free(msg);
9440 return;
9441 }
9442
David S. Miller9360ffd2012-03-29 04:41:26 -04009443 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9444 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9445 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9446 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9447 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009448
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009449 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009450
Johannes Berg463d0182009-07-14 00:33:35 +02009451 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9452 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009453 return;
9454
9455 nla_put_failure:
9456 genlmsg_cancel(msg, hdr);
9457 nlmsg_free(msg);
9458}
9459
9460void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009461 struct net_device *netdev, const u8 *addr,
9462 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009463{
9464 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009465 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009466}
9467
9468void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009469 struct net_device *netdev, const u8 *addr,
9470 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009471{
Johannes Berge6d6e342009-07-01 21:26:47 +02009472 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9473 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009474}
9475
Samuel Ortizb23aa672009-07-01 21:26:54 +02009476void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9477 struct net_device *netdev, const u8 *bssid,
9478 const u8 *req_ie, size_t req_ie_len,
9479 const u8 *resp_ie, size_t resp_ie_len,
9480 u16 status, gfp_t gfp)
9481{
9482 struct sk_buff *msg;
9483 void *hdr;
9484
Thomas Graf58050fc2012-06-28 03:57:45 +00009485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009486 if (!msg)
9487 return;
9488
9489 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9490 if (!hdr) {
9491 nlmsg_free(msg);
9492 return;
9493 }
9494
David S. Miller9360ffd2012-03-29 04:41:26 -04009495 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9496 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9497 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9498 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9499 (req_ie &&
9500 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9501 (resp_ie &&
9502 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9503 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009504
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009505 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009506
Johannes Berg463d0182009-07-14 00:33:35 +02009507 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9508 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009509 return;
9510
9511 nla_put_failure:
9512 genlmsg_cancel(msg, hdr);
9513 nlmsg_free(msg);
9514
9515}
9516
9517void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9518 struct net_device *netdev, const u8 *bssid,
9519 const u8 *req_ie, size_t req_ie_len,
9520 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9521{
9522 struct sk_buff *msg;
9523 void *hdr;
9524
Thomas Graf58050fc2012-06-28 03:57:45 +00009525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009526 if (!msg)
9527 return;
9528
9529 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9530 if (!hdr) {
9531 nlmsg_free(msg);
9532 return;
9533 }
9534
David S. Miller9360ffd2012-03-29 04:41:26 -04009535 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9536 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9537 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9538 (req_ie &&
9539 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9540 (resp_ie &&
9541 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9542 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009543
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009544 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009545
Johannes Berg463d0182009-07-14 00:33:35 +02009546 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9547 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009548 return;
9549
9550 nla_put_failure:
9551 genlmsg_cancel(msg, hdr);
9552 nlmsg_free(msg);
9553
9554}
9555
9556void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9557 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009558 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009559{
9560 struct sk_buff *msg;
9561 void *hdr;
9562
Thomas Graf58050fc2012-06-28 03:57:45 +00009563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009564 if (!msg)
9565 return;
9566
9567 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9568 if (!hdr) {
9569 nlmsg_free(msg);
9570 return;
9571 }
9572
David S. Miller9360ffd2012-03-29 04:41:26 -04009573 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9574 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9575 (from_ap && reason &&
9576 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9577 (from_ap &&
9578 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9579 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9580 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009581
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009582 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009583
Johannes Berg463d0182009-07-14 00:33:35 +02009584 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9585 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009586 return;
9587
9588 nla_put_failure:
9589 genlmsg_cancel(msg, hdr);
9590 nlmsg_free(msg);
9591
9592}
9593
Johannes Berg04a773a2009-04-19 21:24:32 +02009594void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9595 struct net_device *netdev, const u8 *bssid,
9596 gfp_t gfp)
9597{
9598 struct sk_buff *msg;
9599 void *hdr;
9600
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009601 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009602 if (!msg)
9603 return;
9604
9605 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9606 if (!hdr) {
9607 nlmsg_free(msg);
9608 return;
9609 }
9610
David S. Miller9360ffd2012-03-29 04:41:26 -04009611 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9612 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9613 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9614 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009615
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009616 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009617
Johannes Berg463d0182009-07-14 00:33:35 +02009618 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9619 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009620 return;
9621
9622 nla_put_failure:
9623 genlmsg_cancel(msg, hdr);
9624 nlmsg_free(msg);
9625}
9626
Johannes Berg947add32013-02-22 22:05:20 +01009627void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9628 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009629{
Johannes Berg947add32013-02-22 22:05:20 +01009630 struct wireless_dev *wdev = dev->ieee80211_ptr;
9631 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009632 struct sk_buff *msg;
9633 void *hdr;
9634
Johannes Berg947add32013-02-22 22:05:20 +01009635 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9636 return;
9637
9638 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9639
Javier Cardonac93b5e72011-04-07 15:08:34 -07009640 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9641 if (!msg)
9642 return;
9643
9644 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9645 if (!hdr) {
9646 nlmsg_free(msg);
9647 return;
9648 }
9649
David S. Miller9360ffd2012-03-29 04:41:26 -04009650 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009651 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9652 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009653 (ie_len && ie &&
9654 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9655 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009656
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009657 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009658
9659 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9660 nl80211_mlme_mcgrp.id, gfp);
9661 return;
9662
9663 nla_put_failure:
9664 genlmsg_cancel(msg, hdr);
9665 nlmsg_free(msg);
9666}
Johannes Berg947add32013-02-22 22:05:20 +01009667EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009668
Jouni Malinena3b8b052009-03-27 21:59:49 +02009669void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9670 struct net_device *netdev, const u8 *addr,
9671 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009672 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009673{
9674 struct sk_buff *msg;
9675 void *hdr;
9676
Johannes Berge6d6e342009-07-01 21:26:47 +02009677 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009678 if (!msg)
9679 return;
9680
9681 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9682 if (!hdr) {
9683 nlmsg_free(msg);
9684 return;
9685 }
9686
David S. Miller9360ffd2012-03-29 04:41:26 -04009687 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9688 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9689 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
9690 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
9691 (key_id != -1 &&
9692 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
9693 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
9694 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +02009695
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009696 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009697
Johannes Berg463d0182009-07-14 00:33:35 +02009698 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9699 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009700 return;
9701
9702 nla_put_failure:
9703 genlmsg_cancel(msg, hdr);
9704 nlmsg_free(msg);
9705}
9706
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009707void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
9708 struct ieee80211_channel *channel_before,
9709 struct ieee80211_channel *channel_after)
9710{
9711 struct sk_buff *msg;
9712 void *hdr;
9713 struct nlattr *nl_freq;
9714
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009715 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009716 if (!msg)
9717 return;
9718
9719 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
9720 if (!hdr) {
9721 nlmsg_free(msg);
9722 return;
9723 }
9724
9725 /*
9726 * Since we are applying the beacon hint to a wiphy we know its
9727 * wiphy_idx is valid
9728 */
David S. Miller9360ffd2012-03-29 04:41:26 -04009729 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
9730 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009731
9732 /* Before */
9733 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
9734 if (!nl_freq)
9735 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009736 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009737 goto nla_put_failure;
9738 nla_nest_end(msg, nl_freq);
9739
9740 /* After */
9741 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
9742 if (!nl_freq)
9743 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01009744 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009745 goto nla_put_failure;
9746 nla_nest_end(msg, nl_freq);
9747
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009748 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009749
Johannes Berg463d0182009-07-14 00:33:35 +02009750 rcu_read_lock();
9751 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
9752 GFP_ATOMIC);
9753 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04009754
9755 return;
9756
9757nla_put_failure:
9758 genlmsg_cancel(msg, hdr);
9759 nlmsg_free(msg);
9760}
9761
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009762static void nl80211_send_remain_on_chan_event(
9763 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +02009764 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009765 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009766 unsigned int duration, gfp_t gfp)
9767{
9768 struct sk_buff *msg;
9769 void *hdr;
9770
9771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9772 if (!msg)
9773 return;
9774
9775 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9776 if (!hdr) {
9777 nlmsg_free(msg);
9778 return;
9779 }
9780
David S. Miller9360ffd2012-03-29 04:41:26 -04009781 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02009782 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9783 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +02009784 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009785 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +01009786 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
9787 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009788 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9789 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009790
David S. Miller9360ffd2012-03-29 04:41:26 -04009791 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
9792 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
9793 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009794
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009795 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009796
9797 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9798 nl80211_mlme_mcgrp.id, gfp);
9799 return;
9800
9801 nla_put_failure:
9802 genlmsg_cancel(msg, hdr);
9803 nlmsg_free(msg);
9804}
9805
Johannes Berg947add32013-02-22 22:05:20 +01009806void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
9807 struct ieee80211_channel *chan,
9808 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009809{
Johannes Berg947add32013-02-22 22:05:20 +01009810 struct wiphy *wiphy = wdev->wiphy;
9811 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9812
9813 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009814 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +02009815 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +01009816 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009817}
Johannes Berg947add32013-02-22 22:05:20 +01009818EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009819
Johannes Berg947add32013-02-22 22:05:20 +01009820void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
9821 struct ieee80211_channel *chan,
9822 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009823{
Johannes Berg947add32013-02-22 22:05:20 +01009824 struct wiphy *wiphy = wdev->wiphy;
9825 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9826
9827 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009828 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +01009829 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009830}
Johannes Berg947add32013-02-22 22:05:20 +01009831EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009832
Johannes Berg947add32013-02-22 22:05:20 +01009833void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
9834 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +01009835{
Johannes Berg947add32013-02-22 22:05:20 +01009836 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9837 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +01009838 struct sk_buff *msg;
9839
Johannes Berg947add32013-02-22 22:05:20 +01009840 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
9841
Thomas Graf58050fc2012-06-28 03:57:45 +00009842 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +01009843 if (!msg)
9844 return;
9845
John W. Linville66266b32012-03-15 13:25:41 -04009846 if (nl80211_send_station(msg, 0, 0, 0,
9847 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +01009848 nlmsg_free(msg);
9849 return;
9850 }
9851
9852 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9853 nl80211_mlme_mcgrp.id, gfp);
9854}
Johannes Berg947add32013-02-22 22:05:20 +01009855EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +01009856
Johannes Berg947add32013-02-22 22:05:20 +01009857void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +02009858{
Johannes Berg947add32013-02-22 22:05:20 +01009859 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9860 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +02009861 struct sk_buff *msg;
9862 void *hdr;
9863
Johannes Berg947add32013-02-22 22:05:20 +01009864 trace_cfg80211_del_sta(dev, mac_addr);
9865
Thomas Graf58050fc2012-06-28 03:57:45 +00009866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +02009867 if (!msg)
9868 return;
9869
9870 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
9871 if (!hdr) {
9872 nlmsg_free(msg);
9873 return;
9874 }
9875
David S. Miller9360ffd2012-03-29 04:41:26 -04009876 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9877 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
9878 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +02009879
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009880 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +02009881
9882 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9883 nl80211_mlme_mcgrp.id, gfp);
9884 return;
9885
9886 nla_put_failure:
9887 genlmsg_cancel(msg, hdr);
9888 nlmsg_free(msg);
9889}
Johannes Berg947add32013-02-22 22:05:20 +01009890EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +02009891
Johannes Berg947add32013-02-22 22:05:20 +01009892void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
9893 enum nl80211_connect_failed_reason reason,
9894 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309895{
Johannes Berg947add32013-02-22 22:05:20 +01009896 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
9897 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309898 struct sk_buff *msg;
9899 void *hdr;
9900
9901 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
9902 if (!msg)
9903 return;
9904
9905 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
9906 if (!hdr) {
9907 nlmsg_free(msg);
9908 return;
9909 }
9910
9911 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9912 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
9913 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
9914 goto nla_put_failure;
9915
9916 genlmsg_end(msg, hdr);
9917
9918 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9919 nl80211_mlme_mcgrp.id, gfp);
9920 return;
9921
9922 nla_put_failure:
9923 genlmsg_cancel(msg, hdr);
9924 nlmsg_free(msg);
9925}
Johannes Berg947add32013-02-22 22:05:20 +01009926EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +05309927
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009928static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
9929 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +01009930{
9931 struct wireless_dev *wdev = dev->ieee80211_ptr;
9932 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
9933 struct sk_buff *msg;
9934 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +00009935 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009936
Eric W. Biederman15e47302012-09-07 20:12:54 +00009937 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009938 return false;
9939
9940 msg = nlmsg_new(100, gfp);
9941 if (!msg)
9942 return true;
9943
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009944 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +01009945 if (!hdr) {
9946 nlmsg_free(msg);
9947 return true;
9948 }
9949
David S. Miller9360ffd2012-03-29 04:41:26 -04009950 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9951 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9952 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9953 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +01009954
Johannes Berg9c90a9f2013-06-04 12:46:03 +02009955 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +00009956 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +01009957 return true;
9958
9959 nla_put_failure:
9960 genlmsg_cancel(msg, hdr);
9961 nlmsg_free(msg);
9962 return true;
9963}
9964
Johannes Berg947add32013-02-22 22:05:20 +01009965bool cfg80211_rx_spurious_frame(struct net_device *dev,
9966 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009967{
Johannes Berg947add32013-02-22 22:05:20 +01009968 struct wireless_dev *wdev = dev->ieee80211_ptr;
9969 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009970
Johannes Berg947add32013-02-22 22:05:20 +01009971 trace_cfg80211_rx_spurious_frame(dev, addr);
9972
9973 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9974 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
9975 trace_cfg80211_return_bool(false);
9976 return false;
9977 }
9978 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
9979 addr, gfp);
9980 trace_cfg80211_return_bool(ret);
9981 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +01009982}
Johannes Berg947add32013-02-22 22:05:20 +01009983EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
9984
9985bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
9986 const u8 *addr, gfp_t gfp)
9987{
9988 struct wireless_dev *wdev = dev->ieee80211_ptr;
9989 bool ret;
9990
9991 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
9992
9993 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
9994 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
9995 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
9996 trace_cfg80211_return_bool(false);
9997 return false;
9998 }
9999 ret = __nl80211_unexpected_frame(dev,
10000 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10001 addr, gfp);
10002 trace_cfg80211_return_bool(ret);
10003 return ret;
10004}
10005EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010006
Johannes Berg2e161f72010-08-12 15:38:38 +020010007int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010008 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010009 int freq, int sig_dbm,
10010 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010011{
Johannes Berg71bbc992012-06-15 15:30:18 +020010012 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010013 struct sk_buff *msg;
10014 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010015
10016 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10017 if (!msg)
10018 return -ENOMEM;
10019
Johannes Berg2e161f72010-08-12 15:38:38 +020010020 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010021 if (!hdr) {
10022 nlmsg_free(msg);
10023 return -ENOMEM;
10024 }
10025
David S. Miller9360ffd2012-03-29 04:41:26 -040010026 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010027 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10028 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010029 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010030 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10031 (sig_dbm &&
10032 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10033 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10034 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010035
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010036 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010037
Eric W. Biederman15e47302012-09-07 20:12:54 +000010038 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010039
10040 nla_put_failure:
10041 genlmsg_cancel(msg, hdr);
10042 nlmsg_free(msg);
10043 return -ENOBUFS;
10044}
10045
Johannes Berg947add32013-02-22 22:05:20 +010010046void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10047 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010048{
Johannes Berg947add32013-02-22 22:05:20 +010010049 struct wiphy *wiphy = wdev->wiphy;
10050 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010051 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010052 struct sk_buff *msg;
10053 void *hdr;
10054
Johannes Berg947add32013-02-22 22:05:20 +010010055 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10056
Jouni Malinen026331c2010-02-15 12:53:10 +020010057 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10058 if (!msg)
10059 return;
10060
Johannes Berg2e161f72010-08-12 15:38:38 +020010061 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010062 if (!hdr) {
10063 nlmsg_free(msg);
10064 return;
10065 }
10066
David S. Miller9360ffd2012-03-29 04:41:26 -040010067 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010068 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10069 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010070 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010071 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10072 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10073 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10074 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010075
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010076 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010077
10078 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10079 return;
10080
10081 nla_put_failure:
10082 genlmsg_cancel(msg, hdr);
10083 nlmsg_free(msg);
10084}
Johannes Berg947add32013-02-22 22:05:20 +010010085EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010086
Johannes Berg947add32013-02-22 22:05:20 +010010087void cfg80211_cqm_rssi_notify(struct net_device *dev,
10088 enum nl80211_cqm_rssi_threshold_event rssi_event,
10089 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010090{
Johannes Berg947add32013-02-22 22:05:20 +010010091 struct wireless_dev *wdev = dev->ieee80211_ptr;
10092 struct wiphy *wiphy = wdev->wiphy;
10093 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010094 struct sk_buff *msg;
10095 struct nlattr *pinfoattr;
10096 void *hdr;
10097
Johannes Berg947add32013-02-22 22:05:20 +010010098 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10099
Thomas Graf58050fc2012-06-28 03:57:45 +000010100 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010101 if (!msg)
10102 return;
10103
10104 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10105 if (!hdr) {
10106 nlmsg_free(msg);
10107 return;
10108 }
10109
David S. Miller9360ffd2012-03-29 04:41:26 -040010110 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010111 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010112 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010113
10114 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10115 if (!pinfoattr)
10116 goto nla_put_failure;
10117
David S. Miller9360ffd2012-03-29 04:41:26 -040010118 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10119 rssi_event))
10120 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010121
10122 nla_nest_end(msg, pinfoattr);
10123
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010124 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010125
10126 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10127 nl80211_mlme_mcgrp.id, gfp);
10128 return;
10129
10130 nla_put_failure:
10131 genlmsg_cancel(msg, hdr);
10132 nlmsg_free(msg);
10133}
Johannes Berg947add32013-02-22 22:05:20 +010010134EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010135
Johannes Berg947add32013-02-22 22:05:20 +010010136static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10137 struct net_device *netdev, const u8 *bssid,
10138 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010139{
10140 struct sk_buff *msg;
10141 struct nlattr *rekey_attr;
10142 void *hdr;
10143
Thomas Graf58050fc2012-06-28 03:57:45 +000010144 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010145 if (!msg)
10146 return;
10147
10148 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10149 if (!hdr) {
10150 nlmsg_free(msg);
10151 return;
10152 }
10153
David S. Miller9360ffd2012-03-29 04:41:26 -040010154 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10155 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10156 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10157 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010158
10159 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10160 if (!rekey_attr)
10161 goto nla_put_failure;
10162
David S. Miller9360ffd2012-03-29 04:41:26 -040010163 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10164 NL80211_REPLAY_CTR_LEN, replay_ctr))
10165 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010166
10167 nla_nest_end(msg, rekey_attr);
10168
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010169 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010170
10171 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10172 nl80211_mlme_mcgrp.id, gfp);
10173 return;
10174
10175 nla_put_failure:
10176 genlmsg_cancel(msg, hdr);
10177 nlmsg_free(msg);
10178}
10179
Johannes Berg947add32013-02-22 22:05:20 +010010180void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10181 const u8 *replay_ctr, gfp_t gfp)
10182{
10183 struct wireless_dev *wdev = dev->ieee80211_ptr;
10184 struct wiphy *wiphy = wdev->wiphy;
10185 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10186
10187 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10188 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10189}
10190EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10191
10192static void
10193nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10194 struct net_device *netdev, int index,
10195 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010196{
10197 struct sk_buff *msg;
10198 struct nlattr *attr;
10199 void *hdr;
10200
Thomas Graf58050fc2012-06-28 03:57:45 +000010201 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010202 if (!msg)
10203 return;
10204
10205 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10206 if (!hdr) {
10207 nlmsg_free(msg);
10208 return;
10209 }
10210
David S. Miller9360ffd2012-03-29 04:41:26 -040010211 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10212 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10213 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010214
10215 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10216 if (!attr)
10217 goto nla_put_failure;
10218
David S. Miller9360ffd2012-03-29 04:41:26 -040010219 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10220 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10221 (preauth &&
10222 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10223 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010224
10225 nla_nest_end(msg, attr);
10226
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010227 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010228
10229 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10230 nl80211_mlme_mcgrp.id, gfp);
10231 return;
10232
10233 nla_put_failure:
10234 genlmsg_cancel(msg, hdr);
10235 nlmsg_free(msg);
10236}
10237
Johannes Berg947add32013-02-22 22:05:20 +010010238void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10239 const u8 *bssid, bool preauth, gfp_t gfp)
10240{
10241 struct wireless_dev *wdev = dev->ieee80211_ptr;
10242 struct wiphy *wiphy = wdev->wiphy;
10243 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10244
10245 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10246 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10247}
10248EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10249
10250static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10251 struct net_device *netdev,
10252 struct cfg80211_chan_def *chandef,
10253 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010254{
10255 struct sk_buff *msg;
10256 void *hdr;
10257
Thomas Graf58050fc2012-06-28 03:57:45 +000010258 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010259 if (!msg)
10260 return;
10261
10262 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10263 if (!hdr) {
10264 nlmsg_free(msg);
10265 return;
10266 }
10267
Johannes Berg683b6d32012-11-08 21:25:48 +010010268 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10269 goto nla_put_failure;
10270
10271 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010272 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010273
10274 genlmsg_end(msg, hdr);
10275
10276 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10277 nl80211_mlme_mcgrp.id, gfp);
10278 return;
10279
10280 nla_put_failure:
10281 genlmsg_cancel(msg, hdr);
10282 nlmsg_free(msg);
10283}
10284
Johannes Berg947add32013-02-22 22:05:20 +010010285void cfg80211_ch_switch_notify(struct net_device *dev,
10286 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010287{
Johannes Berg947add32013-02-22 22:05:20 +010010288 struct wireless_dev *wdev = dev->ieee80211_ptr;
10289 struct wiphy *wiphy = wdev->wiphy;
10290 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10291
10292 trace_cfg80211_ch_switch_notify(dev, chandef);
10293
10294 wdev_lock(wdev);
10295
10296 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10297 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10298 goto out;
10299
10300 wdev->channel = chandef->chan;
10301 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10302out:
10303 wdev_unlock(wdev);
10304 return;
10305}
10306EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10307
10308void cfg80211_cqm_txe_notify(struct net_device *dev,
10309 const u8 *peer, u32 num_packets,
10310 u32 rate, u32 intvl, gfp_t gfp)
10311{
10312 struct wireless_dev *wdev = dev->ieee80211_ptr;
10313 struct wiphy *wiphy = wdev->wiphy;
10314 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010315 struct sk_buff *msg;
10316 struct nlattr *pinfoattr;
10317 void *hdr;
10318
10319 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10320 if (!msg)
10321 return;
10322
10323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10324 if (!hdr) {
10325 nlmsg_free(msg);
10326 return;
10327 }
10328
10329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010330 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010331 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10332 goto nla_put_failure;
10333
10334 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10335 if (!pinfoattr)
10336 goto nla_put_failure;
10337
10338 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10339 goto nla_put_failure;
10340
10341 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10342 goto nla_put_failure;
10343
10344 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10345 goto nla_put_failure;
10346
10347 nla_nest_end(msg, pinfoattr);
10348
10349 genlmsg_end(msg, hdr);
10350
10351 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10352 nl80211_mlme_mcgrp.id, gfp);
10353 return;
10354
10355 nla_put_failure:
10356 genlmsg_cancel(msg, hdr);
10357 nlmsg_free(msg);
10358}
Johannes Berg947add32013-02-22 22:05:20 +010010359EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010360
10361void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010362nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10363 struct cfg80211_chan_def *chandef,
10364 enum nl80211_radar_event event,
10365 struct net_device *netdev, gfp_t gfp)
10366{
10367 struct sk_buff *msg;
10368 void *hdr;
10369
10370 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10371 if (!msg)
10372 return;
10373
10374 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10375 if (!hdr) {
10376 nlmsg_free(msg);
10377 return;
10378 }
10379
10380 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10381 goto nla_put_failure;
10382
10383 /* NOP and radar events don't need a netdev parameter */
10384 if (netdev) {
10385 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10386
10387 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10388 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10389 goto nla_put_failure;
10390 }
10391
10392 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10393 goto nla_put_failure;
10394
10395 if (nl80211_send_chandef(msg, chandef))
10396 goto nla_put_failure;
10397
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010398 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010399
10400 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10401 nl80211_mlme_mcgrp.id, gfp);
10402 return;
10403
10404 nla_put_failure:
10405 genlmsg_cancel(msg, hdr);
10406 nlmsg_free(msg);
10407}
10408
Johannes Berg947add32013-02-22 22:05:20 +010010409void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10410 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010411{
Johannes Berg947add32013-02-22 22:05:20 +010010412 struct wireless_dev *wdev = dev->ieee80211_ptr;
10413 struct wiphy *wiphy = wdev->wiphy;
10414 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010415 struct sk_buff *msg;
10416 struct nlattr *pinfoattr;
10417 void *hdr;
10418
Johannes Berg947add32013-02-22 22:05:20 +010010419 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10420
Thomas Graf58050fc2012-06-28 03:57:45 +000010421 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010422 if (!msg)
10423 return;
10424
10425 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10426 if (!hdr) {
10427 nlmsg_free(msg);
10428 return;
10429 }
10430
David S. Miller9360ffd2012-03-29 04:41:26 -040010431 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010432 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010433 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10434 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010435
10436 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10437 if (!pinfoattr)
10438 goto nla_put_failure;
10439
David S. Miller9360ffd2012-03-29 04:41:26 -040010440 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10441 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010442
10443 nla_nest_end(msg, pinfoattr);
10444
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010445 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010446
10447 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10448 nl80211_mlme_mcgrp.id, gfp);
10449 return;
10450
10451 nla_put_failure:
10452 genlmsg_cancel(msg, hdr);
10453 nlmsg_free(msg);
10454}
Johannes Berg947add32013-02-22 22:05:20 +010010455EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010456
Johannes Berg7f6cf312011-11-04 11:18:15 +010010457void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10458 u64 cookie, bool acked, gfp_t gfp)
10459{
10460 struct wireless_dev *wdev = dev->ieee80211_ptr;
10461 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10462 struct sk_buff *msg;
10463 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010464
Beni Lev4ee3e062012-08-27 12:49:39 +030010465 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10466
Thomas Graf58050fc2012-06-28 03:57:45 +000010467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010468
Johannes Berg7f6cf312011-11-04 11:18:15 +010010469 if (!msg)
10470 return;
10471
10472 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10473 if (!hdr) {
10474 nlmsg_free(msg);
10475 return;
10476 }
10477
David S. Miller9360ffd2012-03-29 04:41:26 -040010478 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10479 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10480 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10481 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10482 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10483 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010484
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010485 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010486
10487 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10488 nl80211_mlme_mcgrp.id, gfp);
10489 return;
10490
10491 nla_put_failure:
10492 genlmsg_cancel(msg, hdr);
10493 nlmsg_free(msg);
10494}
10495EXPORT_SYMBOL(cfg80211_probe_status);
10496
Johannes Berg5e760232011-11-04 11:18:17 +010010497void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10498 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010499 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010010500{
10501 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10502 struct sk_buff *msg;
10503 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010504 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010010505
Beni Lev4ee3e062012-08-27 12:49:39 +030010506 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10507
Ben Greear37c73b52012-10-26 14:49:25 -070010508 spin_lock_bh(&rdev->beacon_registrations_lock);
10509 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10510 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10511 if (!msg) {
10512 spin_unlock_bh(&rdev->beacon_registrations_lock);
10513 return;
10514 }
Johannes Berg5e760232011-11-04 11:18:17 +010010515
Ben Greear37c73b52012-10-26 14:49:25 -070010516 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10517 if (!hdr)
10518 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010010519
Ben Greear37c73b52012-10-26 14:49:25 -070010520 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10521 (freq &&
10522 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10523 (sig_dbm &&
10524 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10525 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10526 goto nla_put_failure;
10527
10528 genlmsg_end(msg, hdr);
10529
10530 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010010531 }
Ben Greear37c73b52012-10-26 14:49:25 -070010532 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010533 return;
10534
10535 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010536 spin_unlock_bh(&rdev->beacon_registrations_lock);
10537 if (hdr)
10538 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010010539 nlmsg_free(msg);
10540}
10541EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10542
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010543#ifdef CONFIG_PM
10544void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10545 struct cfg80211_wowlan_wakeup *wakeup,
10546 gfp_t gfp)
10547{
10548 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10549 struct sk_buff *msg;
10550 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010551 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010552
10553 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10554
10555 if (wakeup)
10556 size += wakeup->packet_present_len;
10557
10558 msg = nlmsg_new(size, gfp);
10559 if (!msg)
10560 return;
10561
10562 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10563 if (!hdr)
10564 goto free_msg;
10565
10566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10567 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10568 goto free_msg;
10569
10570 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10571 wdev->netdev->ifindex))
10572 goto free_msg;
10573
10574 if (wakeup) {
10575 struct nlattr *reasons;
10576
10577 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10578
10579 if (wakeup->disconnect &&
10580 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10581 goto free_msg;
10582 if (wakeup->magic_pkt &&
10583 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10584 goto free_msg;
10585 if (wakeup->gtk_rekey_failure &&
10586 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10587 goto free_msg;
10588 if (wakeup->eap_identity_req &&
10589 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10590 goto free_msg;
10591 if (wakeup->four_way_handshake &&
10592 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10593 goto free_msg;
10594 if (wakeup->rfkill_release &&
10595 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10596 goto free_msg;
10597
10598 if (wakeup->pattern_idx >= 0 &&
10599 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10600 wakeup->pattern_idx))
10601 goto free_msg;
10602
Johannes Berg2a0e0472013-01-23 22:57:40 +010010603 if (wakeup->tcp_match)
10604 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10605
10606 if (wakeup->tcp_connlost)
10607 nla_put_flag(msg,
10608 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10609
10610 if (wakeup->tcp_nomoretokens)
10611 nla_put_flag(msg,
10612 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10613
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010614 if (wakeup->packet) {
10615 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10616 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10617
10618 if (!wakeup->packet_80211) {
10619 pkt_attr =
10620 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10621 len_attr =
10622 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10623 }
10624
10625 if (wakeup->packet_len &&
10626 nla_put_u32(msg, len_attr, wakeup->packet_len))
10627 goto free_msg;
10628
10629 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10630 wakeup->packet))
10631 goto free_msg;
10632 }
10633
10634 nla_nest_end(msg, reasons);
10635 }
10636
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010637 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010638
10639 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10640 nl80211_mlme_mcgrp.id, gfp);
10641 return;
10642
10643 free_msg:
10644 nlmsg_free(msg);
10645}
10646EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10647#endif
10648
Jouni Malinen3475b092012-11-16 22:49:57 +020010649void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10650 enum nl80211_tdls_operation oper,
10651 u16 reason_code, gfp_t gfp)
10652{
10653 struct wireless_dev *wdev = dev->ieee80211_ptr;
10654 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10655 struct sk_buff *msg;
10656 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010657
10658 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10659 reason_code);
10660
10661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10662 if (!msg)
10663 return;
10664
10665 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10666 if (!hdr) {
10667 nlmsg_free(msg);
10668 return;
10669 }
10670
10671 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10672 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10673 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10674 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10675 (reason_code > 0 &&
10676 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10677 goto nla_put_failure;
10678
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010679 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010680
10681 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10682 nl80211_mlme_mcgrp.id, gfp);
10683 return;
10684
10685 nla_put_failure:
10686 genlmsg_cancel(msg, hdr);
10687 nlmsg_free(msg);
10688}
10689EXPORT_SYMBOL(cfg80211_tdls_oper_request);
10690
Jouni Malinen026331c2010-02-15 12:53:10 +020010691static int nl80211_netlink_notify(struct notifier_block * nb,
10692 unsigned long state,
10693 void *_notify)
10694{
10695 struct netlink_notify *notify = _notify;
10696 struct cfg80211_registered_device *rdev;
10697 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070010698 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020010699
10700 if (state != NETLINK_URELEASE)
10701 return NOTIFY_DONE;
10702
10703 rcu_read_lock();
10704
Johannes Berg5e760232011-11-04 11:18:17 +010010705 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020010706 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000010707 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070010708
10709 spin_lock_bh(&rdev->beacon_registrations_lock);
10710 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
10711 list) {
10712 if (reg->nlportid == notify->portid) {
10713 list_del(&reg->list);
10714 kfree(reg);
10715 break;
10716 }
10717 }
10718 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010010719 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010720
10721 rcu_read_unlock();
10722
10723 return NOTIFY_DONE;
10724}
10725
10726static struct notifier_block nl80211_netlink_notifier = {
10727 .notifier_call = nl80211_netlink_notify,
10728};
10729
Jouni Malinen355199e2013-02-27 17:14:27 +020010730void cfg80211_ft_event(struct net_device *netdev,
10731 struct cfg80211_ft_event_params *ft_event)
10732{
10733 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
10734 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10735 struct sk_buff *msg;
10736 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020010737
10738 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
10739
10740 if (!ft_event->target_ap)
10741 return;
10742
10743 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10744 if (!msg)
10745 return;
10746
10747 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
10748 if (!hdr) {
10749 nlmsg_free(msg);
10750 return;
10751 }
10752
10753 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
10754 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
10755 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
10756 if (ft_event->ies)
10757 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
10758 if (ft_event->ric_ies)
10759 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
10760 ft_event->ric_ies);
10761
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010762 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020010763
10764 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10765 nl80211_mlme_mcgrp.id, GFP_KERNEL);
10766}
10767EXPORT_SYMBOL(cfg80211_ft_event);
10768
Arend van Spriel5de17982013-04-18 15:49:00 +020010769void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
10770{
10771 struct cfg80211_registered_device *rdev;
10772 struct sk_buff *msg;
10773 void *hdr;
10774 u32 nlportid;
10775
10776 rdev = wiphy_to_dev(wdev->wiphy);
10777 if (!rdev->crit_proto_nlportid)
10778 return;
10779
10780 nlportid = rdev->crit_proto_nlportid;
10781 rdev->crit_proto_nlportid = 0;
10782
10783 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10784 if (!msg)
10785 return;
10786
10787 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
10788 if (!hdr)
10789 goto nla_put_failure;
10790
10791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10792 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10793 goto nla_put_failure;
10794
10795 genlmsg_end(msg, hdr);
10796
10797 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
10798 return;
10799
10800 nla_put_failure:
10801 if (hdr)
10802 genlmsg_cancel(msg, hdr);
10803 nlmsg_free(msg);
10804
10805}
10806EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
10807
Johannes Berg55682962007-09-20 13:09:35 -040010808/* initialisation/exit functions */
10809
10810int nl80211_init(void)
10811{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010812 int err;
Johannes Berg55682962007-09-20 13:09:35 -040010813
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000010814 err = genl_register_family_with_ops(&nl80211_fam,
10815 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040010816 if (err)
10817 return err;
10818
Johannes Berg55682962007-09-20 13:09:35 -040010819 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
10820 if (err)
10821 goto err_out;
10822
Johannes Berg2a519312009-02-10 21:25:55 +010010823 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
10824 if (err)
10825 goto err_out;
10826
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010827 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
10828 if (err)
10829 goto err_out;
10830
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010831 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
10832 if (err)
10833 goto err_out;
10834
Johannes Bergaff89a92009-07-01 21:26:51 +020010835#ifdef CONFIG_NL80211_TESTMODE
10836 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
10837 if (err)
10838 goto err_out;
10839#endif
10840
Jouni Malinen026331c2010-02-15 12:53:10 +020010841 err = netlink_register_notifier(&nl80211_netlink_notifier);
10842 if (err)
10843 goto err_out;
10844
Johannes Berg55682962007-09-20 13:09:35 -040010845 return 0;
10846 err_out:
10847 genl_unregister_family(&nl80211_fam);
10848 return err;
10849}
10850
10851void nl80211_exit(void)
10852{
Jouni Malinen026331c2010-02-15 12:53:10 +020010853 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040010854 genl_unregister_family(&nl80211_fam);
10855}