blob: 03d4ef95292e081beb4e8d442c38a6713dd123d0 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Berg4c476992010-10-04 21:36:35 +020033static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
34 struct genl_info *info);
35static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
36 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg89a54e42012-06-15 14:33:17 +020050/* returns ERR_PTR values */
51static struct wireless_dev *
52__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040053{
Johannes Berg89a54e42012-06-15 14:33:17 +020054 struct cfg80211_registered_device *rdev;
55 struct wireless_dev *result = NULL;
56 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
57 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
58 u64 wdev_id;
59 int wiphy_idx = -1;
60 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040061
Johannes Berg5fe231e2013-05-08 21:45:15 +020062 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040063
Johannes Berg89a54e42012-06-15 14:33:17 +020064 if (!have_ifidx && !have_wdev_id)
65 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040066
Johannes Berg89a54e42012-06-15 14:33:17 +020067 if (have_ifidx)
68 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
69 if (have_wdev_id) {
70 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
71 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040072 }
73
Johannes Berg89a54e42012-06-15 14:33:17 +020074 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
75 struct wireless_dev *wdev;
76
77 if (wiphy_net(&rdev->wiphy) != netns)
78 continue;
79
80 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
81 continue;
82
Johannes Berg89a54e42012-06-15 14:33:17 +020083 list_for_each_entry(wdev, &rdev->wdev_list, list) {
84 if (have_ifidx && wdev->netdev &&
85 wdev->netdev->ifindex == ifidx) {
86 result = wdev;
87 break;
88 }
89 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
90 result = wdev;
91 break;
92 }
93 }
Johannes Berg89a54e42012-06-15 14:33:17 +020094
95 if (result)
96 break;
97 }
98
99 if (result)
100 return result;
101 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400102}
103
Johannes Berga9455402012-06-15 13:32:49 +0200104static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200105__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200106{
Johannes Berg7fee4772012-06-15 14:09:58 +0200107 struct cfg80211_registered_device *rdev = NULL, *tmp;
108 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200109
Johannes Berg5fe231e2013-05-08 21:45:15 +0200110 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200111
Johannes Berg878d9ec2012-06-15 14:18:32 +0200112 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200113 !attrs[NL80211_ATTR_IFINDEX] &&
114 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200115 return ERR_PTR(-EINVAL);
116
Johannes Berg878d9ec2012-06-15 14:18:32 +0200117 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200118 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200120
Johannes Berg89a54e42012-06-15 14:33:17 +0200121 if (attrs[NL80211_ATTR_WDEV]) {
122 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
123 struct wireless_dev *wdev;
124 bool found = false;
125
126 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
127 if (tmp) {
128 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200129 list_for_each_entry(wdev, &tmp->wdev_list, list) {
130 if (wdev->identifier != (u32)wdev_id)
131 continue;
132 found = true;
133 break;
134 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200135
136 if (!found)
137 tmp = NULL;
138
139 if (rdev && tmp != rdev)
140 return ERR_PTR(-EINVAL);
141 rdev = tmp;
142 }
143 }
144
Johannes Berg878d9ec2012-06-15 14:18:32 +0200145 if (attrs[NL80211_ATTR_IFINDEX]) {
146 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200147 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200148 if (netdev) {
149 if (netdev->ieee80211_ptr)
150 tmp = wiphy_to_dev(
151 netdev->ieee80211_ptr->wiphy);
152 else
153 tmp = NULL;
154
155 dev_put(netdev);
156
157 /* not wireless device -- return error */
158 if (!tmp)
159 return ERR_PTR(-EINVAL);
160
161 /* mismatch -- return error */
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164
165 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200166 }
Johannes Berga9455402012-06-15 13:32:49 +0200167 }
168
Johannes Berg4f7eff12012-06-15 14:14:22 +0200169 if (!rdev)
170 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200171
Johannes Berg4f7eff12012-06-15 14:14:22 +0200172 if (netns != wiphy_net(&rdev->wiphy))
173 return ERR_PTR(-ENODEV);
174
175 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200176}
177
178/*
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200187{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200188 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
Johannes Berg55682962007-09-20 13:09:35 -0400191/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000192static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400193 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
194 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700195 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200196 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100197
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200198 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100200 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
201 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
202 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200204 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
205 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400209
210 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
211 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
212 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100213
Eliad Pellere007b852011-11-24 18:13:56 +0200214 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
215 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100216
Johannes Bergb9454e82009-07-08 13:29:08 +0200217 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100218 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
219 .len = WLAN_MAX_KEY_LEN },
220 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
221 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
222 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200223 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200224 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100225
226 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
227 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
228 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
229 .len = IEEE80211_MAX_DATA_LEN },
230 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
231 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100232 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
233 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
234 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
235 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
236 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100237 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100238 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200239 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100240 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800241 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100242 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300243
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700244 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
245 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
246
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300247 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200250 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
251 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100252 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300253
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800254 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700255 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700256
Johannes Berg6c739412011-11-03 09:27:01 +0100257 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200258
259 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
260 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
261 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100262 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
263 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200264
265 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
266 .len = IEEE80211_MAX_SSID_LEN },
267 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
268 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200269 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300270 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300271 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300272 [NL80211_ATTR_STA_FLAGS2] = {
273 .len = sizeof(struct nl80211_sta_flag_update),
274 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300275 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200278 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
279 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
280 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200281 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100282 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100283 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
284 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100285 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
286 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200287 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200288 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
289 .len = IEEE80211_MAX_DATA_LEN },
290 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200291 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200292 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300293 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200294 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200297 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900298 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
299 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100300 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100301 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100302 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200303 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700304 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300305 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200306 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200307 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300308 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300309 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
312 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530313 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300314 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530315 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300316 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
318 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
319 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100321 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200322 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
323 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700324 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800325 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
326 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
327 .len = NL80211_HT_CAPABILITY_LEN
328 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100329 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530330 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530331 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200332 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700333 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300334 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000335 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700336 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100337 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
338 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530339 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
340 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200341 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
342 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100343 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100344 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
346 .len = NL80211_VHT_CAPABILITY_LEN,
347 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200348 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
349 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
350 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300351 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Johannes Berg55682962007-09-20 13:09:35 -0400352};
353
Johannes Berge31b8212010-10-05 19:39:30 +0200354/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000355static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200356 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200357 [NL80211_KEY_IDX] = { .type = NLA_U8 },
358 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200359 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200360 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
361 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200362 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
364};
365
366/* policy for the key default flags */
367static const struct nla_policy
368nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200371};
372
Johannes Bergff1b6e62011-05-04 15:37:28 +0200373/* policy for WoWLAN attributes */
374static const struct nla_policy
375nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
376 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
377 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
385};
386
387static const struct nla_policy
388nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
390 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
391 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
392 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
393 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
396 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
397 },
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
399 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
400 },
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404};
405
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700406/* policy for coalesce rule attributes */
407static const struct nla_policy
408nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
409 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
410 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
411 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
412};
413
Johannes Berge5497d72011-07-05 16:35:40 +0200414/* policy for GTK rekey offload attributes */
415static const struct nla_policy
416nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
417 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
418 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
419 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
420};
421
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300422static const struct nla_policy
423nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200424 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300425 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700426 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300427};
428
Johannes Berg97990a02013-04-19 01:02:55 +0200429static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
430 struct netlink_callback *cb,
431 struct cfg80211_registered_device **rdev,
432 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100433{
Johannes Berg67748892010-10-04 21:14:06 +0200434 int err;
435
Johannes Berg67748892010-10-04 21:14:06 +0200436 rtnl_lock();
437
Johannes Berg97990a02013-04-19 01:02:55 +0200438 if (!cb->args[0]) {
439 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
440 nl80211_fam.attrbuf, nl80211_fam.maxattr,
441 nl80211_policy);
442 if (err)
443 goto out_unlock;
444
445 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
446 nl80211_fam.attrbuf);
447 if (IS_ERR(*wdev)) {
448 err = PTR_ERR(*wdev);
449 goto out_unlock;
450 }
451 *rdev = wiphy_to_dev((*wdev)->wiphy);
452 cb->args[0] = (*rdev)->wiphy_idx;
453 cb->args[1] = (*wdev)->identifier;
454 } else {
455 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
456 struct wireless_dev *tmp;
457
458 if (!wiphy) {
459 err = -ENODEV;
460 goto out_unlock;
461 }
462 *rdev = wiphy_to_dev(wiphy);
463 *wdev = NULL;
464
Johannes Berg97990a02013-04-19 01:02:55 +0200465 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
466 if (tmp->identifier == cb->args[1]) {
467 *wdev = tmp;
468 break;
469 }
470 }
Johannes Berg97990a02013-04-19 01:02:55 +0200471
472 if (!*wdev) {
473 err = -ENODEV;
474 goto out_unlock;
475 }
Johannes Berg67748892010-10-04 21:14:06 +0200476 }
477
Johannes Berg67748892010-10-04 21:14:06 +0200478 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200479 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200480 rtnl_unlock();
481 return err;
482}
483
Johannes Berg97990a02013-04-19 01:02:55 +0200484static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 rtnl_unlock();
487}
488
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100489/* IE validation */
490static bool is_valid_ie_attr(const struct nlattr *attr)
491{
492 const u8 *pos;
493 int len;
494
495 if (!attr)
496 return true;
497
498 pos = nla_data(attr);
499 len = nla_len(attr);
500
501 while (len) {
502 u8 elemlen;
503
504 if (len < 2)
505 return false;
506 len -= 2;
507
508 elemlen = pos[1];
509 if (elemlen > len)
510 return false;
511
512 len -= elemlen;
513 pos += 2 + elemlen;
514 }
515
516 return true;
517}
518
Johannes Berg55682962007-09-20 13:09:35 -0400519/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000520static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400521 int flags, u8 cmd)
522{
523 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000524 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400525}
526
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400527static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100528 struct ieee80211_channel *chan,
529 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400530{
David S. Miller9360ffd2012-03-29 04:41:26 -0400531 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
532 chan->center_freq))
533 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400534
David S. Miller9360ffd2012-03-29 04:41:26 -0400535 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
536 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
537 goto nla_put_failure;
538 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
539 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN))
540 goto nla_put_failure;
541 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
542 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS))
543 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100544 if (chan->flags & IEEE80211_CHAN_RADAR) {
545 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
546 goto nla_put_failure;
547 if (large) {
548 u32 time;
549
550 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
551
552 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
553 chan->dfs_state))
554 goto nla_put_failure;
555 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
556 time))
557 goto nla_put_failure;
558 }
559 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400560
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100561 if (large) {
562 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
563 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
564 goto nla_put_failure;
565 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
566 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
567 goto nla_put_failure;
568 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
569 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
570 goto nla_put_failure;
571 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
572 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
573 goto nla_put_failure;
574 }
575
David S. Miller9360ffd2012-03-29 04:41:26 -0400576 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
577 DBM_TO_MBM(chan->max_power)))
578 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400579
580 return 0;
581
582 nla_put_failure:
583 return -ENOBUFS;
584}
585
Johannes Berg55682962007-09-20 13:09:35 -0400586/* netlink command implementations */
587
Johannes Bergb9454e82009-07-08 13:29:08 +0200588struct key_parse {
589 struct key_params p;
590 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200591 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200592 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100593 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200594};
595
596static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
597{
598 struct nlattr *tb[NL80211_KEY_MAX + 1];
599 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
600 nl80211_key_policy);
601 if (err)
602 return err;
603
604 k->def = !!tb[NL80211_KEY_DEFAULT];
605 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
606
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100607 if (k->def) {
608 k->def_uni = true;
609 k->def_multi = true;
610 }
611 if (k->defmgmt)
612 k->def_multi = true;
613
Johannes Bergb9454e82009-07-08 13:29:08 +0200614 if (tb[NL80211_KEY_IDX])
615 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
616
617 if (tb[NL80211_KEY_DATA]) {
618 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
619 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
620 }
621
622 if (tb[NL80211_KEY_SEQ]) {
623 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
624 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
625 }
626
627 if (tb[NL80211_KEY_CIPHER])
628 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
629
Johannes Berge31b8212010-10-05 19:39:30 +0200630 if (tb[NL80211_KEY_TYPE]) {
631 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
632 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
633 return -EINVAL;
634 }
635
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100636 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
637 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100638 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
639 tb[NL80211_KEY_DEFAULT_TYPES],
640 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100641 if (err)
642 return err;
643
644 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
645 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
646 }
647
Johannes Bergb9454e82009-07-08 13:29:08 +0200648 return 0;
649}
650
651static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
652{
653 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
654 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
655 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
656 }
657
658 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
659 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
660 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
661 }
662
663 if (info->attrs[NL80211_ATTR_KEY_IDX])
664 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
665
666 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
667 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
668
669 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
670 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
671
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100672 if (k->def) {
673 k->def_uni = true;
674 k->def_multi = true;
675 }
676 if (k->defmgmt)
677 k->def_multi = true;
678
Johannes Berge31b8212010-10-05 19:39:30 +0200679 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
680 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
681 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
682 return -EINVAL;
683 }
684
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100685 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
686 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
687 int err = nla_parse_nested(
688 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
689 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
690 nl80211_key_default_policy);
691 if (err)
692 return err;
693
694 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
695 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
696 }
697
Johannes Bergb9454e82009-07-08 13:29:08 +0200698 return 0;
699}
700
701static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
702{
703 int err;
704
705 memset(k, 0, sizeof(*k));
706 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200707 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200708
709 if (info->attrs[NL80211_ATTR_KEY])
710 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
711 else
712 err = nl80211_parse_key_old(info, k);
713
714 if (err)
715 return err;
716
717 if (k->def && k->defmgmt)
718 return -EINVAL;
719
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100720 if (k->defmgmt) {
721 if (k->def_uni || !k->def_multi)
722 return -EINVAL;
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 if (k->idx != -1) {
726 if (k->defmgmt) {
727 if (k->idx < 4 || k->idx > 5)
728 return -EINVAL;
729 } else if (k->def) {
730 if (k->idx < 0 || k->idx > 3)
731 return -EINVAL;
732 } else {
733 if (k->idx < 0 || k->idx > 5)
734 return -EINVAL;
735 }
736 }
737
738 return 0;
739}
740
Johannes Bergfffd0932009-07-08 14:22:54 +0200741static struct cfg80211_cached_keys *
742nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530743 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200744{
745 struct key_parse parse;
746 struct nlattr *key;
747 struct cfg80211_cached_keys *result;
748 int rem, err, def = 0;
749
750 result = kzalloc(sizeof(*result), GFP_KERNEL);
751 if (!result)
752 return ERR_PTR(-ENOMEM);
753
754 result->def = -1;
755 result->defmgmt = -1;
756
757 nla_for_each_nested(key, keys, rem) {
758 memset(&parse, 0, sizeof(parse));
759 parse.idx = -1;
760
761 err = nl80211_parse_key_new(key, &parse);
762 if (err)
763 goto error;
764 err = -EINVAL;
765 if (!parse.p.key)
766 goto error;
767 if (parse.idx < 0 || parse.idx > 4)
768 goto error;
769 if (parse.def) {
770 if (def)
771 goto error;
772 def = 1;
773 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100774 if (!parse.def_uni || !parse.def_multi)
775 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200776 } else if (parse.defmgmt)
777 goto error;
778 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200779 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200780 if (err)
781 goto error;
782 result->params[parse.idx].cipher = parse.p.cipher;
783 result->params[parse.idx].key_len = parse.p.key_len;
784 result->params[parse.idx].key = result->data[parse.idx];
785 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530786
787 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
788 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
789 if (no_ht)
790 *no_ht = true;
791 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200792 }
793
794 return result;
795 error:
796 kfree(result);
797 return ERR_PTR(err);
798}
799
800static int nl80211_key_allowed(struct wireless_dev *wdev)
801{
802 ASSERT_WDEV_LOCK(wdev);
803
Johannes Bergfffd0932009-07-08 14:22:54 +0200804 switch (wdev->iftype) {
805 case NL80211_IFTYPE_AP:
806 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200807 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700808 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 break;
810 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200811 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200812 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200813 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200814 return -ENOLINK;
815 break;
816 default:
817 return -EINVAL;
818 }
819
820 return 0;
821}
822
Johannes Berg7527a782011-05-13 10:58:57 +0200823static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
824{
825 struct nlattr *nl_modes = nla_nest_start(msg, attr);
826 int i;
827
828 if (!nl_modes)
829 goto nla_put_failure;
830
831 i = 0;
832 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400833 if ((ifmodes & 1) && nla_put_flag(msg, i))
834 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200835 ifmodes >>= 1;
836 i++;
837 }
838
839 nla_nest_end(msg, nl_modes);
840 return 0;
841
842nla_put_failure:
843 return -ENOBUFS;
844}
845
846static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100847 struct sk_buff *msg,
848 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200849{
850 struct nlattr *nl_combis;
851 int i, j;
852
853 nl_combis = nla_nest_start(msg,
854 NL80211_ATTR_INTERFACE_COMBINATIONS);
855 if (!nl_combis)
856 goto nla_put_failure;
857
858 for (i = 0; i < wiphy->n_iface_combinations; i++) {
859 const struct ieee80211_iface_combination *c;
860 struct nlattr *nl_combi, *nl_limits;
861
862 c = &wiphy->iface_combinations[i];
863
864 nl_combi = nla_nest_start(msg, i + 1);
865 if (!nl_combi)
866 goto nla_put_failure;
867
868 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
869 if (!nl_limits)
870 goto nla_put_failure;
871
872 for (j = 0; j < c->n_limits; j++) {
873 struct nlattr *nl_limit;
874
875 nl_limit = nla_nest_start(msg, j + 1);
876 if (!nl_limit)
877 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400878 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
879 c->limits[j].max))
880 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200881 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
882 c->limits[j].types))
883 goto nla_put_failure;
884 nla_nest_end(msg, nl_limit);
885 }
886
887 nla_nest_end(msg, nl_limits);
888
David S. Miller9360ffd2012-03-29 04:41:26 -0400889 if (c->beacon_int_infra_match &&
890 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
891 goto nla_put_failure;
892 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
893 c->num_different_channels) ||
894 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
895 c->max_interfaces))
896 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100897 if (large &&
898 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
899 c->radar_detect_widths))
900 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200901
902 nla_nest_end(msg, nl_combi);
903 }
904
905 nla_nest_end(msg, nl_combis);
906
907 return 0;
908nla_put_failure:
909 return -ENOBUFS;
910}
911
Johannes Berg3713b4e2013-02-14 16:19:38 +0100912#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100913static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
914 struct sk_buff *msg)
915{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200916 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100917 struct nlattr *nl_tcp;
918
919 if (!tcp)
920 return 0;
921
922 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
923 if (!nl_tcp)
924 return -ENOBUFS;
925
926 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
927 tcp->data_payload_max))
928 return -ENOBUFS;
929
930 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
931 tcp->data_payload_max))
932 return -ENOBUFS;
933
934 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
935 return -ENOBUFS;
936
937 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
938 sizeof(*tcp->tok), tcp->tok))
939 return -ENOBUFS;
940
941 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
942 tcp->data_interval_max))
943 return -ENOBUFS;
944
945 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
946 tcp->wake_payload_max))
947 return -ENOBUFS;
948
949 nla_nest_end(msg, nl_tcp);
950 return 0;
951}
952
Johannes Berg3713b4e2013-02-14 16:19:38 +0100953static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100954 struct cfg80211_registered_device *dev,
955 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100956{
957 struct nlattr *nl_wowlan;
958
Johannes Berg964dc9e2013-06-03 17:25:34 +0200959 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100960 return 0;
961
962 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
963 if (!nl_wowlan)
964 return -ENOBUFS;
965
Johannes Berg964dc9e2013-06-03 17:25:34 +0200966 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200968 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200970 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200972 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200974 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100975 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200976 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100977 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200978 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100979 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +0200980 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +0100981 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
982 return -ENOBUFS;
983
Johannes Berg964dc9e2013-06-03 17:25:34 +0200984 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -0700985 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +0200986 .max_patterns = dev->wiphy.wowlan->n_patterns,
987 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
988 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
989 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +0100990 };
991
992 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
993 sizeof(pat), &pat))
994 return -ENOBUFS;
995 }
996
Johannes Bergb56cf722013-02-20 01:02:38 +0100997 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
998 return -ENOBUFS;
999
Johannes Berg3713b4e2013-02-14 16:19:38 +01001000 nla_nest_end(msg, nl_wowlan);
1001
1002 return 0;
1003}
1004#endif
1005
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001006static int nl80211_send_coalesce(struct sk_buff *msg,
1007 struct cfg80211_registered_device *dev)
1008{
1009 struct nl80211_coalesce_rule_support rule;
1010
1011 if (!dev->wiphy.coalesce)
1012 return 0;
1013
1014 rule.max_rules = dev->wiphy.coalesce->n_rules;
1015 rule.max_delay = dev->wiphy.coalesce->max_delay;
1016 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1017 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1018 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1019 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1020
1021 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1022 return -ENOBUFS;
1023
1024 return 0;
1025}
1026
Johannes Berg3713b4e2013-02-14 16:19:38 +01001027static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1028 struct ieee80211_supported_band *sband)
1029{
1030 struct nlattr *nl_rates, *nl_rate;
1031 struct ieee80211_rate *rate;
1032 int i;
1033
1034 /* add HT info */
1035 if (sband->ht_cap.ht_supported &&
1036 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1037 sizeof(sband->ht_cap.mcs),
1038 &sband->ht_cap.mcs) ||
1039 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1040 sband->ht_cap.cap) ||
1041 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1042 sband->ht_cap.ampdu_factor) ||
1043 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1044 sband->ht_cap.ampdu_density)))
1045 return -ENOBUFS;
1046
1047 /* add VHT info */
1048 if (sband->vht_cap.vht_supported &&
1049 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1050 sizeof(sband->vht_cap.vht_mcs),
1051 &sband->vht_cap.vht_mcs) ||
1052 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1053 sband->vht_cap.cap)))
1054 return -ENOBUFS;
1055
1056 /* add bitrates */
1057 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1058 if (!nl_rates)
1059 return -ENOBUFS;
1060
1061 for (i = 0; i < sband->n_bitrates; i++) {
1062 nl_rate = nla_nest_start(msg, i);
1063 if (!nl_rate)
1064 return -ENOBUFS;
1065
1066 rate = &sband->bitrates[i];
1067 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1068 rate->bitrate))
1069 return -ENOBUFS;
1070 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1071 nla_put_flag(msg,
1072 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1073 return -ENOBUFS;
1074
1075 nla_nest_end(msg, nl_rate);
1076 }
1077
1078 nla_nest_end(msg, nl_rates);
1079
1080 return 0;
1081}
1082
1083static int
1084nl80211_send_mgmt_stypes(struct sk_buff *msg,
1085 const struct ieee80211_txrx_stypes *mgmt_stypes)
1086{
1087 u16 stypes;
1088 struct nlattr *nl_ftypes, *nl_ifs;
1089 enum nl80211_iftype ift;
1090 int i;
1091
1092 if (!mgmt_stypes)
1093 return 0;
1094
1095 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1096 if (!nl_ifs)
1097 return -ENOBUFS;
1098
1099 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1100 nl_ftypes = nla_nest_start(msg, ift);
1101 if (!nl_ftypes)
1102 return -ENOBUFS;
1103 i = 0;
1104 stypes = mgmt_stypes[ift].tx;
1105 while (stypes) {
1106 if ((stypes & 1) &&
1107 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1108 (i << 4) | IEEE80211_FTYPE_MGMT))
1109 return -ENOBUFS;
1110 stypes >>= 1;
1111 i++;
1112 }
1113 nla_nest_end(msg, nl_ftypes);
1114 }
1115
1116 nla_nest_end(msg, nl_ifs);
1117
1118 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1119 if (!nl_ifs)
1120 return -ENOBUFS;
1121
1122 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1123 nl_ftypes = nla_nest_start(msg, ift);
1124 if (!nl_ftypes)
1125 return -ENOBUFS;
1126 i = 0;
1127 stypes = mgmt_stypes[ift].rx;
1128 while (stypes) {
1129 if ((stypes & 1) &&
1130 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1131 (i << 4) | IEEE80211_FTYPE_MGMT))
1132 return -ENOBUFS;
1133 stypes >>= 1;
1134 i++;
1135 }
1136 nla_nest_end(msg, nl_ftypes);
1137 }
1138 nla_nest_end(msg, nl_ifs);
1139
1140 return 0;
1141}
1142
Johannes Berg86e8cf92013-06-19 10:57:22 +02001143struct nl80211_dump_wiphy_state {
1144 s64 filter_wiphy;
1145 long start;
1146 long split_start, band_start, chan_start;
1147 bool split;
1148};
1149
Johannes Berg3713b4e2013-02-14 16:19:38 +01001150static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1151 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001152 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001153{
1154 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001155 struct nlattr *nl_bands, *nl_band;
1156 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001157 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001158 enum ieee80211_band band;
1159 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001160 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001161 const struct ieee80211_txrx_stypes *mgmt_stypes =
1162 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001163 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001164
Eric W. Biederman15e47302012-09-07 20:12:54 +00001165 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001166 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001167 return -ENOBUFS;
1168
Johannes Berg86e8cf92013-06-19 10:57:22 +02001169 if (WARN_ON(!state))
1170 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001171
David S. Miller9360ffd2012-03-29 04:41:26 -04001172 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001173 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1174 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001175 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001176 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001177 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001178
Johannes Berg86e8cf92013-06-19 10:57:22 +02001179 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001180 case 0:
1181 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1182 dev->wiphy.retry_short) ||
1183 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1184 dev->wiphy.retry_long) ||
1185 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1186 dev->wiphy.frag_threshold) ||
1187 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1188 dev->wiphy.rts_threshold) ||
1189 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1190 dev->wiphy.coverage_class) ||
1191 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1192 dev->wiphy.max_scan_ssids) ||
1193 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1194 dev->wiphy.max_sched_scan_ssids) ||
1195 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1196 dev->wiphy.max_scan_ie_len) ||
1197 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1198 dev->wiphy.max_sched_scan_ie_len) ||
1199 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1200 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001201 goto nla_put_failure;
1202
Johannes Berg3713b4e2013-02-14 16:19:38 +01001203 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1204 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1205 goto nla_put_failure;
1206 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1207 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1208 goto nla_put_failure;
1209 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1210 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1211 goto nla_put_failure;
1212 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1213 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1214 goto nla_put_failure;
1215 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1216 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1217 goto nla_put_failure;
1218 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1219 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001220 goto nla_put_failure;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001221 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1222 nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1223 goto nla_put_failure;
Johannes Bergd51626d2008-10-09 12:20:13 +02001224
Johannes Berg86e8cf92013-06-19 10:57:22 +02001225 state->split_start++;
1226 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001227 break;
1228 case 1:
1229 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1230 sizeof(u32) * dev->wiphy.n_cipher_suites,
1231 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001232 goto nla_put_failure;
1233
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1235 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001236 goto nla_put_failure;
1237
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1239 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1240 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001241
Johannes Berg3713b4e2013-02-14 16:19:38 +01001242 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1243 dev->wiphy.available_antennas_tx) ||
1244 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1245 dev->wiphy.available_antennas_rx))
1246 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001247
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1249 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1250 dev->wiphy.probe_resp_offload))
1251 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001252
Johannes Berg3713b4e2013-02-14 16:19:38 +01001253 if ((dev->wiphy.available_antennas_tx ||
1254 dev->wiphy.available_antennas_rx) &&
1255 dev->ops->get_antenna) {
1256 u32 tx_ant = 0, rx_ant = 0;
1257 int res;
1258 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1259 if (!res) {
1260 if (nla_put_u32(msg,
1261 NL80211_ATTR_WIPHY_ANTENNA_TX,
1262 tx_ant) ||
1263 nla_put_u32(msg,
1264 NL80211_ATTR_WIPHY_ANTENNA_RX,
1265 rx_ant))
1266 goto nla_put_failure;
1267 }
Johannes Bergee688b002008-01-24 19:38:39 +01001268 }
1269
Johannes Berg86e8cf92013-06-19 10:57:22 +02001270 state->split_start++;
1271 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 break;
1273 case 2:
1274 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1275 dev->wiphy.interface_modes))
1276 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001277 state->split_start++;
1278 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 break;
1280 case 3:
1281 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1282 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001283 goto nla_put_failure;
1284
Johannes Berg86e8cf92013-06-19 10:57:22 +02001285 for (band = state->band_start;
1286 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 struct ieee80211_supported_band *sband;
1288
1289 sband = dev->wiphy.bands[band];
1290
1291 if (!sband)
1292 continue;
1293
1294 nl_band = nla_nest_start(msg, band);
1295 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001296 goto nla_put_failure;
1297
Johannes Berg86e8cf92013-06-19 10:57:22 +02001298 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 case 0:
1300 if (nl80211_send_band_rateinfo(msg, sband))
1301 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001302 state->chan_start++;
1303 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 break;
1305 default:
1306 /* add frequencies */
1307 nl_freqs = nla_nest_start(
1308 msg, NL80211_BAND_ATTR_FREQS);
1309 if (!nl_freqs)
1310 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001311
Johannes Berg86e8cf92013-06-19 10:57:22 +02001312 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 i < sband->n_channels;
1314 i++) {
1315 nl_freq = nla_nest_start(msg, i);
1316 if (!nl_freq)
1317 goto nla_put_failure;
1318
1319 chan = &sband->channels[i];
1320
Johannes Berg86e8cf92013-06-19 10:57:22 +02001321 if (nl80211_msg_put_channel(
1322 msg, chan,
1323 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 goto nla_put_failure;
1325
1326 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 break;
1329 }
1330 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001331 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001333 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 nla_nest_end(msg, nl_freqs);
1335 }
1336
1337 nla_nest_end(msg, nl_band);
1338
Johannes Berg86e8cf92013-06-19 10:57:22 +02001339 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 band--;
1343 break;
1344 }
Johannes Bergee688b002008-01-24 19:38:39 +01001345 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001347
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001349 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001351 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001352
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001354 if (state->band_start == 0 && state->chan_start == 0)
1355 state->split_start++;
1356 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 break;
1358 case 4:
1359 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1360 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001361 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362
1363 i = 0;
1364#define CMD(op, n) \
1365 do { \
1366 if (dev->ops->op) { \
1367 i++; \
1368 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1369 goto nla_put_failure; \
1370 } \
1371 } while (0)
1372
1373 CMD(add_virtual_intf, NEW_INTERFACE);
1374 CMD(change_virtual_intf, SET_INTERFACE);
1375 CMD(add_key, NEW_KEY);
1376 CMD(start_ap, START_AP);
1377 CMD(add_station, NEW_STATION);
1378 CMD(add_mpath, NEW_MPATH);
1379 CMD(update_mesh_config, SET_MESH_CONFIG);
1380 CMD(change_bss, SET_BSS);
1381 CMD(auth, AUTHENTICATE);
1382 CMD(assoc, ASSOCIATE);
1383 CMD(deauth, DEAUTHENTICATE);
1384 CMD(disassoc, DISASSOCIATE);
1385 CMD(join_ibss, JOIN_IBSS);
1386 CMD(join_mesh, JOIN_MESH);
1387 CMD(set_pmksa, SET_PMKSA);
1388 CMD(del_pmksa, DEL_PMKSA);
1389 CMD(flush_pmksa, FLUSH_PMKSA);
1390 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1391 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1392 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1393 CMD(mgmt_tx, FRAME);
1394 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1395 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1396 i++;
1397 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1398 goto nla_put_failure;
1399 }
1400 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1401 dev->ops->join_mesh) {
1402 i++;
1403 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1404 goto nla_put_failure;
1405 }
1406 CMD(set_wds_peer, SET_WDS_PEER);
1407 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1408 CMD(tdls_mgmt, TDLS_MGMT);
1409 CMD(tdls_oper, TDLS_OPER);
1410 }
1411 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1412 CMD(sched_scan_start, START_SCHED_SCAN);
1413 CMD(probe_client, PROBE_CLIENT);
1414 CMD(set_noack_map, SET_NOACK_MAP);
1415 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1416 i++;
1417 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1418 goto nla_put_failure;
1419 }
1420 CMD(start_p2p_device, START_P2P_DEVICE);
1421 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001423 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1424 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1425 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001426
Kalle Valo4745fc02011-11-17 19:06:10 +02001427#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001429#endif
1430
Johannes Berg8fdc6212009-03-14 09:34:01 +01001431#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 if (dev->ops->connect || dev->ops->auth) {
1434 i++;
1435 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001436 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001437 }
1438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 if (dev->ops->disconnect || dev->ops->deauth) {
1440 i++;
1441 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1442 goto nla_put_failure;
1443 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001444
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 state->split_start++;
1447 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 break;
1449 case 5:
1450 if (dev->ops->remain_on_channel &&
1451 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1452 nla_put_u32(msg,
1453 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1454 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001455 goto nla_put_failure;
1456
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1458 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1459 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001460
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1462 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001463 state->split_start++;
1464 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 break;
1466 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001467#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001468 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001470 state->split_start++;
1471 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 break;
1473#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001474 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001475#endif
1476 case 7:
1477 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1478 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001479 goto nla_put_failure;
1480
Johannes Berg86e8cf92013-06-19 10:57:22 +02001481 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1482 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001484
Johannes Berg86e8cf92013-06-19 10:57:22 +02001485 state->split_start++;
1486 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 break;
1488 case 8:
1489 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1490 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1491 dev->wiphy.ap_sme_capa))
1492 goto nla_put_failure;
1493
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001494 features = dev->wiphy.features;
1495 /*
1496 * We can only add the per-channel limit information if the
1497 * dump is split, otherwise it makes it too big. Therefore
1498 * only advertise it in that case.
1499 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001500 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001501 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1502 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 goto nla_put_failure;
1504
1505 if (dev->wiphy.ht_capa_mod_mask &&
1506 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1507 sizeof(*dev->wiphy.ht_capa_mod_mask),
1508 dev->wiphy.ht_capa_mod_mask))
1509 goto nla_put_failure;
1510
1511 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1512 dev->wiphy.max_acl_mac_addrs &&
1513 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1514 dev->wiphy.max_acl_mac_addrs))
1515 goto nla_put_failure;
1516
1517 /*
1518 * Any information below this point is only available to
1519 * applications that can deal with it being split. This
1520 * helps ensure that newly added capabilities don't break
1521 * older tools by overrunning their buffers.
1522 *
1523 * We still increment split_start so that in the split
1524 * case we'll continue with more data in the next round,
1525 * but break unconditionally so unsplit data stops here.
1526 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 break;
1529 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001530 if (dev->wiphy.extended_capabilities &&
1531 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1532 dev->wiphy.extended_capabilities_len,
1533 dev->wiphy.extended_capabilities) ||
1534 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1535 dev->wiphy.extended_capabilities_len,
1536 dev->wiphy.extended_capabilities_mask)))
1537 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001538
Johannes Bergee2aca32013-02-21 17:36:01 +01001539 if (dev->wiphy.vht_capa_mod_mask &&
1540 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1541 sizeof(*dev->wiphy.vht_capa_mod_mask),
1542 dev->wiphy.vht_capa_mod_mask))
1543 goto nla_put_failure;
1544
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001545 state->split_start++;
1546 break;
1547 case 10:
1548 if (nl80211_send_coalesce(msg, dev))
1549 goto nla_put_failure;
1550
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001554 }
Johannes Berg55682962007-09-20 13:09:35 -04001555 return genlmsg_end(msg, hdr);
1556
1557 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001558 genlmsg_cancel(msg, hdr);
1559 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001560}
1561
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1563 struct netlink_callback *cb,
1564 struct nl80211_dump_wiphy_state *state)
1565{
1566 struct nlattr **tb = nl80211_fam.attrbuf;
1567 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1568 tb, nl80211_fam.maxattr, nl80211_policy);
1569 /* ignore parse errors for backward compatibility */
1570 if (ret)
1571 return 0;
1572
1573 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1574 if (tb[NL80211_ATTR_WIPHY])
1575 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1576 if (tb[NL80211_ATTR_WDEV])
1577 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1578 if (tb[NL80211_ATTR_IFINDEX]) {
1579 struct net_device *netdev;
1580 struct cfg80211_registered_device *rdev;
1581 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1582
1583 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1584 if (!netdev)
1585 return -ENODEV;
1586 if (netdev->ieee80211_ptr) {
1587 rdev = wiphy_to_dev(
1588 netdev->ieee80211_ptr->wiphy);
1589 state->filter_wiphy = rdev->wiphy_idx;
1590 }
1591 dev_put(netdev);
1592 }
1593
1594 return 0;
1595}
1596
Johannes Berg55682962007-09-20 13:09:35 -04001597static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1598{
Johannes Berg645e77d2013-03-01 14:03:49 +01001599 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001600 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001601 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001602
Johannes Berg5fe231e2013-05-08 21:45:15 +02001603 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001604 if (!state) {
1605 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001606 if (!state) {
1607 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001610 state->filter_wiphy = -1;
1611 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1612 if (ret) {
1613 kfree(state);
1614 rtnl_unlock();
1615 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001617 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 }
1619
Johannes Berg79c97e92009-07-07 03:56:12 +02001620 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001621 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1622 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001624 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001625 if (state->filter_wiphy != -1 &&
1626 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 continue;
1628 /* attempt to fit multiple wiphy data chunks into the skb */
1629 do {
1630 ret = nl80211_send_wiphy(dev, skb,
1631 NETLINK_CB(cb->skb).portid,
1632 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001633 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 if (ret < 0) {
1635 /*
1636 * If sending the wiphy data didn't fit (ENOBUFS
1637 * or EMSGSIZE returned), this SKB is still
1638 * empty (so it's not too big because another
1639 * wiphy dataset is already in the skb) and
1640 * we've not tried to adjust the dump allocation
1641 * yet ... then adjust the alloc size to be
1642 * bigger, and return 1 but with the empty skb.
1643 * This results in an empty message being RX'ed
1644 * in userspace, but that is ignored.
1645 *
1646 * We can then retry with the larger buffer.
1647 */
1648 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1649 !skb->len &&
1650 cb->min_dump_alloc < 4096) {
1651 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001652 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001653 return 1;
1654 }
1655 idx--;
1656 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001657 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001658 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 break;
Johannes Berg55682962007-09-20 13:09:35 -04001660 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001661 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001662
Johannes Berg86e8cf92013-06-19 10:57:22 +02001663 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001664
1665 return skb->len;
1666}
1667
Johannes Berg86e8cf92013-06-19 10:57:22 +02001668static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1669{
1670 kfree((void *)cb->args[0]);
1671 return 0;
1672}
1673
Johannes Berg55682962007-09-20 13:09:35 -04001674static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1675{
1676 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001677 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001678 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001679
Johannes Berg645e77d2013-03-01 14:03:49 +01001680 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001681 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001682 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001683
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001685 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001686 nlmsg_free(msg);
1687 return -ENOBUFS;
1688 }
Johannes Berg55682962007-09-20 13:09:35 -04001689
Johannes Berg134e6372009-07-10 09:51:34 +00001690 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001691}
1692
Jouni Malinen31888482008-10-30 16:59:24 +02001693static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1694 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1695 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1696 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1697 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1698 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1699};
1700
1701static int parse_txq_params(struct nlattr *tb[],
1702 struct ieee80211_txq_params *txq_params)
1703{
Johannes Berga3304b02012-03-28 11:04:24 +02001704 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001705 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1706 !tb[NL80211_TXQ_ATTR_AIFS])
1707 return -EINVAL;
1708
Johannes Berga3304b02012-03-28 11:04:24 +02001709 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001710 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1711 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1712 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1713 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1714
Johannes Berga3304b02012-03-28 11:04:24 +02001715 if (txq_params->ac >= NL80211_NUM_ACS)
1716 return -EINVAL;
1717
Jouni Malinen31888482008-10-30 16:59:24 +02001718 return 0;
1719}
1720
Johannes Bergf444de02010-05-05 15:25:02 +02001721static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1722{
1723 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001724 * You can only set the channel explicitly for WDS interfaces,
1725 * all others have their channel managed via their respective
1726 * "establish a connection" command (connect, join, ...)
1727 *
1728 * For AP/GO and mesh mode, the channel can be set with the
1729 * channel userspace API, but is only stored and passed to the
1730 * low-level driver when the AP starts or the mesh is joined.
1731 * This is for backward compatibility, userspace can also give
1732 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001733 *
1734 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001735 * whatever else is going on, so they have their own special
1736 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001737 */
1738 return !wdev ||
1739 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001740 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001741 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1742 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001743}
1744
Johannes Berg683b6d32012-11-08 21:25:48 +01001745static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1746 struct genl_info *info,
1747 struct cfg80211_chan_def *chandef)
1748{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301749 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001750
1751 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1752 return -EINVAL;
1753
1754 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1755
1756 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001757 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1758 chandef->center_freq1 = control_freq;
1759 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001760
1761 /* Primary channel not allowed */
1762 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1763 return -EINVAL;
1764
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001765 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1766 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001767
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001768 chantype = nla_get_u32(
1769 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1770
1771 switch (chantype) {
1772 case NL80211_CHAN_NO_HT:
1773 case NL80211_CHAN_HT20:
1774 case NL80211_CHAN_HT40PLUS:
1775 case NL80211_CHAN_HT40MINUS:
1776 cfg80211_chandef_create(chandef, chandef->chan,
1777 chantype);
1778 break;
1779 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001780 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001781 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001782 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1783 chandef->width =
1784 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1785 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1786 chandef->center_freq1 =
1787 nla_get_u32(
1788 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1789 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1790 chandef->center_freq2 =
1791 nla_get_u32(
1792 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1793 }
1794
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001795 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001796 return -EINVAL;
1797
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001798 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1799 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001800 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001801
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001802 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1803 chandef->width == NL80211_CHAN_WIDTH_10) &&
1804 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1805 return -EINVAL;
1806
Johannes Berg683b6d32012-11-08 21:25:48 +01001807 return 0;
1808}
1809
Johannes Bergf444de02010-05-05 15:25:02 +02001810static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1811 struct wireless_dev *wdev,
1812 struct genl_info *info)
1813{
Johannes Berg683b6d32012-11-08 21:25:48 +01001814 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001815 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001816 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1817
1818 if (wdev)
1819 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001820
Johannes Bergf444de02010-05-05 15:25:02 +02001821 if (!nl80211_can_set_dev_channel(wdev))
1822 return -EOPNOTSUPP;
1823
Johannes Berg683b6d32012-11-08 21:25:48 +01001824 result = nl80211_parse_chandef(rdev, info, &chandef);
1825 if (result)
1826 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001827
Johannes Berge8c9bd52012-06-06 08:18:22 +02001828 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001829 case NL80211_IFTYPE_AP:
1830 case NL80211_IFTYPE_P2P_GO:
1831 if (wdev->beacon_interval) {
1832 result = -EBUSY;
1833 break;
1834 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001835 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001836 result = -EINVAL;
1837 break;
1838 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001839 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001840 result = 0;
1841 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001842 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001843 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001844 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001845 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001846 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001847 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001848 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001849 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001850 }
Johannes Bergf444de02010-05-05 15:25:02 +02001851
1852 return result;
1853}
1854
1855static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1856{
Johannes Berg4c476992010-10-04 21:36:35 +02001857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1858 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001859
Johannes Berg4c476992010-10-04 21:36:35 +02001860 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001861}
1862
Bill Jordane8347eb2010-10-01 13:54:28 -04001863static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1864{
Johannes Berg43b19952010-10-07 13:10:30 +02001865 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1866 struct net_device *dev = info->user_ptr[1];
1867 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001868 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001869
1870 if (!info->attrs[NL80211_ATTR_MAC])
1871 return -EINVAL;
1872
Johannes Berg43b19952010-10-07 13:10:30 +02001873 if (netif_running(dev))
1874 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001875
Johannes Berg43b19952010-10-07 13:10:30 +02001876 if (!rdev->ops->set_wds_peer)
1877 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001878
Johannes Berg43b19952010-10-07 13:10:30 +02001879 if (wdev->iftype != NL80211_IFTYPE_WDS)
1880 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001881
1882 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001883 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001884}
1885
1886
Johannes Berg55682962007-09-20 13:09:35 -04001887static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1888{
1889 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001890 struct net_device *netdev = NULL;
1891 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001892 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001893 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001894 u32 changed;
1895 u8 retry_short = 0, retry_long = 0;
1896 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001897 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001898
Johannes Berg5fe231e2013-05-08 21:45:15 +02001899 ASSERT_RTNL();
1900
Johannes Bergf444de02010-05-05 15:25:02 +02001901 /*
1902 * Try to find the wiphy and netdev. Normally this
1903 * function shouldn't need the netdev, but this is
1904 * done for backward compatibility -- previously
1905 * setting the channel was done per wiphy, but now
1906 * it is per netdev. Previous userland like hostapd
1907 * also passed a netdev to set_wiphy, so that it is
1908 * possible to let that go to the right netdev!
1909 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001910
Johannes Bergf444de02010-05-05 15:25:02 +02001911 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1912 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1913
1914 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001915 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001916 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001917 else
Johannes Bergf444de02010-05-05 15:25:02 +02001918 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001919 }
1920
Johannes Bergf444de02010-05-05 15:25:02 +02001921 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001922 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1923 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001924 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001925 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001926 wdev = NULL;
1927 netdev = NULL;
1928 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001929 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001930 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001931
1932 /*
1933 * end workaround code, by now the rdev is available
1934 * and locked, and wdev may or may not be NULL.
1935 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001936
1937 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001938 result = cfg80211_dev_rename(
1939 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001940
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001941 if (result)
1942 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001943
Jouni Malinen31888482008-10-30 16:59:24 +02001944 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1945 struct ieee80211_txq_params txq_params;
1946 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1947
1948 if (!rdev->ops->set_txq_params) {
1949 result = -EOPNOTSUPP;
1950 goto bad_res;
1951 }
1952
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001953 if (!netdev) {
1954 result = -EINVAL;
1955 goto bad_res;
1956 }
1957
Johannes Berg133a3ff2011-11-03 14:50:13 +01001958 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1959 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
1960 result = -EINVAL;
1961 goto bad_res;
1962 }
1963
Johannes Berg2b5f8b02012-04-02 10:51:55 +02001964 if (!netif_running(netdev)) {
1965 result = -ENETDOWN;
1966 goto bad_res;
1967 }
1968
Jouni Malinen31888482008-10-30 16:59:24 +02001969 nla_for_each_nested(nl_txq_params,
1970 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1971 rem_txq_params) {
1972 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1973 nla_data(nl_txq_params),
1974 nla_len(nl_txq_params),
1975 txq_params_policy);
1976 result = parse_txq_params(tb, &txq_params);
1977 if (result)
1978 goto bad_res;
1979
Hila Gonene35e4d22012-06-27 17:19:42 +03001980 result = rdev_set_txq_params(rdev, netdev,
1981 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02001982 if (result)
1983 goto bad_res;
1984 }
1985 }
1986
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001987 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02001988 result = __nl80211_set_channel(rdev,
1989 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
1990 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001991 if (result)
1992 goto bad_res;
1993 }
1994
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001995 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02001996 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03001997 enum nl80211_tx_power_setting type;
1998 int idx, mbm = 0;
1999
Johannes Bergc8442112012-10-24 10:17:18 +02002000 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2001 txp_wdev = NULL;
2002
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002003 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002004 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002005 goto bad_res;
2006 }
2007
2008 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2009 type = nla_get_u32(info->attrs[idx]);
2010
2011 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2012 (type != NL80211_TX_POWER_AUTOMATIC)) {
2013 result = -EINVAL;
2014 goto bad_res;
2015 }
2016
2017 if (type != NL80211_TX_POWER_AUTOMATIC) {
2018 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2019 mbm = nla_get_u32(info->attrs[idx]);
2020 }
2021
Johannes Bergc8442112012-10-24 10:17:18 +02002022 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002023 if (result)
2024 goto bad_res;
2025 }
2026
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002027 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2028 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2029 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002030 if ((!rdev->wiphy.available_antennas_tx &&
2031 !rdev->wiphy.available_antennas_rx) ||
2032 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002033 result = -EOPNOTSUPP;
2034 goto bad_res;
2035 }
2036
2037 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2038 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2039
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002040 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002041 * available antenna masks, except for the "all" mask */
2042 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2043 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002044 result = -EINVAL;
2045 goto bad_res;
2046 }
2047
Bruno Randolf7f531e02010-12-16 11:30:22 +09002048 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2049 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002050
Hila Gonene35e4d22012-06-27 17:19:42 +03002051 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002052 if (result)
2053 goto bad_res;
2054 }
2055
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056 changed = 0;
2057
2058 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2059 retry_short = nla_get_u8(
2060 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2061 if (retry_short == 0) {
2062 result = -EINVAL;
2063 goto bad_res;
2064 }
2065 changed |= WIPHY_PARAM_RETRY_SHORT;
2066 }
2067
2068 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2069 retry_long = nla_get_u8(
2070 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2071 if (retry_long == 0) {
2072 result = -EINVAL;
2073 goto bad_res;
2074 }
2075 changed |= WIPHY_PARAM_RETRY_LONG;
2076 }
2077
2078 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2079 frag_threshold = nla_get_u32(
2080 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2081 if (frag_threshold < 256) {
2082 result = -EINVAL;
2083 goto bad_res;
2084 }
2085 if (frag_threshold != (u32) -1) {
2086 /*
2087 * Fragments (apart from the last one) are required to
2088 * have even length. Make the fragmentation code
2089 * simpler by stripping LSB should someone try to use
2090 * odd threshold value.
2091 */
2092 frag_threshold &= ~0x1;
2093 }
2094 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2095 }
2096
2097 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2098 rts_threshold = nla_get_u32(
2099 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2100 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2101 }
2102
Lukáš Turek81077e82009-12-21 22:50:47 +01002103 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2104 coverage_class = nla_get_u8(
2105 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2106 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2107 }
2108
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002109 if (changed) {
2110 u8 old_retry_short, old_retry_long;
2111 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002112 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002113
2114 if (!rdev->ops->set_wiphy_params) {
2115 result = -EOPNOTSUPP;
2116 goto bad_res;
2117 }
2118
2119 old_retry_short = rdev->wiphy.retry_short;
2120 old_retry_long = rdev->wiphy.retry_long;
2121 old_frag_threshold = rdev->wiphy.frag_threshold;
2122 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002123 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002124
2125 if (changed & WIPHY_PARAM_RETRY_SHORT)
2126 rdev->wiphy.retry_short = retry_short;
2127 if (changed & WIPHY_PARAM_RETRY_LONG)
2128 rdev->wiphy.retry_long = retry_long;
2129 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2130 rdev->wiphy.frag_threshold = frag_threshold;
2131 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2132 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002133 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2134 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002135
Hila Gonene35e4d22012-06-27 17:19:42 +03002136 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002137 if (result) {
2138 rdev->wiphy.retry_short = old_retry_short;
2139 rdev->wiphy.retry_long = old_retry_long;
2140 rdev->wiphy.frag_threshold = old_frag_threshold;
2141 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002142 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002143 }
2144 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002145
Johannes Berg306d6112008-12-08 12:39:04 +01002146 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002147 if (netdev)
2148 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002149 return result;
2150}
2151
Johannes Berg71bbc992012-06-15 15:30:18 +02002152static inline u64 wdev_id(struct wireless_dev *wdev)
2153{
2154 return (u64)wdev->identifier |
2155 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2156}
Johannes Berg55682962007-09-20 13:09:35 -04002157
Johannes Berg683b6d32012-11-08 21:25:48 +01002158static int nl80211_send_chandef(struct sk_buff *msg,
2159 struct cfg80211_chan_def *chandef)
2160{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002161 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002162
Johannes Berg683b6d32012-11-08 21:25:48 +01002163 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2164 chandef->chan->center_freq))
2165 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002166 switch (chandef->width) {
2167 case NL80211_CHAN_WIDTH_20_NOHT:
2168 case NL80211_CHAN_WIDTH_20:
2169 case NL80211_CHAN_WIDTH_40:
2170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2171 cfg80211_get_chandef_type(chandef)))
2172 return -ENOBUFS;
2173 break;
2174 default:
2175 break;
2176 }
2177 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2178 return -ENOBUFS;
2179 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2180 return -ENOBUFS;
2181 if (chandef->center_freq2 &&
2182 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002183 return -ENOBUFS;
2184 return 0;
2185}
2186
Eric W. Biederman15e47302012-09-07 20:12:54 +00002187static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002188 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002189 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002190{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002191 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002192 void *hdr;
2193
Eric W. Biederman15e47302012-09-07 20:12:54 +00002194 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002195 if (!hdr)
2196 return -1;
2197
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002198 if (dev &&
2199 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002200 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002201 goto nla_put_failure;
2202
2203 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2204 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002205 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002207 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2208 rdev->devlist_generation ^
2209 (cfg80211_rdev_list_generation << 2)))
2210 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002211
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002212 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002213 int ret;
2214 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002215
Johannes Berg683b6d32012-11-08 21:25:48 +01002216 ret = rdev_get_channel(rdev, wdev, &chandef);
2217 if (ret == 0) {
2218 if (nl80211_send_chandef(msg, &chandef))
2219 goto nla_put_failure;
2220 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002221 }
2222
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002223 if (wdev->ssid_len) {
2224 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2225 goto nla_put_failure;
2226 }
2227
Johannes Berg55682962007-09-20 13:09:35 -04002228 return genlmsg_end(msg, hdr);
2229
2230 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002231 genlmsg_cancel(msg, hdr);
2232 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002233}
2234
2235static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2236{
2237 int wp_idx = 0;
2238 int if_idx = 0;
2239 int wp_start = cb->args[0];
2240 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002241 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002242 struct wireless_dev *wdev;
2243
Johannes Berg5fe231e2013-05-08 21:45:15 +02002244 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002245 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2246 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002247 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002248 if (wp_idx < wp_start) {
2249 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002250 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002251 }
Johannes Berg55682962007-09-20 13:09:35 -04002252 if_idx = 0;
2253
Johannes Berg89a54e42012-06-15 14:33:17 +02002254 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002255 if (if_idx < if_start) {
2256 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002257 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002258 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002259 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002260 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002261 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002262 goto out;
2263 }
2264 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002265 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002266
2267 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002268 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002269 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002270 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002271
2272 cb->args[0] = wp_idx;
2273 cb->args[1] = if_idx;
2274
2275 return skb->len;
2276}
2277
2278static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2279{
2280 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002281 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002282 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002283
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002284 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002285 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002286 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002287
Eric W. Biederman15e47302012-09-07 20:12:54 +00002288 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002289 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002290 nlmsg_free(msg);
2291 return -ENOBUFS;
2292 }
Johannes Berg55682962007-09-20 13:09:35 -04002293
Johannes Berg134e6372009-07-10 09:51:34 +00002294 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002295}
2296
Michael Wu66f7ac52008-01-31 19:48:22 +01002297static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2298 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2299 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2300 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2301 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2302 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002303 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002304};
2305
2306static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2307{
2308 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2309 int flag;
2310
2311 *mntrflags = 0;
2312
2313 if (!nla)
2314 return -EINVAL;
2315
2316 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2317 nla, mntr_flags_policy))
2318 return -EINVAL;
2319
2320 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2321 if (flags[flag])
2322 *mntrflags |= (1<<flag);
2323
2324 return 0;
2325}
2326
Johannes Berg9bc383d2009-11-19 11:55:19 +01002327static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002328 struct net_device *netdev, u8 use_4addr,
2329 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002330{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002331 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002332 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002333 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002334 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002335 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002336
2337 switch (iftype) {
2338 case NL80211_IFTYPE_AP_VLAN:
2339 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2340 return 0;
2341 break;
2342 case NL80211_IFTYPE_STATION:
2343 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2344 return 0;
2345 break;
2346 default:
2347 break;
2348 }
2349
2350 return -EOPNOTSUPP;
2351}
2352
Johannes Berg55682962007-09-20 13:09:35 -04002353static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2354{
Johannes Berg4c476992010-10-04 21:36:35 +02002355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002356 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002357 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002358 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002359 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002360 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002361 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002362
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002363 memset(&params, 0, sizeof(params));
2364
Johannes Berg04a773a2009-04-19 21:24:32 +02002365 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002366
Johannes Berg723b0382008-09-16 20:22:09 +02002367 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002368 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002369 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002370 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002371 if (ntype > NL80211_IFTYPE_MAX)
2372 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002373 }
2374
Johannes Berg92ffe052008-09-16 20:39:36 +02002375 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002376 struct wireless_dev *wdev = dev->ieee80211_ptr;
2377
Johannes Berg4c476992010-10-04 21:36:35 +02002378 if (ntype != NL80211_IFTYPE_MESH_POINT)
2379 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002380 if (netif_running(dev))
2381 return -EBUSY;
2382
2383 wdev_lock(wdev);
2384 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2385 IEEE80211_MAX_MESH_ID_LEN);
2386 wdev->mesh_id_up_len =
2387 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2388 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2389 wdev->mesh_id_up_len);
2390 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002391 }
2392
Felix Fietkau8b787642009-11-10 18:53:10 +01002393 if (info->attrs[NL80211_ATTR_4ADDR]) {
2394 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2395 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002396 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002397 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002398 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002399 } else {
2400 params.use_4addr = -1;
2401 }
2402
Johannes Berg92ffe052008-09-16 20:39:36 +02002403 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002404 if (ntype != NL80211_IFTYPE_MONITOR)
2405 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002406 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2407 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002408 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002409 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002410
2411 flags = &_flags;
2412 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002413 }
Johannes Berg3b858752009-03-12 09:55:09 +01002414
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002415 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
2416 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2417 return -EOPNOTSUPP;
2418
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002419 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002420 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002421 else
2422 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002423
Johannes Berg9bc383d2009-11-19 11:55:19 +01002424 if (!err && params.use_4addr != -1)
2425 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2426
Johannes Berg55682962007-09-20 13:09:35 -04002427 return err;
2428}
2429
2430static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2431{
Johannes Berg4c476992010-10-04 21:36:35 +02002432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002433 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002434 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002435 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002436 int err;
2437 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002438 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002439
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002440 memset(&params, 0, sizeof(params));
2441
Johannes Berg55682962007-09-20 13:09:35 -04002442 if (!info->attrs[NL80211_ATTR_IFNAME])
2443 return -EINVAL;
2444
2445 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2446 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2447 if (type > NL80211_IFTYPE_MAX)
2448 return -EINVAL;
2449 }
2450
Johannes Berg79c97e92009-07-07 03:56:12 +02002451 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002452 !(rdev->wiphy.interface_modes & (1 << type)))
2453 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002454
Arend van Spriel1c18f142013-01-08 10:17:27 +01002455 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2456 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2457 ETH_ALEN);
2458 if (!is_valid_ether_addr(params.macaddr))
2459 return -EADDRNOTAVAIL;
2460 }
2461
Johannes Berg9bc383d2009-11-19 11:55:19 +01002462 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002463 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002464 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002465 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002466 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002467 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002468
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2470 if (!msg)
2471 return -ENOMEM;
2472
Michael Wu66f7ac52008-01-31 19:48:22 +01002473 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2474 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2475 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002476
2477 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
2478 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2479 return -EOPNOTSUPP;
2480
Hila Gonene35e4d22012-06-27 17:19:42 +03002481 wdev = rdev_add_virtual_intf(rdev,
2482 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2483 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002484 if (IS_ERR(wdev)) {
2485 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002486 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002487 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002488
Johannes Berg98104fde2012-06-16 00:19:54 +02002489 switch (type) {
2490 case NL80211_IFTYPE_MESH_POINT:
2491 if (!info->attrs[NL80211_ATTR_MESH_ID])
2492 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002493 wdev_lock(wdev);
2494 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2495 IEEE80211_MAX_MESH_ID_LEN);
2496 wdev->mesh_id_up_len =
2497 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2498 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2499 wdev->mesh_id_up_len);
2500 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002501 break;
2502 case NL80211_IFTYPE_P2P_DEVICE:
2503 /*
2504 * P2P Device doesn't have a netdev, so doesn't go
2505 * through the netdev notifier and must be added here
2506 */
2507 mutex_init(&wdev->mtx);
2508 INIT_LIST_HEAD(&wdev->event_list);
2509 spin_lock_init(&wdev->event_lock);
2510 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2511 spin_lock_init(&wdev->mgmt_registrations_lock);
2512
Johannes Berg98104fde2012-06-16 00:19:54 +02002513 wdev->identifier = ++rdev->wdev_id;
2514 list_add_rcu(&wdev->list, &rdev->wdev_list);
2515 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002516 break;
2517 default:
2518 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002519 }
2520
Eric W. Biederman15e47302012-09-07 20:12:54 +00002521 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002522 rdev, wdev) < 0) {
2523 nlmsg_free(msg);
2524 return -ENOBUFS;
2525 }
2526
2527 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002528}
2529
2530static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2531{
Johannes Berg4c476992010-10-04 21:36:35 +02002532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002533 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002534
Johannes Berg4c476992010-10-04 21:36:35 +02002535 if (!rdev->ops->del_virtual_intf)
2536 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002537
Johannes Berg84efbb82012-06-16 00:00:26 +02002538 /*
2539 * If we remove a wireless device without a netdev then clear
2540 * user_ptr[1] so that nl80211_post_doit won't dereference it
2541 * to check if it needs to do dev_put(). Otherwise it crashes
2542 * since the wdev has been freed, unlike with a netdev where
2543 * we need the dev_put() for the netdev to really be freed.
2544 */
2545 if (!wdev->netdev)
2546 info->user_ptr[1] = NULL;
2547
Hila Gonene35e4d22012-06-27 17:19:42 +03002548 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002549}
2550
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002551static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2552{
2553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2554 struct net_device *dev = info->user_ptr[1];
2555 u16 noack_map;
2556
2557 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2558 return -EINVAL;
2559
2560 if (!rdev->ops->set_noack_map)
2561 return -EOPNOTSUPP;
2562
2563 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2564
Hila Gonene35e4d22012-06-27 17:19:42 +03002565 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002566}
2567
Johannes Berg41ade002007-12-19 02:03:29 +01002568struct get_key_cookie {
2569 struct sk_buff *msg;
2570 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002571 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002572};
2573
2574static void get_key_callback(void *c, struct key_params *params)
2575{
Johannes Bergb9454e82009-07-08 13:29:08 +02002576 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002577 struct get_key_cookie *cookie = c;
2578
David S. Miller9360ffd2012-03-29 04:41:26 -04002579 if ((params->key &&
2580 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2581 params->key_len, params->key)) ||
2582 (params->seq &&
2583 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2584 params->seq_len, params->seq)) ||
2585 (params->cipher &&
2586 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2587 params->cipher)))
2588 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002589
Johannes Bergb9454e82009-07-08 13:29:08 +02002590 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2591 if (!key)
2592 goto nla_put_failure;
2593
David S. Miller9360ffd2012-03-29 04:41:26 -04002594 if ((params->key &&
2595 nla_put(cookie->msg, NL80211_KEY_DATA,
2596 params->key_len, params->key)) ||
2597 (params->seq &&
2598 nla_put(cookie->msg, NL80211_KEY_SEQ,
2599 params->seq_len, params->seq)) ||
2600 (params->cipher &&
2601 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2602 params->cipher)))
2603 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002604
David S. Miller9360ffd2012-03-29 04:41:26 -04002605 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2606 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002607
2608 nla_nest_end(cookie->msg, key);
2609
Johannes Berg41ade002007-12-19 02:03:29 +01002610 return;
2611 nla_put_failure:
2612 cookie->error = 1;
2613}
2614
2615static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2616{
Johannes Berg4c476992010-10-04 21:36:35 +02002617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002618 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002619 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002620 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002621 const u8 *mac_addr = NULL;
2622 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002623 struct get_key_cookie cookie = {
2624 .error = 0,
2625 };
2626 void *hdr;
2627 struct sk_buff *msg;
2628
2629 if (info->attrs[NL80211_ATTR_KEY_IDX])
2630 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2631
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002632 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002633 return -EINVAL;
2634
2635 if (info->attrs[NL80211_ATTR_MAC])
2636 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2637
Johannes Berge31b8212010-10-05 19:39:30 +02002638 pairwise = !!mac_addr;
2639 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2640 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2641 if (kt >= NUM_NL80211_KEYTYPES)
2642 return -EINVAL;
2643 if (kt != NL80211_KEYTYPE_GROUP &&
2644 kt != NL80211_KEYTYPE_PAIRWISE)
2645 return -EINVAL;
2646 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2647 }
2648
Johannes Berg4c476992010-10-04 21:36:35 +02002649 if (!rdev->ops->get_key)
2650 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002651
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002652 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002653 if (!msg)
2654 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002655
Eric W. Biederman15e47302012-09-07 20:12:54 +00002656 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002657 NL80211_CMD_NEW_KEY);
Johannes Berg4c476992010-10-04 21:36:35 +02002658 if (IS_ERR(hdr))
2659 return PTR_ERR(hdr);
Johannes Berg41ade002007-12-19 02:03:29 +01002660
2661 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002662 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002663
David S. Miller9360ffd2012-03-29 04:41:26 -04002664 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2665 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2666 goto nla_put_failure;
2667 if (mac_addr &&
2668 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2669 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002670
Johannes Berge31b8212010-10-05 19:39:30 +02002671 if (pairwise && mac_addr &&
2672 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2673 return -ENOENT;
2674
Hila Gonene35e4d22012-06-27 17:19:42 +03002675 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2676 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002677
2678 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002679 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002680
2681 if (cookie.error)
2682 goto nla_put_failure;
2683
2684 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002685 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002686
2687 nla_put_failure:
2688 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002689 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002690 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002691 return err;
2692}
2693
2694static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2695{
Johannes Berg4c476992010-10-04 21:36:35 +02002696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002697 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002698 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002699 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002700
Johannes Bergb9454e82009-07-08 13:29:08 +02002701 err = nl80211_parse_key(info, &key);
2702 if (err)
2703 return err;
2704
2705 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002706 return -EINVAL;
2707
Johannes Bergb9454e82009-07-08 13:29:08 +02002708 /* only support setting default key */
2709 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002710 return -EINVAL;
2711
Johannes Bergfffd0932009-07-08 14:22:54 +02002712 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002713
2714 if (key.def) {
2715 if (!rdev->ops->set_default_key) {
2716 err = -EOPNOTSUPP;
2717 goto out;
2718 }
2719
2720 err = nl80211_key_allowed(dev->ieee80211_ptr);
2721 if (err)
2722 goto out;
2723
Hila Gonene35e4d22012-06-27 17:19:42 +03002724 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002725 key.def_uni, key.def_multi);
2726
2727 if (err)
2728 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002729
Johannes Berg3d23e342009-09-29 23:27:28 +02002730#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002731 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002732#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002733 } else {
2734 if (key.def_uni || !key.def_multi) {
2735 err = -EINVAL;
2736 goto out;
2737 }
2738
2739 if (!rdev->ops->set_default_mgmt_key) {
2740 err = -EOPNOTSUPP;
2741 goto out;
2742 }
2743
2744 err = nl80211_key_allowed(dev->ieee80211_ptr);
2745 if (err)
2746 goto out;
2747
Hila Gonene35e4d22012-06-27 17:19:42 +03002748 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002749 if (err)
2750 goto out;
2751
2752#ifdef CONFIG_CFG80211_WEXT
2753 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2754#endif
2755 }
2756
2757 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002758 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002759
Johannes Berg41ade002007-12-19 02:03:29 +01002760 return err;
2761}
2762
2763static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2764{
Johannes Berg4c476992010-10-04 21:36:35 +02002765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002766 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002767 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002768 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002769 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002770
Johannes Bergb9454e82009-07-08 13:29:08 +02002771 err = nl80211_parse_key(info, &key);
2772 if (err)
2773 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002774
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002776 return -EINVAL;
2777
Johannes Berg41ade002007-12-19 02:03:29 +01002778 if (info->attrs[NL80211_ATTR_MAC])
2779 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2780
Johannes Berge31b8212010-10-05 19:39:30 +02002781 if (key.type == -1) {
2782 if (mac_addr)
2783 key.type = NL80211_KEYTYPE_PAIRWISE;
2784 else
2785 key.type = NL80211_KEYTYPE_GROUP;
2786 }
2787
2788 /* for now */
2789 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2790 key.type != NL80211_KEYTYPE_GROUP)
2791 return -EINVAL;
2792
Johannes Berg4c476992010-10-04 21:36:35 +02002793 if (!rdev->ops->add_key)
2794 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002795
Johannes Berge31b8212010-10-05 19:39:30 +02002796 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2797 key.type == NL80211_KEYTYPE_PAIRWISE,
2798 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002799 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002800
2801 wdev_lock(dev->ieee80211_ptr);
2802 err = nl80211_key_allowed(dev->ieee80211_ptr);
2803 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002804 err = rdev_add_key(rdev, dev, key.idx,
2805 key.type == NL80211_KEYTYPE_PAIRWISE,
2806 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002807 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002808
Johannes Berg41ade002007-12-19 02:03:29 +01002809 return err;
2810}
2811
2812static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2813{
Johannes Berg4c476992010-10-04 21:36:35 +02002814 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002815 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002816 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002817 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002819
Johannes Bergb9454e82009-07-08 13:29:08 +02002820 err = nl80211_parse_key(info, &key);
2821 if (err)
2822 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002823
2824 if (info->attrs[NL80211_ATTR_MAC])
2825 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2826
Johannes Berge31b8212010-10-05 19:39:30 +02002827 if (key.type == -1) {
2828 if (mac_addr)
2829 key.type = NL80211_KEYTYPE_PAIRWISE;
2830 else
2831 key.type = NL80211_KEYTYPE_GROUP;
2832 }
2833
2834 /* for now */
2835 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2836 key.type != NL80211_KEYTYPE_GROUP)
2837 return -EINVAL;
2838
Johannes Berg4c476992010-10-04 21:36:35 +02002839 if (!rdev->ops->del_key)
2840 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002841
Johannes Bergfffd0932009-07-08 14:22:54 +02002842 wdev_lock(dev->ieee80211_ptr);
2843 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002844
2845 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2846 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2847 err = -ENOENT;
2848
Johannes Bergfffd0932009-07-08 14:22:54 +02002849 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002850 err = rdev_del_key(rdev, dev, key.idx,
2851 key.type == NL80211_KEYTYPE_PAIRWISE,
2852 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002853
Johannes Berg3d23e342009-09-29 23:27:28 +02002854#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002855 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002856 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002857 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002858 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002859 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2860 }
2861#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002862 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002863
Johannes Berg41ade002007-12-19 02:03:29 +01002864 return err;
2865}
2866
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302867/* This function returns an error or the number of nested attributes */
2868static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2869{
2870 struct nlattr *attr;
2871 int n_entries = 0, tmp;
2872
2873 nla_for_each_nested(attr, nl_attr, tmp) {
2874 if (nla_len(attr) != ETH_ALEN)
2875 return -EINVAL;
2876
2877 n_entries++;
2878 }
2879
2880 return n_entries;
2881}
2882
2883/*
2884 * This function parses ACL information and allocates memory for ACL data.
2885 * On successful return, the calling function is responsible to free the
2886 * ACL buffer returned by this function.
2887 */
2888static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2889 struct genl_info *info)
2890{
2891 enum nl80211_acl_policy acl_policy;
2892 struct nlattr *attr;
2893 struct cfg80211_acl_data *acl;
2894 int i = 0, n_entries, tmp;
2895
2896 if (!wiphy->max_acl_mac_addrs)
2897 return ERR_PTR(-EOPNOTSUPP);
2898
2899 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2900 return ERR_PTR(-EINVAL);
2901
2902 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2903 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2904 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2905 return ERR_PTR(-EINVAL);
2906
2907 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2908 return ERR_PTR(-EINVAL);
2909
2910 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2911 if (n_entries < 0)
2912 return ERR_PTR(n_entries);
2913
2914 if (n_entries > wiphy->max_acl_mac_addrs)
2915 return ERR_PTR(-ENOTSUPP);
2916
2917 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2918 GFP_KERNEL);
2919 if (!acl)
2920 return ERR_PTR(-ENOMEM);
2921
2922 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2923 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2924 i++;
2925 }
2926
2927 acl->n_acl_entries = n_entries;
2928 acl->acl_policy = acl_policy;
2929
2930 return acl;
2931}
2932
2933static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2934{
2935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2936 struct net_device *dev = info->user_ptr[1];
2937 struct cfg80211_acl_data *acl;
2938 int err;
2939
2940 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2941 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2942 return -EOPNOTSUPP;
2943
2944 if (!dev->ieee80211_ptr->beacon_interval)
2945 return -EINVAL;
2946
2947 acl = parse_acl_data(&rdev->wiphy, info);
2948 if (IS_ERR(acl))
2949 return PTR_ERR(acl);
2950
2951 err = rdev_set_mac_acl(rdev, dev, acl);
2952
2953 kfree(acl);
2954
2955 return err;
2956}
2957
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002958static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01002959 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01002960{
Johannes Berg88600202012-02-13 15:17:18 +01002961 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002962
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002963 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
2964 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
2965 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
2966 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002967 return -EINVAL;
2968
Johannes Berg88600202012-02-13 15:17:18 +01002969 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01002970
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002971 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
2972 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
2973 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01002974 if (!bcn->head_len)
2975 return -EINVAL;
2976 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002977 }
2978
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002979 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
2980 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
2981 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01002982 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002983 }
2984
Johannes Berg4c476992010-10-04 21:36:35 +02002985 if (!haveinfo)
2986 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01002987
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002988 if (attrs[NL80211_ATTR_IE]) {
2989 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
2990 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002991 }
2992
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002993 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01002994 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002995 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01002996 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02002997 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03002998 }
2999
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003000 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003001 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003002 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003003 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003004 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003005 }
3006
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003007 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3008 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3009 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003010 }
3011
Johannes Berg88600202012-02-13 15:17:18 +01003012 return 0;
3013}
3014
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003015static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3016 struct cfg80211_ap_settings *params)
3017{
3018 struct wireless_dev *wdev;
3019 bool ret = false;
3020
Johannes Berg89a54e42012-06-15 14:33:17 +02003021 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003022 if (wdev->iftype != NL80211_IFTYPE_AP &&
3023 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3024 continue;
3025
Johannes Berg683b6d32012-11-08 21:25:48 +01003026 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003027 continue;
3028
Johannes Berg683b6d32012-11-08 21:25:48 +01003029 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003030 ret = true;
3031 break;
3032 }
3033
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003034 return ret;
3035}
3036
Jouni Malinene39e5b52012-09-30 19:29:39 +03003037static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3038 enum nl80211_auth_type auth_type,
3039 enum nl80211_commands cmd)
3040{
3041 if (auth_type > NL80211_AUTHTYPE_MAX)
3042 return false;
3043
3044 switch (cmd) {
3045 case NL80211_CMD_AUTHENTICATE:
3046 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3047 auth_type == NL80211_AUTHTYPE_SAE)
3048 return false;
3049 return true;
3050 case NL80211_CMD_CONNECT:
3051 case NL80211_CMD_START_AP:
3052 /* SAE not supported yet */
3053 if (auth_type == NL80211_AUTHTYPE_SAE)
3054 return false;
3055 return true;
3056 default:
3057 return false;
3058 }
3059}
3060
Johannes Berg88600202012-02-13 15:17:18 +01003061static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3062{
3063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3064 struct net_device *dev = info->user_ptr[1];
3065 struct wireless_dev *wdev = dev->ieee80211_ptr;
3066 struct cfg80211_ap_settings params;
3067 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003068 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003069
3070 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3071 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3072 return -EOPNOTSUPP;
3073
3074 if (!rdev->ops->start_ap)
3075 return -EOPNOTSUPP;
3076
3077 if (wdev->beacon_interval)
3078 return -EALREADY;
3079
3080 memset(&params, 0, sizeof(params));
3081
3082 /* these are required for START_AP */
3083 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3084 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3085 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3086 return -EINVAL;
3087
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003088 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003089 if (err)
3090 return err;
3091
3092 params.beacon_interval =
3093 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3094 params.dtim_period =
3095 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3096
3097 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3098 if (err)
3099 return err;
3100
3101 /*
3102 * In theory, some of these attributes should be required here
3103 * but since they were not used when the command was originally
3104 * added, keep them optional for old user space programs to let
3105 * them continue to work with drivers that do not need the
3106 * additional information -- drivers must check!
3107 */
3108 if (info->attrs[NL80211_ATTR_SSID]) {
3109 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3110 params.ssid_len =
3111 nla_len(info->attrs[NL80211_ATTR_SSID]);
3112 if (params.ssid_len == 0 ||
3113 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3114 return -EINVAL;
3115 }
3116
3117 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3118 params.hidden_ssid = nla_get_u32(
3119 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3120 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3121 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3122 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3123 return -EINVAL;
3124 }
3125
3126 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3127
3128 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3129 params.auth_type = nla_get_u32(
3130 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003131 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3132 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003133 return -EINVAL;
3134 } else
3135 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3136
3137 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3138 NL80211_MAX_NR_CIPHER_SUITES);
3139 if (err)
3140 return err;
3141
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303142 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3143 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3144 return -EOPNOTSUPP;
3145 params.inactivity_timeout = nla_get_u16(
3146 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3147 }
3148
Johannes Berg53cabad2012-11-14 15:17:28 +01003149 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3151 return -EINVAL;
3152 params.p2p_ctwindow =
3153 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3154 if (params.p2p_ctwindow > 127)
3155 return -EINVAL;
3156 if (params.p2p_ctwindow != 0 &&
3157 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3158 return -EINVAL;
3159 }
3160
3161 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3162 u8 tmp;
3163
3164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3165 return -EINVAL;
3166 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3167 if (tmp > 1)
3168 return -EINVAL;
3169 params.p2p_opp_ps = tmp;
3170 if (params.p2p_opp_ps != 0 &&
3171 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3172 return -EINVAL;
3173 }
3174
Johannes Bergaa430da2012-05-16 23:50:18 +02003175 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003176 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3177 if (err)
3178 return err;
3179 } else if (wdev->preset_chandef.chan) {
3180 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003181 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003182 return -EINVAL;
3183
Johannes Berg683b6d32012-11-08 21:25:48 +01003184 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003185 return -EINVAL;
3186
Simon Wunderlich04f39042013-02-08 18:16:19 +01003187 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3188 if (err < 0)
3189 return err;
3190 if (err) {
3191 radar_detect_width = BIT(params.chandef.width);
3192 params.radar_required = true;
3193 }
3194
Simon Wunderlich04f39042013-02-08 18:16:19 +01003195 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3196 params.chandef.chan,
3197 CHAN_MODE_SHARED,
3198 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003199 if (err)
3200 return err;
3201
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303202 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3203 params.acl = parse_acl_data(&rdev->wiphy, info);
3204 if (IS_ERR(params.acl))
3205 return PTR_ERR(params.acl);
3206 }
3207
Hila Gonene35e4d22012-06-27 17:19:42 +03003208 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003209 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003210 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003211 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003212 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003213 wdev->ssid_len = params.ssid_len;
3214 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003215 }
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303216
3217 kfree(params.acl);
3218
Johannes Berg56d18932011-05-09 18:41:15 +02003219 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003220}
3221
Johannes Berg88600202012-02-13 15:17:18 +01003222static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3223{
3224 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3225 struct net_device *dev = info->user_ptr[1];
3226 struct wireless_dev *wdev = dev->ieee80211_ptr;
3227 struct cfg80211_beacon_data params;
3228 int err;
3229
3230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3231 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3232 return -EOPNOTSUPP;
3233
3234 if (!rdev->ops->change_beacon)
3235 return -EOPNOTSUPP;
3236
3237 if (!wdev->beacon_interval)
3238 return -EINVAL;
3239
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003240 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003241 if (err)
3242 return err;
3243
Hila Gonene35e4d22012-06-27 17:19:42 +03003244 return rdev_change_beacon(rdev, dev, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003245}
3246
3247static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003248{
Johannes Berg4c476992010-10-04 21:36:35 +02003249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3250 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003251
Michal Kazior60771782012-06-29 12:46:56 +02003252 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003253}
3254
Johannes Berg5727ef12007-12-19 02:03:34 +01003255static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3256 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3257 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3258 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003259 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003260 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003261 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003262};
3263
Johannes Bergeccb8e82009-05-11 21:57:56 +03003264static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003265 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003266 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003267{
3268 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003269 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003270 int flag;
3271
Johannes Bergeccb8e82009-05-11 21:57:56 +03003272 /*
3273 * Try parsing the new attribute first so userspace
3274 * can specify both for older kernels.
3275 */
3276 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3277 if (nla) {
3278 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003279
Johannes Bergeccb8e82009-05-11 21:57:56 +03003280 sta_flags = nla_data(nla);
3281 params->sta_flags_mask = sta_flags->mask;
3282 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003283 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003284 if ((params->sta_flags_mask |
3285 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3286 return -EINVAL;
3287 return 0;
3288 }
3289
3290 /* if present, parse the old attribute */
3291
3292 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003293 if (!nla)
3294 return 0;
3295
3296 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3297 nla, sta_flags_policy))
3298 return -EINVAL;
3299
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003300 /*
3301 * Only allow certain flags for interface types so that
3302 * other attributes are silently ignored. Remember that
3303 * this is backward compatibility code with old userspace
3304 * and shouldn't be hit in other cases anyway.
3305 */
3306 switch (iftype) {
3307 case NL80211_IFTYPE_AP:
3308 case NL80211_IFTYPE_AP_VLAN:
3309 case NL80211_IFTYPE_P2P_GO:
3310 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3311 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3312 BIT(NL80211_STA_FLAG_WME) |
3313 BIT(NL80211_STA_FLAG_MFP);
3314 break;
3315 case NL80211_IFTYPE_P2P_CLIENT:
3316 case NL80211_IFTYPE_STATION:
3317 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3318 BIT(NL80211_STA_FLAG_TDLS_PEER);
3319 break;
3320 case NL80211_IFTYPE_MESH_POINT:
3321 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3322 BIT(NL80211_STA_FLAG_MFP) |
3323 BIT(NL80211_STA_FLAG_AUTHORIZED);
3324 default:
3325 return -EINVAL;
3326 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003327
Johannes Berg3383b5a2012-05-10 20:14:43 +02003328 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3329 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003330 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003331
Johannes Berg3383b5a2012-05-10 20:14:43 +02003332 /* no longer support new API additions in old API */
3333 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3334 return -EINVAL;
3335 }
3336 }
3337
Johannes Berg5727ef12007-12-19 02:03:34 +01003338 return 0;
3339}
3340
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003341static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3342 int attr)
3343{
3344 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003345 u32 bitrate;
3346 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003347
3348 rate = nla_nest_start(msg, attr);
3349 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003350 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003351
3352 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3353 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003354 /* report 16-bit bitrate only if we can */
3355 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003356 if (bitrate > 0 &&
3357 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3358 return false;
3359 if (bitrate_compat > 0 &&
3360 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3361 return false;
3362
3363 if (info->flags & RATE_INFO_FLAGS_MCS) {
3364 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3365 return false;
3366 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3367 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3368 return false;
3369 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3370 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3371 return false;
3372 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3373 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3374 return false;
3375 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3376 return false;
3377 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3378 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3379 return false;
3380 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3381 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3382 return false;
3383 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3384 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3385 return false;
3386 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3387 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3388 return false;
3389 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3390 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3391 return false;
3392 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003393
3394 nla_nest_end(msg, rate);
3395 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003396}
3397
Felix Fietkau119363c2013-04-22 16:29:30 +02003398static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3399 int id)
3400{
3401 void *attr;
3402 int i = 0;
3403
3404 if (!mask)
3405 return true;
3406
3407 attr = nla_nest_start(msg, id);
3408 if (!attr)
3409 return false;
3410
3411 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3412 if (!(mask & BIT(i)))
3413 continue;
3414
3415 if (nla_put_u8(msg, i, signal[i]))
3416 return false;
3417 }
3418
3419 nla_nest_end(msg, attr);
3420
3421 return true;
3422}
3423
Eric W. Biederman15e47302012-09-07 20:12:54 +00003424static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003425 int flags,
3426 struct cfg80211_registered_device *rdev,
3427 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003428 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003429{
3430 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003431 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003432
Eric W. Biederman15e47302012-09-07 20:12:54 +00003433 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003434 if (!hdr)
3435 return -1;
3436
David S. Miller9360ffd2012-03-29 04:41:26 -04003437 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3438 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3439 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3440 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003441
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003442 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3443 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003444 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003445 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3446 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3447 sinfo->connected_time))
3448 goto nla_put_failure;
3449 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3450 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3451 sinfo->inactive_time))
3452 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003453 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3454 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003455 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003456 (u32)sinfo->rx_bytes))
3457 goto nla_put_failure;
3458 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003459 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003460 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3461 (u32)sinfo->tx_bytes))
3462 goto nla_put_failure;
3463 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3464 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003465 sinfo->rx_bytes))
3466 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003467 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3468 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003469 sinfo->tx_bytes))
3470 goto nla_put_failure;
3471 if ((sinfo->filled & STATION_INFO_LLID) &&
3472 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3473 goto nla_put_failure;
3474 if ((sinfo->filled & STATION_INFO_PLID) &&
3475 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3476 goto nla_put_failure;
3477 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3478 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3479 sinfo->plink_state))
3480 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003481 switch (rdev->wiphy.signal_type) {
3482 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003483 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3484 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3485 sinfo->signal))
3486 goto nla_put_failure;
3487 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3488 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3489 sinfo->signal_avg))
3490 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003491 break;
3492 default:
3493 break;
3494 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003495 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3496 if (!nl80211_put_signal(msg, sinfo->chains,
3497 sinfo->chain_signal,
3498 NL80211_STA_INFO_CHAIN_SIGNAL))
3499 goto nla_put_failure;
3500 }
3501 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3502 if (!nl80211_put_signal(msg, sinfo->chains,
3503 sinfo->chain_signal_avg,
3504 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3505 goto nla_put_failure;
3506 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003507 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003508 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3509 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003510 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003511 }
3512 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3513 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3514 NL80211_STA_INFO_RX_BITRATE))
3515 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003516 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003517 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3518 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3519 sinfo->rx_packets))
3520 goto nla_put_failure;
3521 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3522 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3523 sinfo->tx_packets))
3524 goto nla_put_failure;
3525 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3526 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3527 sinfo->tx_retries))
3528 goto nla_put_failure;
3529 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3530 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3531 sinfo->tx_failed))
3532 goto nla_put_failure;
3533 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3534 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3535 sinfo->beacon_loss_count))
3536 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003537 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3538 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3539 sinfo->local_pm))
3540 goto nla_put_failure;
3541 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3542 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3543 sinfo->peer_pm))
3544 goto nla_put_failure;
3545 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3546 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3547 sinfo->nonpeer_pm))
3548 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003549 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3550 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3551 if (!bss_param)
3552 goto nla_put_failure;
3553
David S. Miller9360ffd2012-03-29 04:41:26 -04003554 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3555 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3556 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3557 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3558 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3559 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3560 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3561 sinfo->bss_param.dtim_period) ||
3562 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3563 sinfo->bss_param.beacon_interval))
3564 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003565
3566 nla_nest_end(msg, bss_param);
3567 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003568 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3569 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3570 sizeof(struct nl80211_sta_flag_update),
3571 &sinfo->sta_flags))
3572 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003573 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3574 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3575 sinfo->t_offset))
3576 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003577 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003578
David S. Miller9360ffd2012-03-29 04:41:26 -04003579 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3580 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3581 sinfo->assoc_req_ies))
3582 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003583
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584 return genlmsg_end(msg, hdr);
3585
3586 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003587 genlmsg_cancel(msg, hdr);
3588 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003589}
3590
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003591static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003592 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003593{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003594 struct station_info sinfo;
3595 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003596 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003597 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003598 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003599 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003600
Johannes Berg97990a02013-04-19 01:02:55 +02003601 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003602 if (err)
3603 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003604
Johannes Berg97990a02013-04-19 01:02:55 +02003605 if (!wdev->netdev) {
3606 err = -EINVAL;
3607 goto out_err;
3608 }
3609
Johannes Bergbba95fe2008-07-29 13:22:51 +02003610 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003611 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003612 goto out_err;
3613 }
3614
Johannes Bergbba95fe2008-07-29 13:22:51 +02003615 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003616 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003617 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003618 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003619 if (err == -ENOENT)
3620 break;
3621 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003622 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003623
3624 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003625 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003626 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003627 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003628 &sinfo) < 0)
3629 goto out;
3630
3631 sta_idx++;
3632 }
3633
3634
3635 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003636 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003637 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003638 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003639 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003640
3641 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003642}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003643
Johannes Berg5727ef12007-12-19 02:03:34 +01003644static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3645{
Johannes Berg4c476992010-10-04 21:36:35 +02003646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3647 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003648 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003649 struct sk_buff *msg;
3650 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003651 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003652
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003653 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003654
3655 if (!info->attrs[NL80211_ATTR_MAC])
3656 return -EINVAL;
3657
3658 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3659
Johannes Berg4c476992010-10-04 21:36:35 +02003660 if (!rdev->ops->get_station)
3661 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003662
Hila Gonene35e4d22012-06-27 17:19:42 +03003663 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003664 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003665 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003666
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003668 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003669 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003670
Eric W. Biederman15e47302012-09-07 20:12:54 +00003671 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003672 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003673 nlmsg_free(msg);
3674 return -ENOBUFS;
3675 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003676
Johannes Berg4c476992010-10-04 21:36:35 +02003677 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003678}
3679
Johannes Berg77ee7c82013-02-15 00:48:33 +01003680int cfg80211_check_station_change(struct wiphy *wiphy,
3681 struct station_parameters *params,
3682 enum cfg80211_station_type statype)
3683{
3684 if (params->listen_interval != -1)
3685 return -EINVAL;
3686 if (params->aid)
3687 return -EINVAL;
3688
3689 /* When you run into this, adjust the code below for the new flag */
3690 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3691
3692 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003693 case CFG80211_STA_MESH_PEER_KERNEL:
3694 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003695 /*
3696 * No ignoring the TDLS flag here -- the userspace mesh
3697 * code doesn't have the bug of including TDLS in the
3698 * mask everywhere.
3699 */
3700 if (params->sta_flags_mask &
3701 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3702 BIT(NL80211_STA_FLAG_MFP) |
3703 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3704 return -EINVAL;
3705 break;
3706 case CFG80211_STA_TDLS_PEER_SETUP:
3707 case CFG80211_STA_TDLS_PEER_ACTIVE:
3708 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3709 return -EINVAL;
3710 /* ignore since it can't change */
3711 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3712 break;
3713 default:
3714 /* disallow mesh-specific things */
3715 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3716 return -EINVAL;
3717 if (params->local_pm)
3718 return -EINVAL;
3719 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3720 return -EINVAL;
3721 }
3722
3723 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3724 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3725 /* TDLS can't be set, ... */
3726 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3727 return -EINVAL;
3728 /*
3729 * ... but don't bother the driver with it. This works around
3730 * a hostapd/wpa_supplicant issue -- it always includes the
3731 * TLDS_PEER flag in the mask even for AP mode.
3732 */
3733 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3734 }
3735
3736 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3737 /* reject other things that can't change */
3738 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3739 return -EINVAL;
3740 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3741 return -EINVAL;
3742 if (params->supported_rates)
3743 return -EINVAL;
3744 if (params->ext_capab || params->ht_capa || params->vht_capa)
3745 return -EINVAL;
3746 }
3747
3748 if (statype != CFG80211_STA_AP_CLIENT) {
3749 if (params->vlan)
3750 return -EINVAL;
3751 }
3752
3753 switch (statype) {
3754 case CFG80211_STA_AP_MLME_CLIENT:
3755 /* Use this only for authorizing/unauthorizing a station */
3756 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3757 return -EOPNOTSUPP;
3758 break;
3759 case CFG80211_STA_AP_CLIENT:
3760 /* accept only the listed bits */
3761 if (params->sta_flags_mask &
3762 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3763 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3764 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3765 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3766 BIT(NL80211_STA_FLAG_WME) |
3767 BIT(NL80211_STA_FLAG_MFP)))
3768 return -EINVAL;
3769
3770 /* but authenticated/associated only if driver handles it */
3771 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3772 params->sta_flags_mask &
3773 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3774 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3775 return -EINVAL;
3776 break;
3777 case CFG80211_STA_IBSS:
3778 case CFG80211_STA_AP_STA:
3779 /* reject any changes other than AUTHORIZED */
3780 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3781 return -EINVAL;
3782 break;
3783 case CFG80211_STA_TDLS_PEER_SETUP:
3784 /* reject any changes other than AUTHORIZED or WME */
3785 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3786 BIT(NL80211_STA_FLAG_WME)))
3787 return -EINVAL;
3788 /* force (at least) rates when authorizing */
3789 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3790 !params->supported_rates)
3791 return -EINVAL;
3792 break;
3793 case CFG80211_STA_TDLS_PEER_ACTIVE:
3794 /* reject any changes */
3795 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003796 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003797 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3798 return -EINVAL;
3799 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003800 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003801 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3802 return -EINVAL;
3803 break;
3804 }
3805
3806 return 0;
3807}
3808EXPORT_SYMBOL(cfg80211_check_station_change);
3809
Johannes Berg5727ef12007-12-19 02:03:34 +01003810/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003811 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003812 */
Johannes Berg80b99892011-11-18 16:23:01 +01003813static struct net_device *get_vlan(struct genl_info *info,
3814 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003815{
Johannes Berg463d0182009-07-14 00:33:35 +02003816 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003817 struct net_device *v;
3818 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003819
Johannes Berg80b99892011-11-18 16:23:01 +01003820 if (!vlanattr)
3821 return NULL;
3822
3823 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3824 if (!v)
3825 return ERR_PTR(-ENODEV);
3826
3827 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3828 ret = -EINVAL;
3829 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003830 }
Johannes Berg80b99892011-11-18 16:23:01 +01003831
Johannes Berg77ee7c82013-02-15 00:48:33 +01003832 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3833 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3834 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3835 ret = -EINVAL;
3836 goto error;
3837 }
3838
Johannes Berg80b99892011-11-18 16:23:01 +01003839 if (!netif_running(v)) {
3840 ret = -ENETDOWN;
3841 goto error;
3842 }
3843
3844 return v;
3845 error:
3846 dev_put(v);
3847 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003848}
3849
Jouni Malinendf881292013-02-14 21:10:54 +02003850static struct nla_policy
3851nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3852 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3853 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3854};
3855
Johannes Bergff276692013-02-15 00:09:01 +01003856static int nl80211_parse_sta_wme(struct genl_info *info,
3857 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003858{
Jouni Malinendf881292013-02-14 21:10:54 +02003859 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3860 struct nlattr *nla;
3861 int err;
3862
Jouni Malinendf881292013-02-14 21:10:54 +02003863 /* parse WME attributes if present */
3864 if (!info->attrs[NL80211_ATTR_STA_WME])
3865 return 0;
3866
3867 nla = info->attrs[NL80211_ATTR_STA_WME];
3868 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3869 nl80211_sta_wme_policy);
3870 if (err)
3871 return err;
3872
3873 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3874 params->uapsd_queues = nla_get_u8(
3875 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3876 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3877 return -EINVAL;
3878
3879 if (tb[NL80211_STA_WME_MAX_SP])
3880 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3881
3882 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3883 return -EINVAL;
3884
3885 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3886
3887 return 0;
3888}
3889
Johannes Bergff276692013-02-15 00:09:01 +01003890static int nl80211_set_station_tdls(struct genl_info *info,
3891 struct station_parameters *params)
3892{
3893 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003894 if (info->attrs[NL80211_ATTR_PEER_AID])
3895 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003896 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3897 params->ht_capa =
3898 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3899 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3900 params->vht_capa =
3901 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3902
3903 return nl80211_parse_sta_wme(info, params);
3904}
3905
Johannes Berg5727ef12007-12-19 02:03:34 +01003906static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
3907{
Johannes Berg4c476992010-10-04 21:36:35 +02003908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02003909 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01003910 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003911 u8 *mac_addr;
3912 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01003913
3914 memset(&params, 0, sizeof(params));
3915
3916 params.listen_interval = -1;
3917
Johannes Berg77ee7c82013-02-15 00:48:33 +01003918 if (!rdev->ops->change_station)
3919 return -EOPNOTSUPP;
3920
Johannes Berg5727ef12007-12-19 02:03:34 +01003921 if (info->attrs[NL80211_ATTR_STA_AID])
3922 return -EINVAL;
3923
3924 if (!info->attrs[NL80211_ATTR_MAC])
3925 return -EINVAL;
3926
3927 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3928
3929 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
3930 params.supported_rates =
3931 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3932 params.supported_rates_len =
3933 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
3934 }
3935
Jouni Malinen9d62a982013-02-14 21:10:13 +02003936 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
3937 params.capability =
3938 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
3939 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
3940 }
3941
3942 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
3943 params.ext_capab =
3944 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3945 params.ext_capab_len =
3946 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
3947 }
3948
Jouni Malinendf881292013-02-14 21:10:54 +02003949 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01003950 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03003951
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003952 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01003953 return -EINVAL;
3954
Johannes Bergf8bacc22013-02-14 23:27:01 +01003955 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003956 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003957 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
3958 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
3959 return -EINVAL;
3960 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003961
Johannes Bergf8bacc22013-02-14 23:27:01 +01003962 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07003963 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01003964 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
3965 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
3966 return -EINVAL;
3967 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
3968 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07003969
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003970 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
3971 enum nl80211_mesh_power_mode pm = nla_get_u32(
3972 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
3973
3974 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
3975 pm > NL80211_MESH_POWER_MAX)
3976 return -EINVAL;
3977
3978 params.local_pm = pm;
3979 }
3980
Johannes Berg77ee7c82013-02-15 00:48:33 +01003981 /* Include parameters for TDLS peer (will check later) */
3982 err = nl80211_set_station_tdls(info, &params);
3983 if (err)
3984 return err;
3985
3986 params.vlan = get_vlan(info, rdev);
3987 if (IS_ERR(params.vlan))
3988 return PTR_ERR(params.vlan);
3989
Johannes Berga97f4422009-06-18 17:23:43 +02003990 switch (dev->ieee80211_ptr->iftype) {
3991 case NL80211_IFTYPE_AP:
3992 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003993 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02003994 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02003995 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01003996 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02003997 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02003998 break;
3999 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004000 err = -EOPNOTSUPP;
4001 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004002 }
4003
Johannes Berg77ee7c82013-02-15 00:48:33 +01004004 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004005 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004006
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004008 if (params.vlan)
4009 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004010
Johannes Berg5727ef12007-12-19 02:03:34 +01004011 return err;
4012}
4013
4014static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4015{
Johannes Berg4c476992010-10-04 21:36:35 +02004016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004017 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004018 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004019 struct station_parameters params;
4020 u8 *mac_addr = NULL;
4021
4022 memset(&params, 0, sizeof(params));
4023
Johannes Berg984c3112013-02-14 23:43:25 +01004024 if (!rdev->ops->add_station)
4025 return -EOPNOTSUPP;
4026
Johannes Berg5727ef12007-12-19 02:03:34 +01004027 if (!info->attrs[NL80211_ATTR_MAC])
4028 return -EINVAL;
4029
Johannes Berg5727ef12007-12-19 02:03:34 +01004030 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4031 return -EINVAL;
4032
4033 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4034 return -EINVAL;
4035
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004036 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4037 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004038 return -EINVAL;
4039
Johannes Berg5727ef12007-12-19 02:03:34 +01004040 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4041 params.supported_rates =
4042 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4043 params.supported_rates_len =
4044 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4045 params.listen_interval =
4046 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004047
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004048 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004049 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004050 else
4051 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004052 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4053 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004054
Jouni Malinen9d62a982013-02-14 21:10:13 +02004055 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4056 params.capability =
4057 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4058 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4059 }
4060
4061 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4062 params.ext_capab =
4063 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4064 params.ext_capab_len =
4065 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4066 }
4067
Jouni Malinen36aedc902008-08-25 11:58:58 +03004068 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4069 params.ht_capa =
4070 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004071
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004072 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4073 params.vht_capa =
4074 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4075
Johannes Bergf8bacc22013-02-14 23:27:01 +01004076 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004077 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004078 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4079 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4080 return -EINVAL;
4081 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004082
Johannes Bergff276692013-02-15 00:09:01 +01004083 err = nl80211_parse_sta_wme(info, &params);
4084 if (err)
4085 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004086
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004087 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004088 return -EINVAL;
4089
Johannes Berg77ee7c82013-02-15 00:48:33 +01004090 /* When you run into this, adjust the code below for the new flag */
4091 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4092
Johannes Bergbdd90d52011-12-14 12:20:27 +01004093 switch (dev->ieee80211_ptr->iftype) {
4094 case NL80211_IFTYPE_AP:
4095 case NL80211_IFTYPE_AP_VLAN:
4096 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004097 /* ignore WME attributes if iface/sta is not capable */
4098 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4099 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4100 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004101
Johannes Bergbdd90d52011-12-14 12:20:27 +01004102 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004103 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4104 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004105 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004106 /* but don't bother the driver with it */
4107 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004108
Johannes Bergd582cff2012-10-26 17:53:44 +02004109 /* allow authenticated/associated only if driver handles it */
4110 if (!(rdev->wiphy.features &
4111 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4112 params.sta_flags_mask &
4113 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4114 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4115 return -EINVAL;
4116
Johannes Bergbdd90d52011-12-14 12:20:27 +01004117 /* must be last in here for error handling */
4118 params.vlan = get_vlan(info, rdev);
4119 if (IS_ERR(params.vlan))
4120 return PTR_ERR(params.vlan);
4121 break;
4122 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004123 /* ignore uAPSD data */
4124 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4125
Johannes Bergd582cff2012-10-26 17:53:44 +02004126 /* associated is disallowed */
4127 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4128 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004129 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004130 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4131 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004132 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004133 break;
4134 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004135 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004136 /* ignore uAPSD data */
4137 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4138
Johannes Berg77ee7c82013-02-15 00:48:33 +01004139 /* these are disallowed */
4140 if (params.sta_flags_mask &
4141 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4142 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004143 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004144 /* Only TDLS peers can be added */
4145 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4146 return -EINVAL;
4147 /* Can only add if TDLS ... */
4148 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4149 return -EOPNOTSUPP;
4150 /* ... with external setup is supported */
4151 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4152 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004153 /*
4154 * Older wpa_supplicant versions always mark the TDLS peer
4155 * as authorized, but it shouldn't yet be.
4156 */
4157 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004158 break;
4159 default:
4160 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004161 }
4162
Johannes Bergbdd90d52011-12-14 12:20:27 +01004163 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004164
Hila Gonene35e4d22012-06-27 17:19:42 +03004165 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004166
Johannes Berg5727ef12007-12-19 02:03:34 +01004167 if (params.vlan)
4168 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004169 return err;
4170}
4171
4172static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4173{
Johannes Berg4c476992010-10-04 21:36:35 +02004174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4175 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004176 u8 *mac_addr = NULL;
4177
4178 if (info->attrs[NL80211_ATTR_MAC])
4179 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4180
Johannes Berge80cf852009-05-11 14:43:13 +02004181 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004182 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4185 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004186
Johannes Berg4c476992010-10-04 21:36:35 +02004187 if (!rdev->ops->del_station)
4188 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004189
Hila Gonene35e4d22012-06-27 17:19:42 +03004190 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004191}
4192
Eric W. Biederman15e47302012-09-07 20:12:54 +00004193static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004194 int flags, struct net_device *dev,
4195 u8 *dst, u8 *next_hop,
4196 struct mpath_info *pinfo)
4197{
4198 void *hdr;
4199 struct nlattr *pinfoattr;
4200
Eric W. Biederman15e47302012-09-07 20:12:54 +00004201 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004202 if (!hdr)
4203 return -1;
4204
David S. Miller9360ffd2012-03-29 04:41:26 -04004205 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4206 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4207 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4208 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4209 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004210
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004211 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4212 if (!pinfoattr)
4213 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004214 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4215 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4216 pinfo->frame_qlen))
4217 goto nla_put_failure;
4218 if (((pinfo->filled & MPATH_INFO_SN) &&
4219 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4220 ((pinfo->filled & MPATH_INFO_METRIC) &&
4221 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4222 pinfo->metric)) ||
4223 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4224 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4225 pinfo->exptime)) ||
4226 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4227 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4228 pinfo->flags)) ||
4229 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4230 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4231 pinfo->discovery_timeout)) ||
4232 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4233 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4234 pinfo->discovery_retries)))
4235 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004236
4237 nla_nest_end(msg, pinfoattr);
4238
4239 return genlmsg_end(msg, hdr);
4240
4241 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004242 genlmsg_cancel(msg, hdr);
4243 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004244}
4245
4246static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004247 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004248{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004249 struct mpath_info pinfo;
4250 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004251 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004252 u8 dst[ETH_ALEN];
4253 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004254 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004255 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004256
Johannes Berg97990a02013-04-19 01:02:55 +02004257 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004258 if (err)
4259 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004260
4261 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004262 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004263 goto out_err;
4264 }
4265
Johannes Berg97990a02013-04-19 01:02:55 +02004266 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004267 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004268 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004269 }
4270
Johannes Bergbba95fe2008-07-29 13:22:51 +02004271 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004272 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4273 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004274 if (err == -ENOENT)
4275 break;
4276 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004277 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004278
Eric W. Biederman15e47302012-09-07 20:12:54 +00004279 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004280 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004281 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004282 &pinfo) < 0)
4283 goto out;
4284
4285 path_idx++;
4286 }
4287
4288
4289 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004290 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004291 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004292 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004293 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004294 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004295}
4296
4297static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4298{
Johannes Berg4c476992010-10-04 21:36:35 +02004299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004301 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302 struct mpath_info pinfo;
4303 struct sk_buff *msg;
4304 u8 *dst = NULL;
4305 u8 next_hop[ETH_ALEN];
4306
4307 memset(&pinfo, 0, sizeof(pinfo));
4308
4309 if (!info->attrs[NL80211_ATTR_MAC])
4310 return -EINVAL;
4311
4312 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4313
Johannes Berg4c476992010-10-04 21:36:35 +02004314 if (!rdev->ops->get_mpath)
4315 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004316
Johannes Berg4c476992010-10-04 21:36:35 +02004317 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4318 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004319
Hila Gonene35e4d22012-06-27 17:19:42 +03004320 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004321 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004322 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004323
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004325 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004326 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004327
Eric W. Biederman15e47302012-09-07 20:12:54 +00004328 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004329 dev, dst, next_hop, &pinfo) < 0) {
4330 nlmsg_free(msg);
4331 return -ENOBUFS;
4332 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004333
Johannes Berg4c476992010-10-04 21:36:35 +02004334 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004335}
4336
4337static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4338{
Johannes Berg4c476992010-10-04 21:36:35 +02004339 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4340 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004341 u8 *dst = NULL;
4342 u8 *next_hop = NULL;
4343
4344 if (!info->attrs[NL80211_ATTR_MAC])
4345 return -EINVAL;
4346
4347 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4348 return -EINVAL;
4349
4350 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4351 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4352
Johannes Berg4c476992010-10-04 21:36:35 +02004353 if (!rdev->ops->change_mpath)
4354 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004355
Johannes Berg4c476992010-10-04 21:36:35 +02004356 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4357 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358
Hila Gonene35e4d22012-06-27 17:19:42 +03004359 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004360}
Johannes Berg4c476992010-10-04 21:36:35 +02004361
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004362static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4363{
Johannes Berg4c476992010-10-04 21:36:35 +02004364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4365 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004366 u8 *dst = NULL;
4367 u8 *next_hop = NULL;
4368
4369 if (!info->attrs[NL80211_ATTR_MAC])
4370 return -EINVAL;
4371
4372 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4373 return -EINVAL;
4374
4375 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4376 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4377
Johannes Berg4c476992010-10-04 21:36:35 +02004378 if (!rdev->ops->add_mpath)
4379 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004380
Johannes Berg4c476992010-10-04 21:36:35 +02004381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4382 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004383
Hila Gonene35e4d22012-06-27 17:19:42 +03004384 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004385}
4386
4387static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4388{
Johannes Berg4c476992010-10-04 21:36:35 +02004389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4390 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004391 u8 *dst = NULL;
4392
4393 if (info->attrs[NL80211_ATTR_MAC])
4394 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4395
Johannes Berg4c476992010-10-04 21:36:35 +02004396 if (!rdev->ops->del_mpath)
4397 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004398
Hila Gonene35e4d22012-06-27 17:19:42 +03004399 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004400}
4401
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004402static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4403{
Johannes Berg4c476992010-10-04 21:36:35 +02004404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4405 struct net_device *dev = info->user_ptr[1];
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004406 struct bss_parameters params;
4407
4408 memset(&params, 0, sizeof(params));
4409 /* default to not changing parameters */
4410 params.use_cts_prot = -1;
4411 params.use_short_preamble = -1;
4412 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004413 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004414 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004415 params.p2p_ctwindow = -1;
4416 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004417
4418 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4419 params.use_cts_prot =
4420 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4421 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4422 params.use_short_preamble =
4423 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4424 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4425 params.use_short_slot_time =
4426 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004427 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4428 params.basic_rates =
4429 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4430 params.basic_rates_len =
4431 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4432 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004433 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4434 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004435 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4436 params.ht_opmode =
4437 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004438
Johannes Berg53cabad2012-11-14 15:17:28 +01004439 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4440 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4441 return -EINVAL;
4442 params.p2p_ctwindow =
4443 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4444 if (params.p2p_ctwindow < 0)
4445 return -EINVAL;
4446 if (params.p2p_ctwindow != 0 &&
4447 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4448 return -EINVAL;
4449 }
4450
4451 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4452 u8 tmp;
4453
4454 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4455 return -EINVAL;
4456 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4457 if (tmp > 1)
4458 return -EINVAL;
4459 params.p2p_opp_ps = tmp;
4460 if (params.p2p_opp_ps &&
4461 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4462 return -EINVAL;
4463 }
4464
Johannes Berg4c476992010-10-04 21:36:35 +02004465 if (!rdev->ops->change_bss)
4466 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004467
Johannes Berg074ac8d2010-09-16 14:58:22 +02004468 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004469 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4470 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004471
Hila Gonene35e4d22012-06-27 17:19:42 +03004472 return rdev_change_bss(rdev, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004473}
4474
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004475static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004476 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4477 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4478 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4479 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4480 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4481 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4482};
4483
4484static int parse_reg_rule(struct nlattr *tb[],
4485 struct ieee80211_reg_rule *reg_rule)
4486{
4487 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4488 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4489
4490 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4491 return -EINVAL;
4492 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4493 return -EINVAL;
4494 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4495 return -EINVAL;
4496 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4497 return -EINVAL;
4498 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4499 return -EINVAL;
4500
4501 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4502
4503 freq_range->start_freq_khz =
4504 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4505 freq_range->end_freq_khz =
4506 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4507 freq_range->max_bandwidth_khz =
4508 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4509
4510 power_rule->max_eirp =
4511 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4512
4513 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4514 power_rule->max_antenna_gain =
4515 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4516
4517 return 0;
4518}
4519
4520static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4521{
4522 int r;
4523 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004524 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004525
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004526 /*
4527 * You should only get this when cfg80211 hasn't yet initialized
4528 * completely when built-in to the kernel right between the time
4529 * window between nl80211_init() and regulatory_init(), if that is
4530 * even possible.
4531 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004532 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004533 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004534
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004535 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4536 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004537
4538 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4539
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004540 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4541 user_reg_hint_type =
4542 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4543 else
4544 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4545
4546 switch (user_reg_hint_type) {
4547 case NL80211_USER_REG_HINT_USER:
4548 case NL80211_USER_REG_HINT_CELL_BASE:
4549 break;
4550 default:
4551 return -EINVAL;
4552 }
4553
4554 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004555
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004556 return r;
4557}
4558
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004559static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004560 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004561{
Johannes Berg4c476992010-10-04 21:36:35 +02004562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004563 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004564 struct wireless_dev *wdev = dev->ieee80211_ptr;
4565 struct mesh_config cur_params;
4566 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004567 void *hdr;
4568 struct nlattr *pinfoattr;
4569 struct sk_buff *msg;
4570
Johannes Berg29cbe682010-12-03 09:20:44 +01004571 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4572 return -EOPNOTSUPP;
4573
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004574 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004575 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004576
Johannes Berg29cbe682010-12-03 09:20:44 +01004577 wdev_lock(wdev);
4578 /* If not connected, get default parameters */
4579 if (!wdev->mesh_id_len)
4580 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4581 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004582 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004583 wdev_unlock(wdev);
4584
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004585 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004586 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004587
4588 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004590 if (!msg)
4591 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004592 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004593 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004594 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004595 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004596 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004597 if (!pinfoattr)
4598 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004599 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4600 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4601 cur_params.dot11MeshRetryTimeout) ||
4602 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4603 cur_params.dot11MeshConfirmTimeout) ||
4604 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4605 cur_params.dot11MeshHoldingTimeout) ||
4606 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4607 cur_params.dot11MeshMaxPeerLinks) ||
4608 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4609 cur_params.dot11MeshMaxRetries) ||
4610 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4611 cur_params.dot11MeshTTL) ||
4612 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4613 cur_params.element_ttl) ||
4614 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4615 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004616 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4617 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004618 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4619 cur_params.dot11MeshHWMPmaxPREQretries) ||
4620 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4621 cur_params.path_refresh_time) ||
4622 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4623 cur_params.min_discovery_timeout) ||
4624 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4625 cur_params.dot11MeshHWMPactivePathTimeout) ||
4626 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4627 cur_params.dot11MeshHWMPpreqMinInterval) ||
4628 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4629 cur_params.dot11MeshHWMPperrMinInterval) ||
4630 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4631 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4632 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4633 cur_params.dot11MeshHWMPRootMode) ||
4634 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4635 cur_params.dot11MeshHWMPRannInterval) ||
4636 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4637 cur_params.dot11MeshGateAnnouncementProtocol) ||
4638 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4639 cur_params.dot11MeshForwarding) ||
4640 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004641 cur_params.rssi_threshold) ||
4642 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004643 cur_params.ht_opmode) ||
4644 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4645 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4646 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004647 cur_params.dot11MeshHWMProotInterval) ||
4648 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004649 cur_params.dot11MeshHWMPconfirmationInterval) ||
4650 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4651 cur_params.power_mode) ||
4652 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004653 cur_params.dot11MeshAwakeWindowDuration) ||
4654 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4655 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004656 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004657 nla_nest_end(msg, pinfoattr);
4658 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004659 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004660
Johannes Berg3b858752009-03-12 09:55:09 +01004661 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004662 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004663 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004664 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004665 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004666}
4667
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004668static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004669 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4670 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4671 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4672 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4673 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4674 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004675 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004676 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004677 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004678 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4679 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4680 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4681 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4682 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004683 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004684 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004685 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004686 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004687 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004688 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004689 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4690 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004691 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4692 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004693 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004694 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4695 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004696 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697};
4698
Javier Cardonac80d5452010-12-16 17:37:49 -08004699static const struct nla_policy
4700 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004701 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004702 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4703 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004704 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004705 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004706 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004707 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004708 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004709 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004710};
4711
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004712static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004713 struct mesh_config *cfg,
4714 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004715{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004716 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004717 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004718
Marco Porschea54fba2013-01-07 16:04:48 +01004719#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4720do { \
4721 if (tb[attr]) { \
4722 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4723 return -EINVAL; \
4724 cfg->param = fn(tb[attr]); \
4725 mask |= (1 << (attr - 1)); \
4726 } \
4727} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004728
4729
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004730 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004731 return -EINVAL;
4732 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004733 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004734 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004735 return -EINVAL;
4736
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004737 /* This makes sure that there aren't more than 32 mesh config
4738 * parameters (otherwise our bitfield scheme would not work.) */
4739 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4740
4741 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004742 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004743 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4744 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004745 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004746 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4747 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004748 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004749 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4750 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004751 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004752 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4753 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004754 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004755 mask, NL80211_MESHCONF_MAX_RETRIES,
4756 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004757 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004758 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004759 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004760 mask, NL80211_MESHCONF_ELEMENT_TTL,
4761 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004762 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004763 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4764 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004765 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4766 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004767 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4768 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004769 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004770 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4771 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004772 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004773 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4774 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004775 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004776 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4777 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004778 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4779 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004780 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4781 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004782 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004783 1, 65535, mask,
4784 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004785 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004786 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004787 1, 65535, mask,
4788 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004789 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004791 dot11MeshHWMPnetDiameterTraversalTime,
4792 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004793 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4794 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004795 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4796 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4797 nla_get_u8);
4798 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4799 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004800 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004801 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004802 dot11MeshGateAnnouncementProtocol, 0, 1,
4803 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004804 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004805 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004806 mask, NL80211_MESHCONF_FORWARDING,
4807 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004808 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004809 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
4810 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004811 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004812 mask, NL80211_MESHCONF_HT_OPMODE,
4813 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004814 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004815 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004816 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4817 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004818 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004819 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4820 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004821 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004822 dot11MeshHWMPconfirmationInterval,
4823 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004824 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4825 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004826 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4827 NL80211_MESH_POWER_ACTIVE,
4828 NL80211_MESH_POWER_MAX,
4829 mask, NL80211_MESHCONF_POWER_MODE,
4830 nla_get_u32);
4831 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4832 0, 65535, mask,
4833 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004834 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4835 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4836 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004837 if (mask_out)
4838 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004839
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840 return 0;
4841
4842#undef FILL_IN_MESH_PARAM_IF_SET
4843}
4844
Javier Cardonac80d5452010-12-16 17:37:49 -08004845static int nl80211_parse_mesh_setup(struct genl_info *info,
4846 struct mesh_setup *setup)
4847{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004849 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4850
4851 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4852 return -EINVAL;
4853 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4854 info->attrs[NL80211_ATTR_MESH_SETUP],
4855 nl80211_mesh_setup_params_policy))
4856 return -EINVAL;
4857
Javier Cardonad299a1f2012-03-31 11:31:33 -07004858 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4859 setup->sync_method =
4860 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4861 IEEE80211_SYNC_METHOD_VENDOR :
4862 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4863
Javier Cardonac80d5452010-12-16 17:37:49 -08004864 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4865 setup->path_sel_proto =
4866 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4867 IEEE80211_PATH_PROTOCOL_VENDOR :
4868 IEEE80211_PATH_PROTOCOL_HWMP;
4869
4870 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4871 setup->path_metric =
4872 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4873 IEEE80211_PATH_METRIC_VENDOR :
4874 IEEE80211_PATH_METRIC_AIRTIME;
4875
Javier Cardona581a8b02011-04-07 15:08:27 -07004876
4877 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004878 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004879 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004880 if (!is_valid_ie_attr(ieattr))
4881 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004882 setup->ie = nla_data(ieattr);
4883 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004884 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004885 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4886 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4887 return -EINVAL;
4888 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07004889 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
4890 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004891 if (setup->is_secure)
4892 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08004893
Colleen Twitty6e16d902013-05-08 11:45:59 -07004894 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
4895 if (!setup->user_mpm)
4896 return -EINVAL;
4897 setup->auth_id =
4898 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
4899 }
4900
Javier Cardonac80d5452010-12-16 17:37:49 -08004901 return 0;
4902}
4903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004904static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004905 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004906{
4907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4908 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004909 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004910 struct mesh_config cfg;
4911 u32 mask;
4912 int err;
4913
Johannes Berg29cbe682010-12-03 09:20:44 +01004914 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4915 return -EOPNOTSUPP;
4916
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004917 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004918 return -EOPNOTSUPP;
4919
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004920 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004921 if (err)
4922 return err;
4923
Johannes Berg29cbe682010-12-03 09:20:44 +01004924 wdev_lock(wdev);
4925 if (!wdev->mesh_id_len)
4926 err = -ENOLINK;
4927
4928 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004929 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01004930
4931 wdev_unlock(wdev);
4932
4933 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004934}
4935
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004936static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
4937{
Johannes Berg458f4f92012-12-06 15:47:38 +01004938 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004939 struct sk_buff *msg;
4940 void *hdr = NULL;
4941 struct nlattr *nl_reg_rules;
4942 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004943
4944 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02004945 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004946
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004947 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02004948 if (!msg)
4949 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004950
Eric W. Biederman15e47302012-09-07 20:12:54 +00004951 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004952 NL80211_CMD_GET_REG);
4953 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004954 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004955
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004956 if (reg_last_request_cell_base() &&
4957 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
4958 NL80211_USER_REG_HINT_CELL_BASE))
4959 goto nla_put_failure;
4960
Johannes Berg458f4f92012-12-06 15:47:38 +01004961 rcu_read_lock();
4962 regdom = rcu_dereference(cfg80211_regdomain);
4963
4964 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
4965 (regdom->dfs_region &&
4966 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
4967 goto nla_put_failure_rcu;
4968
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004969 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
4970 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01004971 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004972
Johannes Berg458f4f92012-12-06 15:47:38 +01004973 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004974 struct nlattr *nl_reg_rule;
4975 const struct ieee80211_reg_rule *reg_rule;
4976 const struct ieee80211_freq_range *freq_range;
4977 const struct ieee80211_power_rule *power_rule;
4978
Johannes Berg458f4f92012-12-06 15:47:38 +01004979 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004980 freq_range = &reg_rule->freq_range;
4981 power_rule = &reg_rule->power_rule;
4982
4983 nl_reg_rule = nla_nest_start(msg, i);
4984 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01004985 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08004986
David S. Miller9360ffd2012-03-29 04:41:26 -04004987 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
4988 reg_rule->flags) ||
4989 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
4990 freq_range->start_freq_khz) ||
4991 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
4992 freq_range->end_freq_khz) ||
4993 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
4994 freq_range->max_bandwidth_khz) ||
4995 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
4996 power_rule->max_antenna_gain) ||
4997 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
4998 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01004999 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005000
5001 nla_nest_end(msg, nl_reg_rule);
5002 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005003 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005004
5005 nla_nest_end(msg, nl_reg_rules);
5006
5007 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005008 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005009
Johannes Berg458f4f92012-12-06 15:47:38 +01005010nla_put_failure_rcu:
5011 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005012nla_put_failure:
5013 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005014put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005015 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005016 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005017}
5018
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005019static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5020{
5021 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5022 struct nlattr *nl_reg_rule;
5023 char *alpha2 = NULL;
5024 int rem_reg_rules = 0, r = 0;
5025 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005026 u8 dfs_region = 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005027 struct ieee80211_regdomain *rd = NULL;
5028
5029 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5030 return -EINVAL;
5031
5032 if (!info->attrs[NL80211_ATTR_REG_RULES])
5033 return -EINVAL;
5034
5035 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5036
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005037 if (info->attrs[NL80211_ATTR_DFS_REGION])
5038 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5039
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005040 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005041 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005042 num_rules++;
5043 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005044 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005045 }
5046
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005047 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005048 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005049
5050 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005051 if (!rd)
5052 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005053
5054 rd->n_reg_rules = num_rules;
5055 rd->alpha2[0] = alpha2[0];
5056 rd->alpha2[1] = alpha2[1];
5057
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005058 /*
5059 * Disable DFS master mode if the DFS region was
5060 * not supported or known on this kernel.
5061 */
5062 if (reg_supported_dfs_region(dfs_region))
5063 rd->dfs_region = dfs_region;
5064
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005065 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005066 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005067 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005068 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5069 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005070 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5071 if (r)
5072 goto bad_reg;
5073
5074 rule_idx++;
5075
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005076 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5077 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005078 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005079 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005080 }
5081
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005082 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005083 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005084 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005085
Johannes Bergd2372b32008-10-24 20:32:20 +02005086 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005087 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005088 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005089}
5090
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005091static int validate_scan_freqs(struct nlattr *freqs)
5092{
5093 struct nlattr *attr1, *attr2;
5094 int n_channels = 0, tmp1, tmp2;
5095
5096 nla_for_each_nested(attr1, freqs, tmp1) {
5097 n_channels++;
5098 /*
5099 * Some hardware has a limited channel list for
5100 * scanning, and it is pretty much nonsensical
5101 * to scan for a channel twice, so disallow that
5102 * and don't require drivers to check that the
5103 * channel list they get isn't longer than what
5104 * they can scan, as long as they can scan all
5105 * the channels they registered at once.
5106 */
5107 nla_for_each_nested(attr2, freqs, tmp2)
5108 if (attr1 != attr2 &&
5109 nla_get_u32(attr1) == nla_get_u32(attr2))
5110 return 0;
5111 }
5112
5113 return n_channels;
5114}
5115
Johannes Berg2a519312009-02-10 21:25:55 +01005116static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5117{
Johannes Berg4c476992010-10-04 21:36:35 +02005118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005119 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005120 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005121 struct nlattr *attr;
5122 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005123 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005124 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005125
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005126 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5127 return -EINVAL;
5128
Johannes Berg79c97e92009-07-07 03:56:12 +02005129 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005130
Johannes Berg4c476992010-10-04 21:36:35 +02005131 if (!rdev->ops->scan)
5132 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005133
Johannes Bergf9f47522013-03-19 15:04:07 +01005134 if (rdev->scan_req) {
5135 err = -EBUSY;
5136 goto unlock;
5137 }
Johannes Berg2a519312009-02-10 21:25:55 +01005138
5139 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005140 n_channels = validate_scan_freqs(
5141 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005142 if (!n_channels) {
5143 err = -EINVAL;
5144 goto unlock;
5145 }
Johannes Berg2a519312009-02-10 21:25:55 +01005146 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005147 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005148 n_channels = 0;
5149
Johannes Berg2a519312009-02-10 21:25:55 +01005150 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5151 if (wiphy->bands[band])
5152 n_channels += wiphy->bands[band]->n_channels;
5153 }
5154
5155 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5156 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5157 n_ssids++;
5158
Johannes Bergf9f47522013-03-19 15:04:07 +01005159 if (n_ssids > wiphy->max_scan_ssids) {
5160 err = -EINVAL;
5161 goto unlock;
5162 }
Johannes Berg2a519312009-02-10 21:25:55 +01005163
Jouni Malinen70692ad2009-02-16 19:39:13 +02005164 if (info->attrs[NL80211_ATTR_IE])
5165 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5166 else
5167 ie_len = 0;
5168
Johannes Bergf9f47522013-03-19 15:04:07 +01005169 if (ie_len > wiphy->max_scan_ie_len) {
5170 err = -EINVAL;
5171 goto unlock;
5172 }
Johannes Berg18a83652009-03-31 12:12:05 +02005173
Johannes Berg2a519312009-02-10 21:25:55 +01005174 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005175 + sizeof(*request->ssids) * n_ssids
5176 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005177 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005178 if (!request) {
5179 err = -ENOMEM;
5180 goto unlock;
5181 }
Johannes Berg2a519312009-02-10 21:25:55 +01005182
Johannes Berg2a519312009-02-10 21:25:55 +01005183 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005184 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005185 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005186 if (ie_len) {
5187 if (request->ssids)
5188 request->ie = (void *)(request->ssids + n_ssids);
5189 else
5190 request->ie = (void *)(request->channels + n_channels);
5191 }
Johannes Berg2a519312009-02-10 21:25:55 +01005192
Johannes Berg584991d2009-11-02 13:32:03 +01005193 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005194 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5195 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005196 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005197 struct ieee80211_channel *chan;
5198
5199 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5200
5201 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005202 err = -EINVAL;
5203 goto out_free;
5204 }
Johannes Berg584991d2009-11-02 13:32:03 +01005205
5206 /* ignore disabled channels */
5207 if (chan->flags & IEEE80211_CHAN_DISABLED)
5208 continue;
5209
5210 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005211 i++;
5212 }
5213 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005214 enum ieee80211_band band;
5215
Johannes Berg2a519312009-02-10 21:25:55 +01005216 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005217 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5218 int j;
5219 if (!wiphy->bands[band])
5220 continue;
5221 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005222 struct ieee80211_channel *chan;
5223
5224 chan = &wiphy->bands[band]->channels[j];
5225
5226 if (chan->flags & IEEE80211_CHAN_DISABLED)
5227 continue;
5228
5229 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005230 i++;
5231 }
5232 }
5233 }
5234
Johannes Berg584991d2009-11-02 13:32:03 +01005235 if (!i) {
5236 err = -EINVAL;
5237 goto out_free;
5238 }
5239
5240 request->n_channels = i;
5241
Johannes Berg2a519312009-02-10 21:25:55 +01005242 i = 0;
5243 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5244 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005245 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005246 err = -EINVAL;
5247 goto out_free;
5248 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005249 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005250 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005251 i++;
5252 }
5253 }
5254
Jouni Malinen70692ad2009-02-16 19:39:13 +02005255 if (info->attrs[NL80211_ATTR_IE]) {
5256 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005257 memcpy((void *)request->ie,
5258 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005259 request->ie_len);
5260 }
5261
Johannes Berg34850ab2011-07-18 18:08:35 +02005262 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005263 if (wiphy->bands[i])
5264 request->rates[i] =
5265 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005266
5267 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5268 nla_for_each_nested(attr,
5269 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5270 tmp) {
5271 enum ieee80211_band band = nla_type(attr);
5272
Dan Carpenter84404622011-07-29 11:52:18 +03005273 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005274 err = -EINVAL;
5275 goto out_free;
5276 }
5277 err = ieee80211_get_ratemask(wiphy->bands[band],
5278 nla_data(attr),
5279 nla_len(attr),
5280 &request->rates[band]);
5281 if (err)
5282 goto out_free;
5283 }
5284 }
5285
Sam Leffler46856bb2012-10-11 21:03:32 -07005286 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005287 request->flags = nla_get_u32(
5288 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005289 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5290 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5291 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5292 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005293 err = -EOPNOTSUPP;
5294 goto out_free;
5295 }
5296 }
Sam Lefflered4737712012-10-11 21:03:31 -07005297
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305298 request->no_cck =
5299 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5300
Johannes Bergfd014282012-06-18 19:17:03 +02005301 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005302 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005303 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005304
Johannes Berg79c97e92009-07-07 03:56:12 +02005305 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005306 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005307
Johannes Berg463d0182009-07-14 00:33:35 +02005308 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005309 nl80211_send_scan_start(rdev, wdev);
5310 if (wdev->netdev)
5311 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005312 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005313 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005314 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005315 kfree(request);
5316 }
Johannes Berg3b858752009-03-12 09:55:09 +01005317
Johannes Bergf9f47522013-03-19 15:04:07 +01005318 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005319 return err;
5320}
5321
Luciano Coelho807f8a82011-05-11 17:09:35 +03005322static int nl80211_start_sched_scan(struct sk_buff *skb,
5323 struct genl_info *info)
5324{
5325 struct cfg80211_sched_scan_request *request;
5326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5327 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005328 struct nlattr *attr;
5329 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005330 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005331 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005332 enum ieee80211_band band;
5333 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005334 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005335
5336 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5337 !rdev->ops->sched_scan_start)
5338 return -EOPNOTSUPP;
5339
5340 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5341 return -EINVAL;
5342
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005343 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5344 return -EINVAL;
5345
5346 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5347 if (interval == 0)
5348 return -EINVAL;
5349
Luciano Coelho807f8a82011-05-11 17:09:35 +03005350 wiphy = &rdev->wiphy;
5351
5352 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5353 n_channels = validate_scan_freqs(
5354 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5355 if (!n_channels)
5356 return -EINVAL;
5357 } else {
5358 n_channels = 0;
5359
5360 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5361 if (wiphy->bands[band])
5362 n_channels += wiphy->bands[band]->n_channels;
5363 }
5364
5365 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5366 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5367 tmp)
5368 n_ssids++;
5369
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005370 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005371 return -EINVAL;
5372
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005373 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5374 nla_for_each_nested(attr,
5375 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5376 tmp)
5377 n_match_sets++;
5378
5379 if (n_match_sets > wiphy->max_match_sets)
5380 return -EINVAL;
5381
Luciano Coelho807f8a82011-05-11 17:09:35 +03005382 if (info->attrs[NL80211_ATTR_IE])
5383 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5384 else
5385 ie_len = 0;
5386
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005387 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005388 return -EINVAL;
5389
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005390 if (rdev->sched_scan_req) {
5391 err = -EINPROGRESS;
5392 goto out;
5393 }
5394
Luciano Coelho807f8a82011-05-11 17:09:35 +03005395 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005396 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005397 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005398 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005399 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005400 if (!request) {
5401 err = -ENOMEM;
5402 goto out;
5403 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005404
5405 if (n_ssids)
5406 request->ssids = (void *)&request->channels[n_channels];
5407 request->n_ssids = n_ssids;
5408 if (ie_len) {
5409 if (request->ssids)
5410 request->ie = (void *)(request->ssids + n_ssids);
5411 else
5412 request->ie = (void *)(request->channels + n_channels);
5413 }
5414
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005415 if (n_match_sets) {
5416 if (request->ie)
5417 request->match_sets = (void *)(request->ie + ie_len);
5418 else if (request->ssids)
5419 request->match_sets =
5420 (void *)(request->ssids + n_ssids);
5421 else
5422 request->match_sets =
5423 (void *)(request->channels + n_channels);
5424 }
5425 request->n_match_sets = n_match_sets;
5426
Luciano Coelho807f8a82011-05-11 17:09:35 +03005427 i = 0;
5428 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5429 /* user specified, bail out if channel not found */
5430 nla_for_each_nested(attr,
5431 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5432 tmp) {
5433 struct ieee80211_channel *chan;
5434
5435 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5436
5437 if (!chan) {
5438 err = -EINVAL;
5439 goto out_free;
5440 }
5441
5442 /* ignore disabled channels */
5443 if (chan->flags & IEEE80211_CHAN_DISABLED)
5444 continue;
5445
5446 request->channels[i] = chan;
5447 i++;
5448 }
5449 } else {
5450 /* all channels */
5451 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5452 int j;
5453 if (!wiphy->bands[band])
5454 continue;
5455 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5456 struct ieee80211_channel *chan;
5457
5458 chan = &wiphy->bands[band]->channels[j];
5459
5460 if (chan->flags & IEEE80211_CHAN_DISABLED)
5461 continue;
5462
5463 request->channels[i] = chan;
5464 i++;
5465 }
5466 }
5467 }
5468
5469 if (!i) {
5470 err = -EINVAL;
5471 goto out_free;
5472 }
5473
5474 request->n_channels = i;
5475
5476 i = 0;
5477 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5478 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5479 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005480 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005481 err = -EINVAL;
5482 goto out_free;
5483 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005484 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005485 memcpy(request->ssids[i].ssid, nla_data(attr),
5486 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005487 i++;
5488 }
5489 }
5490
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005491 i = 0;
5492 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5493 nla_for_each_nested(attr,
5494 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5495 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005496 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005497
5498 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5499 nla_data(attr), nla_len(attr),
5500 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005501 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005502 if (ssid) {
5503 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5504 err = -EINVAL;
5505 goto out_free;
5506 }
5507 memcpy(request->match_sets[i].ssid.ssid,
5508 nla_data(ssid), nla_len(ssid));
5509 request->match_sets[i].ssid.ssid_len =
5510 nla_len(ssid);
5511 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005512 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5513 if (rssi)
5514 request->rssi_thold = nla_get_u32(rssi);
5515 else
5516 request->rssi_thold =
5517 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005518 i++;
5519 }
5520 }
5521
Luciano Coelho807f8a82011-05-11 17:09:35 +03005522 if (info->attrs[NL80211_ATTR_IE]) {
5523 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5524 memcpy((void *)request->ie,
5525 nla_data(info->attrs[NL80211_ATTR_IE]),
5526 request->ie_len);
5527 }
5528
Sam Leffler46856bb2012-10-11 21:03:32 -07005529 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005530 request->flags = nla_get_u32(
5531 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Sam Leffler15d60302012-10-11 21:03:34 -07005532 if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5533 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
5534 ((request->flags & NL80211_SCAN_FLAG_FLUSH) &&
5535 !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005536 err = -EOPNOTSUPP;
5537 goto out_free;
5538 }
5539 }
Sam Lefflered4737712012-10-11 21:03:31 -07005540
Luciano Coelho807f8a82011-05-11 17:09:35 +03005541 request->dev = dev;
5542 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005543 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005544 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005545
Hila Gonene35e4d22012-06-27 17:19:42 +03005546 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005547 if (!err) {
5548 rdev->sched_scan_req = request;
5549 nl80211_send_sched_scan(rdev, dev,
5550 NL80211_CMD_START_SCHED_SCAN);
5551 goto out;
5552 }
5553
5554out_free:
5555 kfree(request);
5556out:
5557 return err;
5558}
5559
5560static int nl80211_stop_sched_scan(struct sk_buff *skb,
5561 struct genl_info *info)
5562{
5563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5564
5565 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5566 !rdev->ops->sched_scan_stop)
5567 return -EOPNOTSUPP;
5568
Johannes Berg5fe231e2013-05-08 21:45:15 +02005569 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005570}
5571
Simon Wunderlich04f39042013-02-08 18:16:19 +01005572static int nl80211_start_radar_detection(struct sk_buff *skb,
5573 struct genl_info *info)
5574{
5575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5576 struct net_device *dev = info->user_ptr[1];
5577 struct wireless_dev *wdev = dev->ieee80211_ptr;
5578 struct cfg80211_chan_def chandef;
5579 int err;
5580
5581 err = nl80211_parse_chandef(rdev, info, &chandef);
5582 if (err)
5583 return err;
5584
5585 if (wdev->cac_started)
5586 return -EBUSY;
5587
5588 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5589 if (err < 0)
5590 return err;
5591
5592 if (err == 0)
5593 return -EINVAL;
5594
5595 if (chandef.chan->dfs_state != NL80211_DFS_USABLE)
5596 return -EINVAL;
5597
5598 if (!rdev->ops->start_radar_detection)
5599 return -EOPNOTSUPP;
5600
Simon Wunderlich04f39042013-02-08 18:16:19 +01005601 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5602 chandef.chan, CHAN_MODE_SHARED,
5603 BIT(chandef.width));
5604 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005605 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005606
5607 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5608 if (!err) {
5609 wdev->channel = chandef.chan;
5610 wdev->cac_started = true;
5611 wdev->cac_start_time = jiffies;
5612 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005613 return err;
5614}
5615
Johannes Berg9720bb32011-06-21 09:45:33 +02005616static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5617 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005618 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005619 struct wireless_dev *wdev,
5620 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005621{
Johannes Berg48ab9052009-07-10 18:42:31 +02005622 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005623 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005624 void *hdr;
5625 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005626 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005627
5628 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005629
Eric W. Biederman15e47302012-09-07 20:12:54 +00005630 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005631 NL80211_CMD_NEW_SCAN_RESULTS);
5632 if (!hdr)
5633 return -1;
5634
Johannes Berg9720bb32011-06-21 09:45:33 +02005635 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5636
Johannes Berg97990a02013-04-19 01:02:55 +02005637 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5638 goto nla_put_failure;
5639 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005640 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5641 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005642 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5643 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005644
5645 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5646 if (!bss)
5647 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005648 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005649 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005650 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005651
5652 rcu_read_lock();
5653 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005654 if (ies) {
5655 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5656 goto fail_unlock_rcu;
5657 tsf = true;
5658 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5659 ies->len, ies->data))
5660 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005661 }
5662 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005663 if (ies) {
5664 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5665 goto fail_unlock_rcu;
5666 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5667 ies->len, ies->data))
5668 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005669 }
5670 rcu_read_unlock();
5671
David S. Miller9360ffd2012-03-29 04:41:26 -04005672 if (res->beacon_interval &&
5673 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5674 goto nla_put_failure;
5675 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5676 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005677 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005678 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5679 jiffies_to_msecs(jiffies - intbss->ts)))
5680 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005681
Johannes Berg77965c92009-02-18 18:45:06 +01005682 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005683 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005684 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5685 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005686 break;
5687 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005688 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5689 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005690 break;
5691 default:
5692 break;
5693 }
5694
Johannes Berg48ab9052009-07-10 18:42:31 +02005695 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005696 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005697 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005698 if (intbss == wdev->current_bss &&
5699 nla_put_u32(msg, NL80211_BSS_STATUS,
5700 NL80211_BSS_STATUS_ASSOCIATED))
5701 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005702 break;
5703 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005704 if (intbss == wdev->current_bss &&
5705 nla_put_u32(msg, NL80211_BSS_STATUS,
5706 NL80211_BSS_STATUS_IBSS_JOINED))
5707 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005708 break;
5709 default:
5710 break;
5711 }
5712
Johannes Berg2a519312009-02-10 21:25:55 +01005713 nla_nest_end(msg, bss);
5714
5715 return genlmsg_end(msg, hdr);
5716
Johannes Berg8cef2c92013-02-05 16:54:31 +01005717 fail_unlock_rcu:
5718 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005719 nla_put_failure:
5720 genlmsg_cancel(msg, hdr);
5721 return -EMSGSIZE;
5722}
5723
Johannes Berg97990a02013-04-19 01:02:55 +02005724static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005725{
Johannes Berg48ab9052009-07-10 18:42:31 +02005726 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005727 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005728 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005729 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005730 int err;
5731
Johannes Berg97990a02013-04-19 01:02:55 +02005732 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005733 if (err)
5734 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005735
Johannes Berg48ab9052009-07-10 18:42:31 +02005736 wdev_lock(wdev);
5737 spin_lock_bh(&rdev->bss_lock);
5738 cfg80211_bss_expire(rdev);
5739
Johannes Berg9720bb32011-06-21 09:45:33 +02005740 cb->seq = rdev->bss_generation;
5741
Johannes Berg48ab9052009-07-10 18:42:31 +02005742 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005743 if (++idx <= start)
5744 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005745 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005746 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005747 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005748 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005749 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005750 }
5751 }
5752
Johannes Berg48ab9052009-07-10 18:42:31 +02005753 spin_unlock_bh(&rdev->bss_lock);
5754 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005755
Johannes Berg97990a02013-04-19 01:02:55 +02005756 cb->args[2] = idx;
5757 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005758
Johannes Berg67748892010-10-04 21:14:06 +02005759 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01005760}
5761
Eric W. Biederman15e47302012-09-07 20:12:54 +00005762static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01005763 int flags, struct net_device *dev,
5764 struct survey_info *survey)
5765{
5766 void *hdr;
5767 struct nlattr *infoattr;
5768
Eric W. Biederman15e47302012-09-07 20:12:54 +00005769 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01005770 NL80211_CMD_NEW_SURVEY_RESULTS);
5771 if (!hdr)
5772 return -ENOMEM;
5773
David S. Miller9360ffd2012-03-29 04:41:26 -04005774 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
5775 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005776
5777 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
5778 if (!infoattr)
5779 goto nla_put_failure;
5780
David S. Miller9360ffd2012-03-29 04:41:26 -04005781 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
5782 survey->channel->center_freq))
5783 goto nla_put_failure;
5784
5785 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
5786 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
5787 goto nla_put_failure;
5788 if ((survey->filled & SURVEY_INFO_IN_USE) &&
5789 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
5790 goto nla_put_failure;
5791 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
5792 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
5793 survey->channel_time))
5794 goto nla_put_failure;
5795 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
5796 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
5797 survey->channel_time_busy))
5798 goto nla_put_failure;
5799 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
5800 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
5801 survey->channel_time_ext_busy))
5802 goto nla_put_failure;
5803 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
5804 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
5805 survey->channel_time_rx))
5806 goto nla_put_failure;
5807 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
5808 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
5809 survey->channel_time_tx))
5810 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01005811
5812 nla_nest_end(msg, infoattr);
5813
5814 return genlmsg_end(msg, hdr);
5815
5816 nla_put_failure:
5817 genlmsg_cancel(msg, hdr);
5818 return -EMSGSIZE;
5819}
5820
5821static int nl80211_dump_survey(struct sk_buff *skb,
5822 struct netlink_callback *cb)
5823{
5824 struct survey_info survey;
5825 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02005826 struct wireless_dev *wdev;
5827 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01005828 int res;
5829
Johannes Berg97990a02013-04-19 01:02:55 +02005830 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005831 if (res)
5832 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01005833
Johannes Berg97990a02013-04-19 01:02:55 +02005834 if (!wdev->netdev) {
5835 res = -EINVAL;
5836 goto out_err;
5837 }
5838
Holger Schurig61fa7132009-11-11 12:25:40 +01005839 if (!dev->ops->dump_survey) {
5840 res = -EOPNOTSUPP;
5841 goto out_err;
5842 }
5843
5844 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005845 struct ieee80211_channel *chan;
5846
Johannes Berg97990a02013-04-19 01:02:55 +02005847 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01005848 if (res == -ENOENT)
5849 break;
5850 if (res)
5851 goto out_err;
5852
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07005853 /* Survey without a channel doesn't make sense */
5854 if (!survey.channel) {
5855 res = -EINVAL;
5856 goto out;
5857 }
5858
5859 chan = ieee80211_get_channel(&dev->wiphy,
5860 survey.channel->center_freq);
5861 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
5862 survey_idx++;
5863 continue;
5864 }
5865
Holger Schurig61fa7132009-11-11 12:25:40 +01005866 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005867 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01005868 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02005869 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01005870 goto out;
5871 survey_idx++;
5872 }
5873
5874 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005875 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01005876 res = skb->len;
5877 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02005878 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01005879 return res;
5880}
5881
Samuel Ortizb23aa672009-07-01 21:26:54 +02005882static bool nl80211_valid_wpa_versions(u32 wpa_versions)
5883{
5884 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
5885 NL80211_WPA_VERSION_2));
5886}
5887
Jouni Malinen636a5d32009-03-19 13:39:22 +02005888static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
5889{
Johannes Berg4c476992010-10-04 21:36:35 +02005890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5891 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02005892 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005893 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
5894 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02005895 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02005896 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005897 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005898
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005899 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5900 return -EINVAL;
5901
5902 if (!info->attrs[NL80211_ATTR_MAC])
5903 return -EINVAL;
5904
Jouni Malinen17780922009-03-27 20:52:47 +02005905 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
5906 return -EINVAL;
5907
Johannes Berg19957bb2009-07-02 17:20:43 +02005908 if (!info->attrs[NL80211_ATTR_SSID])
5909 return -EINVAL;
5910
5911 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
5912 return -EINVAL;
5913
Johannes Bergfffd0932009-07-08 14:22:54 +02005914 err = nl80211_parse_key(info, &key);
5915 if (err)
5916 return err;
5917
5918 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02005919 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
5920 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02005921 if (!key.p.key || !key.p.key_len)
5922 return -EINVAL;
5923 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
5924 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
5925 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
5926 key.p.key_len != WLAN_KEY_LEN_WEP104))
5927 return -EINVAL;
5928 if (key.idx > 4)
5929 return -EINVAL;
5930 } else {
5931 key.p.key_len = 0;
5932 key.p.key = NULL;
5933 }
5934
Johannes Bergafea0b72010-08-10 09:46:42 +02005935 if (key.idx >= 0) {
5936 int i;
5937 bool ok = false;
5938 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
5939 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
5940 ok = true;
5941 break;
5942 }
5943 }
Johannes Berg4c476992010-10-04 21:36:35 +02005944 if (!ok)
5945 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02005946 }
5947
Johannes Berg4c476992010-10-04 21:36:35 +02005948 if (!rdev->ops->auth)
5949 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005950
Johannes Berg074ac8d2010-09-16 14:58:22 +02005951 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02005952 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
5953 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02005954
Johannes Berg19957bb2009-07-02 17:20:43 +02005955 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02005956 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02005957 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02005958 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
5959 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02005960
Johannes Berg19957bb2009-07-02 17:20:43 +02005961 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5962 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
5963
5964 if (info->attrs[NL80211_ATTR_IE]) {
5965 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
5966 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5967 }
5968
5969 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005970 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02005971 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02005972
Jouni Malinene39e5b52012-09-30 19:29:39 +03005973 if (auth_type == NL80211_AUTHTYPE_SAE &&
5974 !info->attrs[NL80211_ATTR_SAE_DATA])
5975 return -EINVAL;
5976
5977 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
5978 if (auth_type != NL80211_AUTHTYPE_SAE)
5979 return -EINVAL;
5980 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
5981 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
5982 /* need to include at least Auth Transaction and Status Code */
5983 if (sae_data_len < 4)
5984 return -EINVAL;
5985 }
5986
Jouni Malinend5cdfac2010-04-04 09:37:19 +03005987 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
5988
Johannes Berg95de8172012-01-20 13:55:25 +01005989 /*
5990 * Since we no longer track auth state, ignore
5991 * requests to only change local state.
5992 */
5993 if (local_state_change)
5994 return 0;
5995
Johannes Berg91bf9b22013-05-15 17:44:01 +02005996 wdev_lock(dev->ieee80211_ptr);
5997 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
5998 ssid, ssid_len, ie, ie_len,
5999 key.p.key, key.p.key_len, key.idx,
6000 sae_data, sae_data_len);
6001 wdev_unlock(dev->ieee80211_ptr);
6002 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006003}
6004
Johannes Bergc0692b82010-08-27 14:26:53 +03006005static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6006 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006007 struct cfg80211_crypto_settings *settings,
6008 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006009{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006010 memset(settings, 0, sizeof(*settings));
6011
Samuel Ortizb23aa672009-07-01 21:26:54 +02006012 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6013
Johannes Bergc0692b82010-08-27 14:26:53 +03006014 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6015 u16 proto;
6016 proto = nla_get_u16(
6017 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6018 settings->control_port_ethertype = cpu_to_be16(proto);
6019 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6020 proto != ETH_P_PAE)
6021 return -EINVAL;
6022 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6023 settings->control_port_no_encrypt = true;
6024 } else
6025 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6026
Samuel Ortizb23aa672009-07-01 21:26:54 +02006027 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6028 void *data;
6029 int len, i;
6030
6031 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6032 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6033 settings->n_ciphers_pairwise = len / sizeof(u32);
6034
6035 if (len % sizeof(u32))
6036 return -EINVAL;
6037
Johannes Berg3dc27d22009-07-02 21:36:37 +02006038 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006039 return -EINVAL;
6040
6041 memcpy(settings->ciphers_pairwise, data, len);
6042
6043 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006044 if (!cfg80211_supported_cipher_suite(
6045 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006046 settings->ciphers_pairwise[i]))
6047 return -EINVAL;
6048 }
6049
6050 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6051 settings->cipher_group =
6052 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006053 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6054 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006055 return -EINVAL;
6056 }
6057
6058 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6059 settings->wpa_versions =
6060 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6061 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6062 return -EINVAL;
6063 }
6064
6065 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6066 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006067 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006068
6069 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6070 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6071 settings->n_akm_suites = len / sizeof(u32);
6072
6073 if (len % sizeof(u32))
6074 return -EINVAL;
6075
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006076 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6077 return -EINVAL;
6078
Samuel Ortizb23aa672009-07-01 21:26:54 +02006079 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006080 }
6081
6082 return 0;
6083}
6084
Jouni Malinen636a5d32009-03-19 13:39:22 +02006085static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6086{
Johannes Berg4c476992010-10-04 21:36:35 +02006087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6088 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006089 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006090 struct cfg80211_assoc_request req = {};
6091 const u8 *bssid, *ssid;
6092 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006093
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006094 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6095 return -EINVAL;
6096
6097 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006098 !info->attrs[NL80211_ATTR_SSID] ||
6099 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006100 return -EINVAL;
6101
Johannes Berg4c476992010-10-04 21:36:35 +02006102 if (!rdev->ops->assoc)
6103 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006104
Johannes Berg074ac8d2010-09-16 14:58:22 +02006105 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006106 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6107 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006108
Johannes Berg19957bb2009-07-02 17:20:43 +02006109 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006110
Johannes Berg19957bb2009-07-02 17:20:43 +02006111 chan = ieee80211_get_channel(&rdev->wiphy,
6112 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006113 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6114 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006115
Johannes Berg19957bb2009-07-02 17:20:43 +02006116 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6117 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006118
6119 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006120 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6121 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006122 }
6123
Jouni Malinendc6382c2009-05-06 22:09:37 +03006124 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006125 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006126 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006127 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006128 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006129 else if (mfp != NL80211_MFP_NO)
6130 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006131 }
6132
Johannes Berg3e5d7642009-07-07 14:37:26 +02006133 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006134 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006135
Ben Greear7e7c8922011-11-18 11:31:59 -08006136 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006137 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006138
6139 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006140 memcpy(&req.ht_capa_mask,
6141 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6142 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006143
6144 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006145 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006146 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006147 memcpy(&req.ht_capa,
6148 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6149 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006150 }
6151
Johannes Bergee2aca32013-02-21 17:36:01 +01006152 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006153 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006154
6155 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006156 memcpy(&req.vht_capa_mask,
6157 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6158 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006159
6160 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006161 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006162 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006163 memcpy(&req.vht_capa,
6164 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6165 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006166 }
6167
Johannes Bergf62fab72013-02-21 20:09:09 +01006168 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006169 if (!err) {
6170 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006171 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6172 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006173 wdev_unlock(dev->ieee80211_ptr);
6174 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006175
Jouni Malinen636a5d32009-03-19 13:39:22 +02006176 return err;
6177}
6178
6179static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6180{
Johannes Berg4c476992010-10-04 21:36:35 +02006181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6182 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006183 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006184 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006185 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006186 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006187
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006188 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6189 return -EINVAL;
6190
6191 if (!info->attrs[NL80211_ATTR_MAC])
6192 return -EINVAL;
6193
6194 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6195 return -EINVAL;
6196
Johannes Berg4c476992010-10-04 21:36:35 +02006197 if (!rdev->ops->deauth)
6198 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006199
Johannes Berg074ac8d2010-09-16 14:58:22 +02006200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6202 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006203
Johannes Berg19957bb2009-07-02 17:20:43 +02006204 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006205
Johannes Berg19957bb2009-07-02 17:20:43 +02006206 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6207 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006208 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006209 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006210 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006211
6212 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006213 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6214 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006215 }
6216
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006217 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6218
Johannes Berg91bf9b22013-05-15 17:44:01 +02006219 wdev_lock(dev->ieee80211_ptr);
6220 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6221 local_state_change);
6222 wdev_unlock(dev->ieee80211_ptr);
6223 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006224}
6225
6226static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6227{
Johannes Berg4c476992010-10-04 21:36:35 +02006228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6229 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006230 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006231 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006232 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006233 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006234
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006235 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6236 return -EINVAL;
6237
6238 if (!info->attrs[NL80211_ATTR_MAC])
6239 return -EINVAL;
6240
6241 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6242 return -EINVAL;
6243
Johannes Berg4c476992010-10-04 21:36:35 +02006244 if (!rdev->ops->disassoc)
6245 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006246
Johannes Berg074ac8d2010-09-16 14:58:22 +02006247 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006248 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6249 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006250
Johannes Berg19957bb2009-07-02 17:20:43 +02006251 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006252
Johannes Berg19957bb2009-07-02 17:20:43 +02006253 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6254 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006255 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006256 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006257 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006258
6259 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006260 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6261 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006262 }
6263
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006264 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6265
Johannes Berg91bf9b22013-05-15 17:44:01 +02006266 wdev_lock(dev->ieee80211_ptr);
6267 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6268 local_state_change);
6269 wdev_unlock(dev->ieee80211_ptr);
6270 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006271}
6272
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006273static bool
6274nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6275 int mcast_rate[IEEE80211_NUM_BANDS],
6276 int rateval)
6277{
6278 struct wiphy *wiphy = &rdev->wiphy;
6279 bool found = false;
6280 int band, i;
6281
6282 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6283 struct ieee80211_supported_band *sband;
6284
6285 sband = wiphy->bands[band];
6286 if (!sband)
6287 continue;
6288
6289 for (i = 0; i < sband->n_bitrates; i++) {
6290 if (sband->bitrates[i].bitrate == rateval) {
6291 mcast_rate[band] = i + 1;
6292 found = true;
6293 break;
6294 }
6295 }
6296 }
6297
6298 return found;
6299}
6300
Johannes Berg04a773a2009-04-19 21:24:32 +02006301static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6302{
Johannes Berg4c476992010-10-04 21:36:35 +02006303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6304 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006305 struct cfg80211_ibss_params ibss;
6306 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006307 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006308 int err;
6309
Johannes Berg8e30bc52009-04-22 17:45:38 +02006310 memset(&ibss, 0, sizeof(ibss));
6311
Johannes Berg04a773a2009-04-19 21:24:32 +02006312 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6313 return -EINVAL;
6314
Johannes Berg683b6d32012-11-08 21:25:48 +01006315 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006316 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6317 return -EINVAL;
6318
Johannes Berg8e30bc52009-04-22 17:45:38 +02006319 ibss.beacon_interval = 100;
6320
6321 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6322 ibss.beacon_interval =
6323 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6324 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6325 return -EINVAL;
6326 }
6327
Johannes Berg4c476992010-10-04 21:36:35 +02006328 if (!rdev->ops->join_ibss)
6329 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006330
Johannes Berg4c476992010-10-04 21:36:35 +02006331 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6332 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006333
Johannes Berg79c97e92009-07-07 03:56:12 +02006334 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006335
Johannes Berg39193492011-09-16 13:45:25 +02006336 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006337 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006338
6339 if (!is_valid_ether_addr(ibss.bssid))
6340 return -EINVAL;
6341 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006342 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6343 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6344
6345 if (info->attrs[NL80211_ATTR_IE]) {
6346 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6347 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6348 }
6349
Johannes Berg683b6d32012-11-08 21:25:48 +01006350 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6351 if (err)
6352 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006353
Johannes Berg683b6d32012-11-08 21:25:48 +01006354 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006355 return -EINVAL;
6356
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006357 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006358 case NL80211_CHAN_WIDTH_5:
6359 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006360 case NL80211_CHAN_WIDTH_20_NOHT:
6361 break;
6362 case NL80211_CHAN_WIDTH_20:
6363 case NL80211_CHAN_WIDTH_40:
6364 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6365 break;
6366 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006367 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006368 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006369
Johannes Berg04a773a2009-04-19 21:24:32 +02006370 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006371 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006372
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006373 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6374 u8 *rates =
6375 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6376 int n_rates =
6377 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6378 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006379 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006380
Johannes Berg34850ab2011-07-18 18:08:35 +02006381 err = ieee80211_get_ratemask(sband, rates, n_rates,
6382 &ibss.basic_rates);
6383 if (err)
6384 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006385 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006386
Simon Wunderlich803768f2013-06-28 10:39:58 +02006387 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6388 memcpy(&ibss.ht_capa_mask,
6389 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6390 sizeof(ibss.ht_capa_mask));
6391
6392 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6393 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6394 return -EINVAL;
6395 memcpy(&ibss.ht_capa,
6396 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6397 sizeof(ibss.ht_capa));
6398 }
6399
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006400 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6401 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6402 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6403 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006404
Johannes Berg4c476992010-10-04 21:36:35 +02006405 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306406 bool no_ht = false;
6407
Johannes Berg4c476992010-10-04 21:36:35 +02006408 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306409 info->attrs[NL80211_ATTR_KEYS],
6410 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006411 if (IS_ERR(connkeys))
6412 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306413
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006414 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6415 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306416 kfree(connkeys);
6417 return -EINVAL;
6418 }
Johannes Berg4c476992010-10-04 21:36:35 +02006419 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006420
Antonio Quartulli267335d2012-01-31 20:25:47 +01006421 ibss.control_port =
6422 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6423
Johannes Berg4c476992010-10-04 21:36:35 +02006424 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006425 if (err)
6426 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006427 return err;
6428}
6429
6430static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6431{
Johannes Berg4c476992010-10-04 21:36:35 +02006432 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6433 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006434
Johannes Berg4c476992010-10-04 21:36:35 +02006435 if (!rdev->ops->leave_ibss)
6436 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006437
Johannes Berg4c476992010-10-04 21:36:35 +02006438 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6439 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006440
Johannes Berg4c476992010-10-04 21:36:35 +02006441 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006442}
6443
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006444static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6445{
6446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6447 struct net_device *dev = info->user_ptr[1];
6448 int mcast_rate[IEEE80211_NUM_BANDS];
6449 u32 nla_rate;
6450 int err;
6451
6452 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6453 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6454 return -EOPNOTSUPP;
6455
6456 if (!rdev->ops->set_mcast_rate)
6457 return -EOPNOTSUPP;
6458
6459 memset(mcast_rate, 0, sizeof(mcast_rate));
6460
6461 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6462 return -EINVAL;
6463
6464 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6465 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6466 return -EINVAL;
6467
6468 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6469
6470 return err;
6471}
6472
6473
Johannes Bergaff89a92009-07-01 21:26:51 +02006474#ifdef CONFIG_NL80211_TESTMODE
6475static struct genl_multicast_group nl80211_testmode_mcgrp = {
6476 .name = "testmode",
6477};
6478
6479static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6480{
Johannes Berg4c476992010-10-04 21:36:35 +02006481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006482 int err;
6483
6484 if (!info->attrs[NL80211_ATTR_TESTDATA])
6485 return -EINVAL;
6486
Johannes Bergaff89a92009-07-01 21:26:51 +02006487 err = -EOPNOTSUPP;
6488 if (rdev->ops->testmode_cmd) {
6489 rdev->testmode_info = info;
Hila Gonene35e4d22012-06-27 17:19:42 +03006490 err = rdev_testmode_cmd(rdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006491 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6492 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
6493 rdev->testmode_info = NULL;
6494 }
6495
Johannes Bergaff89a92009-07-01 21:26:51 +02006496 return err;
6497}
6498
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006499static int nl80211_testmode_dump(struct sk_buff *skb,
6500 struct netlink_callback *cb)
6501{
Johannes Berg00918d32011-12-13 17:22:05 +01006502 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006503 int err;
6504 long phy_idx;
6505 void *data = NULL;
6506 int data_len = 0;
6507
Johannes Berg5fe231e2013-05-08 21:45:15 +02006508 rtnl_lock();
6509
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006510 if (cb->args[0]) {
6511 /*
6512 * 0 is a valid index, but not valid for args[0],
6513 * so we need to offset by 1.
6514 */
6515 phy_idx = cb->args[0] - 1;
6516 } else {
6517 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6518 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6519 nl80211_policy);
6520 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006521 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006522
Johannes Berg2bd7e352012-06-15 14:23:16 +02006523 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6524 nl80211_fam.attrbuf);
6525 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006526 err = PTR_ERR(rdev);
6527 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006528 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006529 phy_idx = rdev->wiphy_idx;
6530 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006531
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006532 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6533 cb->args[1] =
6534 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6535 }
6536
6537 if (cb->args[1]) {
6538 data = nla_data((void *)cb->args[1]);
6539 data_len = nla_len((void *)cb->args[1]);
6540 }
6541
Johannes Berg00918d32011-12-13 17:22:05 +01006542 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6543 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006544 err = -ENOENT;
6545 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006546 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006547
Johannes Berg00918d32011-12-13 17:22:05 +01006548 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006549 err = -EOPNOTSUPP;
6550 goto out_err;
6551 }
6552
6553 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006554 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006555 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6556 NL80211_CMD_TESTMODE);
6557 struct nlattr *tmdata;
6558
David S. Miller9360ffd2012-03-29 04:41:26 -04006559 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006560 genlmsg_cancel(skb, hdr);
6561 break;
6562 }
6563
6564 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6565 if (!tmdata) {
6566 genlmsg_cancel(skb, hdr);
6567 break;
6568 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006569 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006570 nla_nest_end(skb, tmdata);
6571
6572 if (err == -ENOBUFS || err == -ENOENT) {
6573 genlmsg_cancel(skb, hdr);
6574 break;
6575 } else if (err) {
6576 genlmsg_cancel(skb, hdr);
6577 goto out_err;
6578 }
6579
6580 genlmsg_end(skb, hdr);
6581 }
6582
6583 err = skb->len;
6584 /* see above */
6585 cb->args[0] = phy_idx + 1;
6586 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006587 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006588 return err;
6589}
6590
Johannes Bergaff89a92009-07-01 21:26:51 +02006591static struct sk_buff *
6592__cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006593 int approxlen, u32 portid, u32 seq, gfp_t gfp)
Johannes Bergaff89a92009-07-01 21:26:51 +02006594{
6595 struct sk_buff *skb;
6596 void *hdr;
6597 struct nlattr *data;
6598
6599 skb = nlmsg_new(approxlen + 100, gfp);
6600 if (!skb)
6601 return NULL;
6602
Eric W. Biederman15e47302012-09-07 20:12:54 +00006603 hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE);
Johannes Bergaff89a92009-07-01 21:26:51 +02006604 if (!hdr) {
6605 kfree_skb(skb);
6606 return NULL;
6607 }
6608
David S. Miller9360ffd2012-03-29 04:41:26 -04006609 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6610 goto nla_put_failure;
Johannes Bergaff89a92009-07-01 21:26:51 +02006611 data = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6612
6613 ((void **)skb->cb)[0] = rdev;
6614 ((void **)skb->cb)[1] = hdr;
6615 ((void **)skb->cb)[2] = data;
6616
6617 return skb;
6618
6619 nla_put_failure:
6620 kfree_skb(skb);
6621 return NULL;
6622}
6623
6624struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy,
6625 int approxlen)
6626{
6627 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6628
6629 if (WARN_ON(!rdev->testmode_info))
6630 return NULL;
6631
6632 return __cfg80211_testmode_alloc_skb(rdev, approxlen,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006633 rdev->testmode_info->snd_portid,
Johannes Bergaff89a92009-07-01 21:26:51 +02006634 rdev->testmode_info->snd_seq,
6635 GFP_KERNEL);
6636}
6637EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb);
6638
6639int cfg80211_testmode_reply(struct sk_buff *skb)
6640{
6641 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6642 void *hdr = ((void **)skb->cb)[1];
6643 struct nlattr *data = ((void **)skb->cb)[2];
6644
6645 if (WARN_ON(!rdev->testmode_info)) {
6646 kfree_skb(skb);
6647 return -EINVAL;
6648 }
6649
6650 nla_nest_end(skb, data);
6651 genlmsg_end(skb, hdr);
6652 return genlmsg_reply(skb, rdev->testmode_info);
6653}
6654EXPORT_SYMBOL(cfg80211_testmode_reply);
6655
6656struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6657 int approxlen, gfp_t gfp)
6658{
6659 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6660
6661 return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp);
6662}
6663EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6664
6665void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6666{
6667 void *hdr = ((void **)skb->cb)[1];
6668 struct nlattr *data = ((void **)skb->cb)[2];
6669
6670 nla_nest_end(skb, data);
6671 genlmsg_end(skb, hdr);
6672 genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
6673}
6674EXPORT_SYMBOL(cfg80211_testmode_event);
6675#endif
6676
Samuel Ortizb23aa672009-07-01 21:26:54 +02006677static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6678{
Johannes Berg4c476992010-10-04 21:36:35 +02006679 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6680 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006681 struct cfg80211_connect_params connect;
6682 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006683 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006684 int err;
6685
6686 memset(&connect, 0, sizeof(connect));
6687
6688 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6689 return -EINVAL;
6690
6691 if (!info->attrs[NL80211_ATTR_SSID] ||
6692 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6693 return -EINVAL;
6694
6695 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6696 connect.auth_type =
6697 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006698 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6699 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006700 return -EINVAL;
6701 } else
6702 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6703
6704 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6705
Johannes Bergc0692b82010-08-27 14:26:53 +03006706 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006707 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006708 if (err)
6709 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006710
Johannes Berg074ac8d2010-09-16 14:58:22 +02006711 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006712 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6713 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006714
Johannes Berg79c97e92009-07-07 03:56:12 +02006715 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006716
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306717 connect.bg_scan_period = -1;
6718 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6719 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6720 connect.bg_scan_period =
6721 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6722 }
6723
Samuel Ortizb23aa672009-07-01 21:26:54 +02006724 if (info->attrs[NL80211_ATTR_MAC])
6725 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6726 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6727 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6728
6729 if (info->attrs[NL80211_ATTR_IE]) {
6730 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6731 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6732 }
6733
Jouni Malinencee00a92013-01-15 17:15:57 +02006734 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6735 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6736 if (connect.mfp != NL80211_MFP_REQUIRED &&
6737 connect.mfp != NL80211_MFP_NO)
6738 return -EINVAL;
6739 } else {
6740 connect.mfp = NL80211_MFP_NO;
6741 }
6742
Samuel Ortizb23aa672009-07-01 21:26:54 +02006743 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6744 connect.channel =
6745 ieee80211_get_channel(wiphy,
6746 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6747 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006748 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6749 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006750 }
6751
Johannes Bergfffd0932009-07-08 14:22:54 +02006752 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6753 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306754 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006755 if (IS_ERR(connkeys))
6756 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006757 }
6758
Ben Greear7e7c8922011-11-18 11:31:59 -08006759 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6760 connect.flags |= ASSOC_REQ_DISABLE_HT;
6761
6762 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6763 memcpy(&connect.ht_capa_mask,
6764 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6765 sizeof(connect.ht_capa_mask));
6766
6767 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006768 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
6769 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08006770 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08006771 }
Ben Greear7e7c8922011-11-18 11:31:59 -08006772 memcpy(&connect.ht_capa,
6773 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6774 sizeof(connect.ht_capa));
6775 }
6776
Johannes Bergee2aca32013-02-21 17:36:01 +01006777 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6778 connect.flags |= ASSOC_REQ_DISABLE_VHT;
6779
6780 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6781 memcpy(&connect.vht_capa_mask,
6782 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6783 sizeof(connect.vht_capa_mask));
6784
6785 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6786 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
6787 kfree(connkeys);
6788 return -EINVAL;
6789 }
6790 memcpy(&connect.vht_capa,
6791 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6792 sizeof(connect.vht_capa));
6793 }
6794
Johannes Berg83739b02013-05-15 17:44:01 +02006795 wdev_lock(dev->ieee80211_ptr);
6796 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
6797 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02006798 if (err)
6799 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006800 return err;
6801}
6802
6803static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
6804{
Johannes Berg4c476992010-10-04 21:36:35 +02006805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6806 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006807 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02006808 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006809
6810 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6811 reason = WLAN_REASON_DEAUTH_LEAVING;
6812 else
6813 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6814
6815 if (reason == 0)
6816 return -EINVAL;
6817
Johannes Berg074ac8d2010-09-16 14:58:22 +02006818 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006819 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6820 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006821
Johannes Berg83739b02013-05-15 17:44:01 +02006822 wdev_lock(dev->ieee80211_ptr);
6823 ret = cfg80211_disconnect(rdev, dev, reason, true);
6824 wdev_unlock(dev->ieee80211_ptr);
6825 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006826}
6827
Johannes Berg463d0182009-07-14 00:33:35 +02006828static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
6829{
Johannes Berg4c476992010-10-04 21:36:35 +02006830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02006831 struct net *net;
6832 int err;
6833 u32 pid;
6834
6835 if (!info->attrs[NL80211_ATTR_PID])
6836 return -EINVAL;
6837
6838 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
6839
Johannes Berg463d0182009-07-14 00:33:35 +02006840 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02006841 if (IS_ERR(net))
6842 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006843
6844 err = 0;
6845
6846 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02006847 if (!net_eq(wiphy_net(&rdev->wiphy), net))
6848 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02006849
Johannes Berg463d0182009-07-14 00:33:35 +02006850 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02006851 return err;
6852}
6853
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006854static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
6855{
Johannes Berg4c476992010-10-04 21:36:35 +02006856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006857 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
6858 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02006859 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006860 struct cfg80211_pmksa pmksa;
6861
6862 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
6863
6864 if (!info->attrs[NL80211_ATTR_MAC])
6865 return -EINVAL;
6866
6867 if (!info->attrs[NL80211_ATTR_PMKID])
6868 return -EINVAL;
6869
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006870 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
6871 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6872
Johannes Berg074ac8d2010-09-16 14:58:22 +02006873 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006874 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6875 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006876
6877 switch (info->genlhdr->cmd) {
6878 case NL80211_CMD_SET_PMKSA:
6879 rdev_ops = rdev->ops->set_pmksa;
6880 break;
6881 case NL80211_CMD_DEL_PMKSA:
6882 rdev_ops = rdev->ops->del_pmksa;
6883 break;
6884 default:
6885 WARN_ON(1);
6886 break;
6887 }
6888
Johannes Berg4c476992010-10-04 21:36:35 +02006889 if (!rdev_ops)
6890 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006891
Johannes Berg4c476992010-10-04 21:36:35 +02006892 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006893}
6894
6895static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
6896{
Johannes Berg4c476992010-10-04 21:36:35 +02006897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6898 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006899
Johannes Berg074ac8d2010-09-16 14:58:22 +02006900 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006901 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6902 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006903
Johannes Berg4c476992010-10-04 21:36:35 +02006904 if (!rdev->ops->flush_pmksa)
6905 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006906
Hila Gonene35e4d22012-06-27 17:19:42 +03006907 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01006908}
6909
Arik Nemtsov109086c2011-09-28 14:12:50 +03006910static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
6911{
6912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6913 struct net_device *dev = info->user_ptr[1];
6914 u8 action_code, dialog_token;
6915 u16 status_code;
6916 u8 *peer;
6917
6918 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6919 !rdev->ops->tdls_mgmt)
6920 return -EOPNOTSUPP;
6921
6922 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
6923 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
6924 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
6925 !info->attrs[NL80211_ATTR_IE] ||
6926 !info->attrs[NL80211_ATTR_MAC])
6927 return -EINVAL;
6928
6929 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6930 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
6931 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
6932 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
6933
Hila Gonene35e4d22012-06-27 17:19:42 +03006934 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
6935 dialog_token, status_code,
6936 nla_data(info->attrs[NL80211_ATTR_IE]),
6937 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03006938}
6939
6940static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
6941{
6942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6943 struct net_device *dev = info->user_ptr[1];
6944 enum nl80211_tdls_operation operation;
6945 u8 *peer;
6946
6947 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
6948 !rdev->ops->tdls_oper)
6949 return -EOPNOTSUPP;
6950
6951 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
6952 !info->attrs[NL80211_ATTR_MAC])
6953 return -EINVAL;
6954
6955 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
6956 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
6957
Hila Gonene35e4d22012-06-27 17:19:42 +03006958 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03006959}
6960
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006961static int nl80211_remain_on_channel(struct sk_buff *skb,
6962 struct genl_info *info)
6963{
Johannes Berg4c476992010-10-04 21:36:35 +02006964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02006965 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01006966 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006967 struct sk_buff *msg;
6968 void *hdr;
6969 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01006970 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006971 int err;
6972
6973 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6974 !info->attrs[NL80211_ATTR_DURATION])
6975 return -EINVAL;
6976
6977 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
6978
Johannes Berg7c4ef712011-11-18 15:33:48 +01006979 if (!rdev->ops->remain_on_channel ||
6980 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02006981 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006982
Johannes Bergebf348f2012-06-01 12:50:54 +02006983 /*
6984 * We should be on that channel for at least a minimum amount of
6985 * time (10ms) but no longer than the driver supports.
6986 */
6987 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
6988 duration > rdev->wiphy.max_remain_on_channel_duration)
6989 return -EINVAL;
6990
Johannes Berg683b6d32012-11-08 21:25:48 +01006991 err = nl80211_parse_chandef(rdev, info, &chandef);
6992 if (err)
6993 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006994
6995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006996 if (!msg)
6997 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01006998
Eric W. Biederman15e47302012-09-07 20:12:54 +00006999 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007000 NL80211_CMD_REMAIN_ON_CHANNEL);
7001
7002 if (IS_ERR(hdr)) {
7003 err = PTR_ERR(hdr);
7004 goto free_msg;
7005 }
7006
Johannes Berg683b6d32012-11-08 21:25:48 +01007007 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7008 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007009
7010 if (err)
7011 goto free_msg;
7012
David S. Miller9360ffd2012-03-29 04:41:26 -04007013 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7014 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007015
7016 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007017
7018 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007019
7020 nla_put_failure:
7021 err = -ENOBUFS;
7022 free_msg:
7023 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007024 return err;
7025}
7026
7027static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7028 struct genl_info *info)
7029{
Johannes Berg4c476992010-10-04 21:36:35 +02007030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007031 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007032 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007033
7034 if (!info->attrs[NL80211_ATTR_COOKIE])
7035 return -EINVAL;
7036
Johannes Berg4c476992010-10-04 21:36:35 +02007037 if (!rdev->ops->cancel_remain_on_channel)
7038 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007039
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007040 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7041
Hila Gonene35e4d22012-06-27 17:19:42 +03007042 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007043}
7044
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007045static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7046 u8 *rates, u8 rates_len)
7047{
7048 u8 i;
7049 u32 mask = 0;
7050
7051 for (i = 0; i < rates_len; i++) {
7052 int rate = (rates[i] & 0x7f) * 5;
7053 int ridx;
7054 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7055 struct ieee80211_rate *srate =
7056 &sband->bitrates[ridx];
7057 if (rate == srate->bitrate) {
7058 mask |= 1 << ridx;
7059 break;
7060 }
7061 }
7062 if (ridx == sband->n_bitrates)
7063 return 0; /* rate not found */
7064 }
7065
7066 return mask;
7067}
7068
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007069static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7070 u8 *rates, u8 rates_len,
7071 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7072{
7073 u8 i;
7074
7075 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7076
7077 for (i = 0; i < rates_len; i++) {
7078 int ridx, rbit;
7079
7080 ridx = rates[i] / 8;
7081 rbit = BIT(rates[i] % 8);
7082
7083 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007084 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007085 return false;
7086
7087 /* check availability */
7088 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7089 mcs[ridx] |= rbit;
7090 else
7091 return false;
7092 }
7093
7094 return true;
7095}
7096
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007097static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007098 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7099 .len = NL80211_MAX_SUPP_RATES },
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007100 [NL80211_TXRATE_MCS] = { .type = NLA_BINARY,
7101 .len = NL80211_MAX_SUPP_HT_RATES },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007102};
7103
7104static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7105 struct genl_info *info)
7106{
7107 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007109 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007110 int rem, i;
7111 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007112 struct nlattr *tx_rates;
7113 struct ieee80211_supported_band *sband;
7114
7115 if (info->attrs[NL80211_ATTR_TX_RATES] == NULL)
7116 return -EINVAL;
7117
Johannes Berg4c476992010-10-04 21:36:35 +02007118 if (!rdev->ops->set_bitrate_mask)
7119 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007120
7121 memset(&mask, 0, sizeof(mask));
7122 /* Default to all rates enabled */
7123 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7124 sband = rdev->wiphy.bands[i];
7125 mask.control[i].legacy =
7126 sband ? (1 << sband->n_bitrates) - 1 : 0;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007127 if (sband)
7128 memcpy(mask.control[i].mcs,
7129 sband->ht_cap.mcs.rx_mask,
7130 sizeof(mask.control[i].mcs));
7131 else
7132 memset(mask.control[i].mcs, 0,
7133 sizeof(mask.control[i].mcs));
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007134 }
7135
7136 /*
7137 * The nested attribute uses enum nl80211_band as the index. This maps
7138 * directly to the enum ieee80211_band values used in cfg80211.
7139 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007140 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007141 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7142 {
7143 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007144 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7145 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007146 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007147 if (sband == NULL)
7148 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007149 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7150 nla_len(tx_rates), nl80211_txattr_policy);
7151 if (tb[NL80211_TXRATE_LEGACY]) {
7152 mask.control[band].legacy = rateset_to_mask(
7153 sband,
7154 nla_data(tb[NL80211_TXRATE_LEGACY]),
7155 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307156 if ((mask.control[band].legacy == 0) &&
7157 nla_len(tb[NL80211_TXRATE_LEGACY]))
7158 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007159 }
7160 if (tb[NL80211_TXRATE_MCS]) {
7161 if (!ht_rateset_to_mask(
7162 sband,
7163 nla_data(tb[NL80211_TXRATE_MCS]),
7164 nla_len(tb[NL80211_TXRATE_MCS]),
7165 mask.control[band].mcs))
7166 return -EINVAL;
7167 }
7168
7169 if (mask.control[band].legacy == 0) {
7170 /* don't allow empty legacy rates if HT
7171 * is not even supported. */
7172 if (!rdev->wiphy.bands[band]->ht_cap.ht_supported)
7173 return -EINVAL;
7174
7175 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
7176 if (mask.control[band].mcs[i])
7177 break;
7178
7179 /* legacy and mcs rates may not be both empty */
7180 if (i == IEEE80211_HT_MCS_MASK_LEN)
Johannes Berg4c476992010-10-04 21:36:35 +02007181 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007182 }
7183 }
7184
Hila Gonene35e4d22012-06-27 17:19:42 +03007185 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007186}
7187
Johannes Berg2e161f72010-08-12 15:38:38 +02007188static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007189{
Johannes Berg4c476992010-10-04 21:36:35 +02007190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007191 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007192 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007193
7194 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7195 return -EINVAL;
7196
Johannes Berg2e161f72010-08-12 15:38:38 +02007197 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7198 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007199
Johannes Berg71bbc992012-06-15 15:30:18 +02007200 switch (wdev->iftype) {
7201 case NL80211_IFTYPE_STATION:
7202 case NL80211_IFTYPE_ADHOC:
7203 case NL80211_IFTYPE_P2P_CLIENT:
7204 case NL80211_IFTYPE_AP:
7205 case NL80211_IFTYPE_AP_VLAN:
7206 case NL80211_IFTYPE_MESH_POINT:
7207 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007208 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007209 break;
7210 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007211 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007212 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007213
7214 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007215 if (!rdev->ops->mgmt_tx)
7216 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007217
Eric W. Biederman15e47302012-09-07 20:12:54 +00007218 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007219 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7220 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007221}
7222
Johannes Berg2e161f72010-08-12 15:38:38 +02007223static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007224{
Johannes Berg4c476992010-10-04 21:36:35 +02007225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007226 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007227 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007228 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007229 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007230 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007231 struct sk_buff *msg = NULL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007232 unsigned int wait = 0;
Johannes Berge247bd902011-11-04 11:18:21 +01007233 bool offchan, no_cck, dont_wait_for_ack;
7234
7235 dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Jouni Malinen026331c2010-02-15 12:53:10 +02007236
Johannes Berg683b6d32012-11-08 21:25:48 +01007237 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007238 return -EINVAL;
7239
Johannes Berg4c476992010-10-04 21:36:35 +02007240 if (!rdev->ops->mgmt_tx)
7241 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007242
Johannes Berg71bbc992012-06-15 15:30:18 +02007243 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007244 case NL80211_IFTYPE_P2P_DEVICE:
7245 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7246 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007247 case NL80211_IFTYPE_STATION:
7248 case NL80211_IFTYPE_ADHOC:
7249 case NL80211_IFTYPE_P2P_CLIENT:
7250 case NL80211_IFTYPE_AP:
7251 case NL80211_IFTYPE_AP_VLAN:
7252 case NL80211_IFTYPE_MESH_POINT:
7253 case NL80211_IFTYPE_P2P_GO:
7254 break;
7255 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007256 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007257 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007258
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007259 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007260 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007261 return -EINVAL;
7262 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007263
7264 /*
7265 * We should wait on the channel for at least a minimum amount
7266 * of time (10ms) but no longer than the driver supports.
7267 */
7268 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7269 wait > rdev->wiphy.max_remain_on_channel_duration)
7270 return -EINVAL;
7271
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007272 }
7273
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007274 offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
7275
Johannes Berg7c4ef712011-11-18 15:33:48 +01007276 if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
7277 return -EINVAL;
7278
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307279 no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7280
Antonio Quartulliea141b752013-06-11 14:20:03 +02007281 /* get the channel if any has been specified, otherwise pass NULL to
7282 * the driver. The latter will use the current one
7283 */
7284 chandef.chan = NULL;
7285 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7286 err = nl80211_parse_chandef(rdev, info, &chandef);
7287 if (err)
7288 return err;
7289 }
7290
7291 if (!chandef.chan && offchan)
7292 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007293
Johannes Berge247bd902011-11-04 11:18:21 +01007294 if (!dont_wait_for_ack) {
7295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7296 if (!msg)
7297 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007298
Eric W. Biederman15e47302012-09-07 20:12:54 +00007299 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007300 NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +02007301
Johannes Berge247bd902011-11-04 11:18:21 +01007302 if (IS_ERR(hdr)) {
7303 err = PTR_ERR(hdr);
7304 goto free_msg;
7305 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007306 }
Johannes Berge247bd902011-11-04 11:18:21 +01007307
Johannes Berg683b6d32012-11-08 21:25:48 +01007308 err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02007309 nla_data(info->attrs[NL80211_ATTR_FRAME]),
7310 nla_len(info->attrs[NL80211_ATTR_FRAME]),
Johannes Berge247bd902011-11-04 11:18:21 +01007311 no_cck, dont_wait_for_ack, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007312 if (err)
7313 goto free_msg;
7314
Johannes Berge247bd902011-11-04 11:18:21 +01007315 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007316 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7317 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007318
Johannes Berge247bd902011-11-04 11:18:21 +01007319 genlmsg_end(msg, hdr);
7320 return genlmsg_reply(msg, info);
7321 }
7322
7323 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007324
7325 nla_put_failure:
7326 err = -ENOBUFS;
7327 free_msg:
7328 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007329 return err;
7330}
7331
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007332static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7333{
7334 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007335 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007336 u64 cookie;
7337
7338 if (!info->attrs[NL80211_ATTR_COOKIE])
7339 return -EINVAL;
7340
7341 if (!rdev->ops->mgmt_tx_cancel_wait)
7342 return -EOPNOTSUPP;
7343
Johannes Berg71bbc992012-06-15 15:30:18 +02007344 switch (wdev->iftype) {
7345 case NL80211_IFTYPE_STATION:
7346 case NL80211_IFTYPE_ADHOC:
7347 case NL80211_IFTYPE_P2P_CLIENT:
7348 case NL80211_IFTYPE_AP:
7349 case NL80211_IFTYPE_AP_VLAN:
7350 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007351 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007352 break;
7353 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007354 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007355 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007356
7357 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7358
Hila Gonene35e4d22012-06-27 17:19:42 +03007359 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007360}
7361
Kalle Valoffb9eb32010-02-17 17:58:10 +02007362static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7363{
Johannes Berg4c476992010-10-04 21:36:35 +02007364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007365 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007366 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007367 u8 ps_state;
7368 bool state;
7369 int err;
7370
Johannes Berg4c476992010-10-04 21:36:35 +02007371 if (!info->attrs[NL80211_ATTR_PS_STATE])
7372 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007373
7374 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7375
Johannes Berg4c476992010-10-04 21:36:35 +02007376 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7377 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007378
7379 wdev = dev->ieee80211_ptr;
7380
Johannes Berg4c476992010-10-04 21:36:35 +02007381 if (!rdev->ops->set_power_mgmt)
7382 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007383
7384 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7385
7386 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007387 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007388
Hila Gonene35e4d22012-06-27 17:19:42 +03007389 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007390 if (!err)
7391 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007392 return err;
7393}
7394
7395static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7396{
Johannes Berg4c476992010-10-04 21:36:35 +02007397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007398 enum nl80211_ps_state ps_state;
7399 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007400 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007401 struct sk_buff *msg;
7402 void *hdr;
7403 int err;
7404
Kalle Valoffb9eb32010-02-17 17:58:10 +02007405 wdev = dev->ieee80211_ptr;
7406
Johannes Berg4c476992010-10-04 21:36:35 +02007407 if (!rdev->ops->set_power_mgmt)
7408 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007409
7410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007411 if (!msg)
7412 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007413
Eric W. Biederman15e47302012-09-07 20:12:54 +00007414 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007415 NL80211_CMD_GET_POWER_SAVE);
7416 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007417 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007418 goto free_msg;
7419 }
7420
7421 if (wdev->ps)
7422 ps_state = NL80211_PS_ENABLED;
7423 else
7424 ps_state = NL80211_PS_DISABLED;
7425
David S. Miller9360ffd2012-03-29 04:41:26 -04007426 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7427 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007428
7429 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007430 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007431
Johannes Berg4c476992010-10-04 21:36:35 +02007432 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007433 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007434 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007435 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007436 return err;
7437}
7438
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007439static struct nla_policy
7440nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7441 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7442 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7443 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007444 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7445 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7446 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007447};
7448
Thomas Pedersen84f10702012-07-12 16:17:33 -07007449static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007450 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007451{
7452 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7453 struct wireless_dev *wdev;
7454 struct net_device *dev = info->user_ptr[1];
7455
Johannes Bergd9d8b012012-11-26 12:51:52 +01007456 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007457 return -EINVAL;
7458
7459 wdev = dev->ieee80211_ptr;
7460
7461 if (!rdev->ops->set_cqm_txe_config)
7462 return -EOPNOTSUPP;
7463
7464 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7465 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7466 return -EOPNOTSUPP;
7467
Hila Gonene35e4d22012-06-27 17:19:42 +03007468 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007469}
7470
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007471static int nl80211_set_cqm_rssi(struct genl_info *info,
7472 s32 threshold, u32 hysteresis)
7473{
Johannes Berg4c476992010-10-04 21:36:35 +02007474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007475 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007476 struct net_device *dev = info->user_ptr[1];
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007477
7478 if (threshold > 0)
7479 return -EINVAL;
7480
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007481 wdev = dev->ieee80211_ptr;
7482
Johannes Berg4c476992010-10-04 21:36:35 +02007483 if (!rdev->ops->set_cqm_rssi_config)
7484 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007485
Johannes Berg074ac8d2010-09-16 14:58:22 +02007486 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007487 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7488 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007489
Hila Gonene35e4d22012-06-27 17:19:42 +03007490 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007491}
7492
7493static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7494{
7495 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7496 struct nlattr *cqm;
7497 int err;
7498
7499 cqm = info->attrs[NL80211_ATTR_CQM];
7500 if (!cqm) {
7501 err = -EINVAL;
7502 goto out;
7503 }
7504
7505 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7506 nl80211_attr_cqm_policy);
7507 if (err)
7508 goto out;
7509
7510 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7511 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
7512 s32 threshold;
7513 u32 hysteresis;
7514 threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7515 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
7516 err = nl80211_set_cqm_rssi(info, threshold, hysteresis);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007517 } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7518 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7519 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7520 u32 rate, pkts, intvl;
7521 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7522 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7523 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7524 err = nl80211_set_cqm_txe(info, rate, pkts, intvl);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007525 } else
7526 err = -EINVAL;
7527
7528out:
7529 return err;
7530}
7531
Johannes Berg29cbe682010-12-03 09:20:44 +01007532static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7533{
7534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7535 struct net_device *dev = info->user_ptr[1];
7536 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007537 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007538 int err;
7539
7540 /* start with default */
7541 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007542 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007543
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007544 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007545 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007546 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007547 if (err)
7548 return err;
7549 }
7550
7551 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7552 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7553 return -EINVAL;
7554
Javier Cardonac80d5452010-12-16 17:37:49 -08007555 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7556 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7557
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007558 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7559 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7560 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7561 return -EINVAL;
7562
Marco Porsch9bdbf042013-01-07 16:04:51 +01007563 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7564 setup.beacon_interval =
7565 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7566 if (setup.beacon_interval < 10 ||
7567 setup.beacon_interval > 10000)
7568 return -EINVAL;
7569 }
7570
7571 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7572 setup.dtim_period =
7573 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7574 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7575 return -EINVAL;
7576 }
7577
Javier Cardonac80d5452010-12-16 17:37:49 -08007578 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7579 /* parse additional setup parameters if given */
7580 err = nl80211_parse_mesh_setup(info, &setup);
7581 if (err)
7582 return err;
7583 }
7584
Thomas Pedersend37bb182013-03-04 13:06:13 -08007585 if (setup.user_mpm)
7586 cfg.auto_open_plinks = false;
7587
Johannes Bergcc1d2802012-05-16 23:50:20 +02007588 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007589 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7590 if (err)
7591 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007592 } else {
7593 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007594 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007595 }
7596
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007597 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7598 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7599 int n_rates =
7600 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7601 struct ieee80211_supported_band *sband;
7602
7603 if (!setup.chandef.chan)
7604 return -EINVAL;
7605
7606 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7607
7608 err = ieee80211_get_ratemask(sband, rates, n_rates,
7609 &setup.basic_rates);
7610 if (err)
7611 return err;
7612 }
7613
Javier Cardonac80d5452010-12-16 17:37:49 -08007614 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007615}
7616
7617static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7618{
7619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7620 struct net_device *dev = info->user_ptr[1];
7621
7622 return cfg80211_leave_mesh(rdev, dev);
7623}
7624
Johannes Bergdfb89c52012-06-27 09:23:48 +02007625#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007626static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7627 struct cfg80211_registered_device *rdev)
7628{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007629 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007630 struct nlattr *nl_pats, *nl_pat;
7631 int i, pat_len;
7632
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007633 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007634 return 0;
7635
7636 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7637 if (!nl_pats)
7638 return -ENOBUFS;
7639
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007640 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007641 nl_pat = nla_nest_start(msg, i + 1);
7642 if (!nl_pat)
7643 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007644 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007645 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007646 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007647 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7648 wowlan->patterns[i].pattern) ||
7649 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007650 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007651 return -ENOBUFS;
7652 nla_nest_end(msg, nl_pat);
7653 }
7654 nla_nest_end(msg, nl_pats);
7655
7656 return 0;
7657}
7658
Johannes Berg2a0e0472013-01-23 22:57:40 +01007659static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7660 struct cfg80211_wowlan_tcp *tcp)
7661{
7662 struct nlattr *nl_tcp;
7663
7664 if (!tcp)
7665 return 0;
7666
7667 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7668 if (!nl_tcp)
7669 return -ENOBUFS;
7670
7671 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7672 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7673 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7674 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7675 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7676 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7677 tcp->payload_len, tcp->payload) ||
7678 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7679 tcp->data_interval) ||
7680 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7681 tcp->wake_len, tcp->wake_data) ||
7682 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7683 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7684 return -ENOBUFS;
7685
7686 if (tcp->payload_seq.len &&
7687 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7688 sizeof(tcp->payload_seq), &tcp->payload_seq))
7689 return -ENOBUFS;
7690
7691 if (tcp->payload_tok.len &&
7692 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
7693 sizeof(tcp->payload_tok) + tcp->tokens_size,
7694 &tcp->payload_tok))
7695 return -ENOBUFS;
7696
Johannes Berge248ad32013-05-16 10:24:28 +02007697 nla_nest_end(msg, nl_tcp);
7698
Johannes Berg2a0e0472013-01-23 22:57:40 +01007699 return 0;
7700}
7701
Johannes Bergff1b6e62011-05-04 15:37:28 +02007702static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
7703{
7704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7705 struct sk_buff *msg;
7706 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007707 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007708
Johannes Berg964dc9e2013-06-03 17:25:34 +02007709 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007710 return -EOPNOTSUPP;
7711
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007712 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01007713 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007714 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
7715 rdev->wiphy.wowlan_config->tcp->payload_len +
7716 rdev->wiphy.wowlan_config->tcp->wake_len +
7717 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007718 }
7719
7720 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02007721 if (!msg)
7722 return -ENOMEM;
7723
Eric W. Biederman15e47302012-09-07 20:12:54 +00007724 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02007725 NL80211_CMD_GET_WOWLAN);
7726 if (!hdr)
7727 goto nla_put_failure;
7728
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007729 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02007730 struct nlattr *nl_wowlan;
7731
7732 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
7733 if (!nl_wowlan)
7734 goto nla_put_failure;
7735
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007736 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007737 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007738 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007739 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007740 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007741 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007742 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007743 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007744 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007745 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007746 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007747 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007748 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04007749 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
7750 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007751
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007752 if (nl80211_send_wowlan_patterns(msg, rdev))
7753 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01007754
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007755 if (nl80211_send_wowlan_tcp(msg,
7756 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01007757 goto nla_put_failure;
7758
Johannes Bergff1b6e62011-05-04 15:37:28 +02007759 nla_nest_end(msg, nl_wowlan);
7760 }
7761
7762 genlmsg_end(msg, hdr);
7763 return genlmsg_reply(msg, info);
7764
7765nla_put_failure:
7766 nlmsg_free(msg);
7767 return -ENOBUFS;
7768}
7769
Johannes Berg2a0e0472013-01-23 22:57:40 +01007770static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
7771 struct nlattr *attr,
7772 struct cfg80211_wowlan *trig)
7773{
7774 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
7775 struct cfg80211_wowlan_tcp *cfg;
7776 struct nl80211_wowlan_tcp_data_token *tok = NULL;
7777 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
7778 u32 size;
7779 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
7780 int err, port;
7781
Johannes Berg964dc9e2013-06-03 17:25:34 +02007782 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007783 return -EINVAL;
7784
7785 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
7786 nla_data(attr), nla_len(attr),
7787 nl80211_wowlan_tcp_policy);
7788 if (err)
7789 return err;
7790
7791 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
7792 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
7793 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
7794 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
7795 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
7796 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
7797 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
7798 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
7799 return -EINVAL;
7800
7801 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007802 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007803 return -EINVAL;
7804
7805 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02007806 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01007807 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007808 return -EINVAL;
7809
7810 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007811 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007812 return -EINVAL;
7813
7814 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
7815 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
7816 return -EINVAL;
7817
7818 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
7819 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7820
7821 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
7822 tokens_size = tokln - sizeof(*tok);
7823
7824 if (!tok->len || tokens_size % tok->len)
7825 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007826 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007827 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007828 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007829 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007830 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007831 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007832 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007833 return -EINVAL;
7834 if (tok->offset + tok->len > data_size)
7835 return -EINVAL;
7836 }
7837
7838 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
7839 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02007840 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01007841 return -EINVAL;
7842 if (seq->len == 0 || seq->len > 4)
7843 return -EINVAL;
7844 if (seq->len + seq->offset > data_size)
7845 return -EINVAL;
7846 }
7847
7848 size = sizeof(*cfg);
7849 size += data_size;
7850 size += wake_size + wake_mask_size;
7851 size += tokens_size;
7852
7853 cfg = kzalloc(size, GFP_KERNEL);
7854 if (!cfg)
7855 return -ENOMEM;
7856 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
7857 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
7858 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
7859 ETH_ALEN);
7860 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
7861 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
7862 else
7863 port = 0;
7864#ifdef CONFIG_INET
7865 /* allocate a socket and port for it and use it */
7866 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
7867 IPPROTO_TCP, &cfg->sock, 1);
7868 if (err) {
7869 kfree(cfg);
7870 return err;
7871 }
7872 if (inet_csk_get_port(cfg->sock->sk, port)) {
7873 sock_release(cfg->sock);
7874 kfree(cfg);
7875 return -EADDRINUSE;
7876 }
7877 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
7878#else
7879 if (!port) {
7880 kfree(cfg);
7881 return -EINVAL;
7882 }
7883 cfg->src_port = port;
7884#endif
7885
7886 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
7887 cfg->payload_len = data_size;
7888 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
7889 memcpy((void *)cfg->payload,
7890 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
7891 data_size);
7892 if (seq)
7893 cfg->payload_seq = *seq;
7894 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
7895 cfg->wake_len = wake_size;
7896 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
7897 memcpy((void *)cfg->wake_data,
7898 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
7899 wake_size);
7900 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
7901 data_size + wake_size;
7902 memcpy((void *)cfg->wake_mask,
7903 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
7904 wake_mask_size);
7905 if (tok) {
7906 cfg->tokens_size = tokens_size;
7907 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
7908 }
7909
7910 trig->tcp = cfg;
7911
7912 return 0;
7913}
7914
Johannes Bergff1b6e62011-05-04 15:37:28 +02007915static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
7916{
7917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7918 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007919 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02007920 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02007921 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007922 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007923 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02007924
Johannes Berg964dc9e2013-06-03 17:25:34 +02007925 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02007926 return -EOPNOTSUPP;
7927
Johannes Bergae33bd82012-07-12 16:25:02 +02007928 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
7929 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007930 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02007931 goto set_wakeup;
7932 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02007933
7934 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
7935 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7936 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
7937 nl80211_wowlan_policy);
7938 if (err)
7939 return err;
7940
7941 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
7942 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
7943 return -EINVAL;
7944 new_triggers.any = true;
7945 }
7946
7947 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
7948 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
7949 return -EINVAL;
7950 new_triggers.disconnect = true;
7951 }
7952
7953 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
7954 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
7955 return -EINVAL;
7956 new_triggers.magic_pkt = true;
7957 }
7958
Johannes Berg77dbbb12011-07-13 10:48:55 +02007959 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
7960 return -EINVAL;
7961
7962 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
7963 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
7964 return -EINVAL;
7965 new_triggers.gtk_rekey_failure = true;
7966 }
7967
7968 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
7969 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
7970 return -EINVAL;
7971 new_triggers.eap_identity_req = true;
7972 }
7973
7974 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
7975 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
7976 return -EINVAL;
7977 new_triggers.four_way_handshake = true;
7978 }
7979
7980 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
7981 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
7982 return -EINVAL;
7983 new_triggers.rfkill_release = true;
7984 }
7985
Johannes Bergff1b6e62011-05-04 15:37:28 +02007986 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
7987 struct nlattr *pat;
7988 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007989 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007990 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02007991
7992 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
7993 rem)
7994 n_patterns++;
7995 if (n_patterns > wowlan->n_patterns)
7996 return -EINVAL;
7997
7998 new_triggers.patterns = kcalloc(n_patterns,
7999 sizeof(new_triggers.patterns[0]),
8000 GFP_KERNEL);
8001 if (!new_triggers.patterns)
8002 return -ENOMEM;
8003
8004 new_triggers.n_patterns = n_patterns;
8005 i = 0;
8006
8007 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8008 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008009 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8010 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008011 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008012 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8013 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008014 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008015 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008016 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008017 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008018 goto error;
8019 if (pat_len > wowlan->pattern_max_len ||
8020 pat_len < wowlan->pattern_min_len)
8021 goto error;
8022
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008023 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008024 pkt_offset = 0;
8025 else
8026 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008027 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008028 if (pkt_offset > wowlan->max_pkt_offset)
8029 goto error;
8030 new_triggers.patterns[i].pkt_offset = pkt_offset;
8031
Johannes Bergff1b6e62011-05-04 15:37:28 +02008032 new_triggers.patterns[i].mask =
8033 kmalloc(mask_len + pat_len, GFP_KERNEL);
8034 if (!new_triggers.patterns[i].mask) {
8035 err = -ENOMEM;
8036 goto error;
8037 }
8038 new_triggers.patterns[i].pattern =
8039 new_triggers.patterns[i].mask + mask_len;
8040 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008041 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008042 mask_len);
8043 new_triggers.patterns[i].pattern_len = pat_len;
8044 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008045 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008046 pat_len);
8047 i++;
8048 }
8049 }
8050
Johannes Berg2a0e0472013-01-23 22:57:40 +01008051 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8052 err = nl80211_parse_wowlan_tcp(
8053 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8054 &new_triggers);
8055 if (err)
8056 goto error;
8057 }
8058
Johannes Bergae33bd82012-07-12 16:25:02 +02008059 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8060 if (!ntrig) {
8061 err = -ENOMEM;
8062 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008063 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008064 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008065 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008066
Johannes Bergae33bd82012-07-12 16:25:02 +02008067 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008068 if (rdev->ops->set_wakeup &&
8069 prev_enabled != !!rdev->wiphy.wowlan_config)
8070 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008071
Johannes Bergff1b6e62011-05-04 15:37:28 +02008072 return 0;
8073 error:
8074 for (i = 0; i < new_triggers.n_patterns; i++)
8075 kfree(new_triggers.patterns[i].mask);
8076 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008077 if (new_triggers.tcp && new_triggers.tcp->sock)
8078 sock_release(new_triggers.tcp->sock);
8079 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008080 return err;
8081}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008082#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008083
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008084static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8085 struct cfg80211_registered_device *rdev)
8086{
8087 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8088 int i, j, pat_len;
8089 struct cfg80211_coalesce_rules *rule;
8090
8091 if (!rdev->coalesce->n_rules)
8092 return 0;
8093
8094 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8095 if (!nl_rules)
8096 return -ENOBUFS;
8097
8098 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8099 nl_rule = nla_nest_start(msg, i + 1);
8100 if (!nl_rule)
8101 return -ENOBUFS;
8102
8103 rule = &rdev->coalesce->rules[i];
8104 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8105 rule->delay))
8106 return -ENOBUFS;
8107
8108 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8109 rule->condition))
8110 return -ENOBUFS;
8111
8112 nl_pats = nla_nest_start(msg,
8113 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8114 if (!nl_pats)
8115 return -ENOBUFS;
8116
8117 for (j = 0; j < rule->n_patterns; j++) {
8118 nl_pat = nla_nest_start(msg, j + 1);
8119 if (!nl_pat)
8120 return -ENOBUFS;
8121 pat_len = rule->patterns[j].pattern_len;
8122 if (nla_put(msg, NL80211_PKTPAT_MASK,
8123 DIV_ROUND_UP(pat_len, 8),
8124 rule->patterns[j].mask) ||
8125 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8126 rule->patterns[j].pattern) ||
8127 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8128 rule->patterns[j].pkt_offset))
8129 return -ENOBUFS;
8130 nla_nest_end(msg, nl_pat);
8131 }
8132 nla_nest_end(msg, nl_pats);
8133 nla_nest_end(msg, nl_rule);
8134 }
8135 nla_nest_end(msg, nl_rules);
8136
8137 return 0;
8138}
8139
8140static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8141{
8142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8143 struct sk_buff *msg;
8144 void *hdr;
8145
8146 if (!rdev->wiphy.coalesce)
8147 return -EOPNOTSUPP;
8148
8149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8150 if (!msg)
8151 return -ENOMEM;
8152
8153 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8154 NL80211_CMD_GET_COALESCE);
8155 if (!hdr)
8156 goto nla_put_failure;
8157
8158 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8159 goto nla_put_failure;
8160
8161 genlmsg_end(msg, hdr);
8162 return genlmsg_reply(msg, info);
8163
8164nla_put_failure:
8165 nlmsg_free(msg);
8166 return -ENOBUFS;
8167}
8168
8169void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8170{
8171 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8172 int i, j;
8173 struct cfg80211_coalesce_rules *rule;
8174
8175 if (!coalesce)
8176 return;
8177
8178 for (i = 0; i < coalesce->n_rules; i++) {
8179 rule = &coalesce->rules[i];
8180 for (j = 0; j < rule->n_patterns; j++)
8181 kfree(rule->patterns[j].mask);
8182 kfree(rule->patterns);
8183 }
8184 kfree(coalesce->rules);
8185 kfree(coalesce);
8186 rdev->coalesce = NULL;
8187}
8188
8189static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8190 struct nlattr *rule,
8191 struct cfg80211_coalesce_rules *new_rule)
8192{
8193 int err, i;
8194 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8195 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8196 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8197 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8198
8199 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8200 nla_len(rule), nl80211_coalesce_policy);
8201 if (err)
8202 return err;
8203
8204 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8205 new_rule->delay =
8206 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8207 if (new_rule->delay > coalesce->max_delay)
8208 return -EINVAL;
8209
8210 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8211 new_rule->condition =
8212 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8213 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8214 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8215 return -EINVAL;
8216
8217 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8218 return -EINVAL;
8219
8220 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8221 rem)
8222 n_patterns++;
8223 if (n_patterns > coalesce->n_patterns)
8224 return -EINVAL;
8225
8226 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8227 GFP_KERNEL);
8228 if (!new_rule->patterns)
8229 return -ENOMEM;
8230
8231 new_rule->n_patterns = n_patterns;
8232 i = 0;
8233
8234 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8235 rem) {
8236 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8237 nla_len(pat), NULL);
8238 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8239 !pat_tb[NL80211_PKTPAT_PATTERN])
8240 return -EINVAL;
8241 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8242 mask_len = DIV_ROUND_UP(pat_len, 8);
8243 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8244 return -EINVAL;
8245 if (pat_len > coalesce->pattern_max_len ||
8246 pat_len < coalesce->pattern_min_len)
8247 return -EINVAL;
8248
8249 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8250 pkt_offset = 0;
8251 else
8252 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8253 if (pkt_offset > coalesce->max_pkt_offset)
8254 return -EINVAL;
8255 new_rule->patterns[i].pkt_offset = pkt_offset;
8256
8257 new_rule->patterns[i].mask =
8258 kmalloc(mask_len + pat_len, GFP_KERNEL);
8259 if (!new_rule->patterns[i].mask)
8260 return -ENOMEM;
8261 new_rule->patterns[i].pattern =
8262 new_rule->patterns[i].mask + mask_len;
8263 memcpy(new_rule->patterns[i].mask,
8264 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8265 new_rule->patterns[i].pattern_len = pat_len;
8266 memcpy(new_rule->patterns[i].pattern,
8267 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8268 i++;
8269 }
8270
8271 return 0;
8272}
8273
8274static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8275{
8276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8277 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8278 struct cfg80211_coalesce new_coalesce = {};
8279 struct cfg80211_coalesce *n_coalesce;
8280 int err, rem_rule, n_rules = 0, i, j;
8281 struct nlattr *rule;
8282 struct cfg80211_coalesce_rules *tmp_rule;
8283
8284 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8285 return -EOPNOTSUPP;
8286
8287 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8288 cfg80211_rdev_free_coalesce(rdev);
8289 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8290 return 0;
8291 }
8292
8293 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8294 rem_rule)
8295 n_rules++;
8296 if (n_rules > coalesce->n_rules)
8297 return -EINVAL;
8298
8299 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8300 GFP_KERNEL);
8301 if (!new_coalesce.rules)
8302 return -ENOMEM;
8303
8304 new_coalesce.n_rules = n_rules;
8305 i = 0;
8306
8307 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8308 rem_rule) {
8309 err = nl80211_parse_coalesce_rule(rdev, rule,
8310 &new_coalesce.rules[i]);
8311 if (err)
8312 goto error;
8313
8314 i++;
8315 }
8316
8317 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8318 if (err)
8319 goto error;
8320
8321 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8322 if (!n_coalesce) {
8323 err = -ENOMEM;
8324 goto error;
8325 }
8326 cfg80211_rdev_free_coalesce(rdev);
8327 rdev->coalesce = n_coalesce;
8328
8329 return 0;
8330error:
8331 for (i = 0; i < new_coalesce.n_rules; i++) {
8332 tmp_rule = &new_coalesce.rules[i];
8333 for (j = 0; j < tmp_rule->n_patterns; j++)
8334 kfree(tmp_rule->patterns[j].mask);
8335 kfree(tmp_rule->patterns);
8336 }
8337 kfree(new_coalesce.rules);
8338
8339 return err;
8340}
8341
Johannes Berge5497d72011-07-05 16:35:40 +02008342static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8343{
8344 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8345 struct net_device *dev = info->user_ptr[1];
8346 struct wireless_dev *wdev = dev->ieee80211_ptr;
8347 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8348 struct cfg80211_gtk_rekey_data rekey_data;
8349 int err;
8350
8351 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8352 return -EINVAL;
8353
8354 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8355 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8356 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8357 nl80211_rekey_policy);
8358 if (err)
8359 return err;
8360
8361 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8362 return -ERANGE;
8363 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8364 return -ERANGE;
8365 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8366 return -ERANGE;
8367
8368 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8369 NL80211_KEK_LEN);
8370 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8371 NL80211_KCK_LEN);
8372 memcpy(rekey_data.replay_ctr,
8373 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8374 NL80211_REPLAY_CTR_LEN);
8375
8376 wdev_lock(wdev);
8377 if (!wdev->current_bss) {
8378 err = -ENOTCONN;
8379 goto out;
8380 }
8381
8382 if (!rdev->ops->set_rekey_data) {
8383 err = -EOPNOTSUPP;
8384 goto out;
8385 }
8386
Hila Gonene35e4d22012-06-27 17:19:42 +03008387 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008388 out:
8389 wdev_unlock(wdev);
8390 return err;
8391}
8392
Johannes Berg28946da2011-11-04 11:18:12 +01008393static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8394 struct genl_info *info)
8395{
8396 struct net_device *dev = info->user_ptr[1];
8397 struct wireless_dev *wdev = dev->ieee80211_ptr;
8398
8399 if (wdev->iftype != NL80211_IFTYPE_AP &&
8400 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8401 return -EINVAL;
8402
Eric W. Biederman15e47302012-09-07 20:12:54 +00008403 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008404 return -EBUSY;
8405
Eric W. Biederman15e47302012-09-07 20:12:54 +00008406 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008407 return 0;
8408}
8409
Johannes Berg7f6cf312011-11-04 11:18:15 +01008410static int nl80211_probe_client(struct sk_buff *skb,
8411 struct genl_info *info)
8412{
8413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8414 struct net_device *dev = info->user_ptr[1];
8415 struct wireless_dev *wdev = dev->ieee80211_ptr;
8416 struct sk_buff *msg;
8417 void *hdr;
8418 const u8 *addr;
8419 u64 cookie;
8420 int err;
8421
8422 if (wdev->iftype != NL80211_IFTYPE_AP &&
8423 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8424 return -EOPNOTSUPP;
8425
8426 if (!info->attrs[NL80211_ATTR_MAC])
8427 return -EINVAL;
8428
8429 if (!rdev->ops->probe_client)
8430 return -EOPNOTSUPP;
8431
8432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8433 if (!msg)
8434 return -ENOMEM;
8435
Eric W. Biederman15e47302012-09-07 20:12:54 +00008436 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008437 NL80211_CMD_PROBE_CLIENT);
8438
8439 if (IS_ERR(hdr)) {
8440 err = PTR_ERR(hdr);
8441 goto free_msg;
8442 }
8443
8444 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8445
Hila Gonene35e4d22012-06-27 17:19:42 +03008446 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008447 if (err)
8448 goto free_msg;
8449
David S. Miller9360ffd2012-03-29 04:41:26 -04008450 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8451 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008452
8453 genlmsg_end(msg, hdr);
8454
8455 return genlmsg_reply(msg, info);
8456
8457 nla_put_failure:
8458 err = -ENOBUFS;
8459 free_msg:
8460 nlmsg_free(msg);
8461 return err;
8462}
8463
Johannes Berg5e7602302011-11-04 11:18:17 +01008464static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8465{
8466 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008467 struct cfg80211_beacon_registration *reg, *nreg;
8468 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008469
8470 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8471 return -EOPNOTSUPP;
8472
Ben Greear37c73b52012-10-26 14:49:25 -07008473 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8474 if (!nreg)
8475 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01008476
Ben Greear37c73b52012-10-26 14:49:25 -07008477 /* First, check if already registered. */
8478 spin_lock_bh(&rdev->beacon_registrations_lock);
8479 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8480 if (reg->nlportid == info->snd_portid) {
8481 rv = -EALREADY;
8482 goto out_err;
8483 }
8484 }
8485 /* Add it to the list */
8486 nreg->nlportid = info->snd_portid;
8487 list_add(&nreg->list, &rdev->beacon_registrations);
8488
8489 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01008490
8491 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008492out_err:
8493 spin_unlock_bh(&rdev->beacon_registrations_lock);
8494 kfree(nreg);
8495 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01008496}
8497
Johannes Berg98104fde2012-06-16 00:19:54 +02008498static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8499{
8500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8501 struct wireless_dev *wdev = info->user_ptr[1];
8502 int err;
8503
8504 if (!rdev->ops->start_p2p_device)
8505 return -EOPNOTSUPP;
8506
8507 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8508 return -EOPNOTSUPP;
8509
8510 if (wdev->p2p_started)
8511 return 0;
8512
Johannes Berg98104fde2012-06-16 00:19:54 +02008513 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008514 if (err)
8515 return err;
8516
Johannes Bergeeb126e2012-10-23 15:16:50 +02008517 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008518 if (err)
8519 return err;
8520
8521 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008522 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008523
8524 return 0;
8525}
8526
8527static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8528{
8529 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8530 struct wireless_dev *wdev = info->user_ptr[1];
8531
8532 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8533 return -EOPNOTSUPP;
8534
8535 if (!rdev->ops->stop_p2p_device)
8536 return -EOPNOTSUPP;
8537
Johannes Bergf9f47522013-03-19 15:04:07 +01008538 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008539
8540 return 0;
8541}
8542
Johannes Berg3713b4e2013-02-14 16:19:38 +01008543static int nl80211_get_protocol_features(struct sk_buff *skb,
8544 struct genl_info *info)
8545{
8546 void *hdr;
8547 struct sk_buff *msg;
8548
8549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8550 if (!msg)
8551 return -ENOMEM;
8552
8553 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8554 NL80211_CMD_GET_PROTOCOL_FEATURES);
8555 if (!hdr)
8556 goto nla_put_failure;
8557
8558 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8559 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8560 goto nla_put_failure;
8561
8562 genlmsg_end(msg, hdr);
8563 return genlmsg_reply(msg, info);
8564
8565 nla_put_failure:
8566 kfree_skb(msg);
8567 return -ENOBUFS;
8568}
8569
Jouni Malinen355199e2013-02-27 17:14:27 +02008570static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8571{
8572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8573 struct cfg80211_update_ft_ies_params ft_params;
8574 struct net_device *dev = info->user_ptr[1];
8575
8576 if (!rdev->ops->update_ft_ies)
8577 return -EOPNOTSUPP;
8578
8579 if (!info->attrs[NL80211_ATTR_MDID] ||
8580 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8581 return -EINVAL;
8582
8583 memset(&ft_params, 0, sizeof(ft_params));
8584 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8585 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8586 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8587
8588 return rdev_update_ft_ies(rdev, dev, &ft_params);
8589}
8590
Arend van Spriel5de17982013-04-18 15:49:00 +02008591static int nl80211_crit_protocol_start(struct sk_buff *skb,
8592 struct genl_info *info)
8593{
8594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8595 struct wireless_dev *wdev = info->user_ptr[1];
8596 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8597 u16 duration;
8598 int ret;
8599
8600 if (!rdev->ops->crit_proto_start)
8601 return -EOPNOTSUPP;
8602
8603 if (WARN_ON(!rdev->ops->crit_proto_stop))
8604 return -EINVAL;
8605
8606 if (rdev->crit_proto_nlportid)
8607 return -EBUSY;
8608
8609 /* determine protocol if provided */
8610 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8611 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8612
8613 if (proto >= NUM_NL80211_CRIT_PROTO)
8614 return -EINVAL;
8615
8616 /* timeout must be provided */
8617 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8618 return -EINVAL;
8619
8620 duration =
8621 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8622
8623 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8624 return -ERANGE;
8625
8626 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8627 if (!ret)
8628 rdev->crit_proto_nlportid = info->snd_portid;
8629
8630 return ret;
8631}
8632
8633static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8634 struct genl_info *info)
8635{
8636 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8637 struct wireless_dev *wdev = info->user_ptr[1];
8638
8639 if (!rdev->ops->crit_proto_stop)
8640 return -EOPNOTSUPP;
8641
8642 if (rdev->crit_proto_nlportid) {
8643 rdev->crit_proto_nlportid = 0;
8644 rdev_crit_proto_stop(rdev, wdev);
8645 }
8646 return 0;
8647}
8648
Johannes Berg4c476992010-10-04 21:36:35 +02008649#define NL80211_FLAG_NEED_WIPHY 0x01
8650#define NL80211_FLAG_NEED_NETDEV 0x02
8651#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02008652#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8653#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8654 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02008655#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02008656/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02008657#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8658 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02008659
8660static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb,
8661 struct genl_info *info)
8662{
8663 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02008664 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008665 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02008666 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
8667
8668 if (rtnl)
8669 rtnl_lock();
8670
8671 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02008672 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02008673 if (IS_ERR(rdev)) {
8674 if (rtnl)
8675 rtnl_unlock();
8676 return PTR_ERR(rdev);
8677 }
8678 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02008679 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
8680 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02008681 ASSERT_RTNL();
8682
Johannes Berg89a54e42012-06-15 14:33:17 +02008683 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
8684 info->attrs);
8685 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02008686 if (rtnl)
8687 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02008688 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02008689 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008690
Johannes Berg89a54e42012-06-15 14:33:17 +02008691 dev = wdev->netdev;
8692 rdev = wiphy_to_dev(wdev->wiphy);
8693
Johannes Berg1bf614e2012-06-15 15:23:36 +02008694 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
8695 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008696 if (rtnl)
8697 rtnl_unlock();
8698 return -EINVAL;
8699 }
8700
8701 info->user_ptr[1] = dev;
8702 } else {
8703 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02008704 }
Johannes Berg89a54e42012-06-15 14:33:17 +02008705
Johannes Berg1bf614e2012-06-15 15:23:36 +02008706 if (dev) {
8707 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
8708 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02008709 if (rtnl)
8710 rtnl_unlock();
8711 return -ENETDOWN;
8712 }
8713
8714 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008715 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
8716 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02008717 if (rtnl)
8718 rtnl_unlock();
8719 return -ENETDOWN;
8720 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02008721 }
8722
Johannes Berg4c476992010-10-04 21:36:35 +02008723 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008724 }
8725
8726 return 0;
8727}
8728
8729static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb,
8730 struct genl_info *info)
8731{
Johannes Berg1bf614e2012-06-15 15:23:36 +02008732 if (info->user_ptr[1]) {
8733 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
8734 struct wireless_dev *wdev = info->user_ptr[1];
8735
8736 if (wdev->netdev)
8737 dev_put(wdev->netdev);
8738 } else {
8739 dev_put(info->user_ptr[1]);
8740 }
8741 }
Johannes Berg4c476992010-10-04 21:36:35 +02008742 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
8743 rtnl_unlock();
8744}
8745
Johannes Berg55682962007-09-20 13:09:35 -04008746static struct genl_ops nl80211_ops[] = {
8747 {
8748 .cmd = NL80211_CMD_GET_WIPHY,
8749 .doit = nl80211_get_wiphy,
8750 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02008751 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04008752 .policy = nl80211_policy,
8753 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008754 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8755 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008756 },
8757 {
8758 .cmd = NL80211_CMD_SET_WIPHY,
8759 .doit = nl80211_set_wiphy,
8760 .policy = nl80211_policy,
8761 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008762 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008763 },
8764 {
8765 .cmd = NL80211_CMD_GET_INTERFACE,
8766 .doit = nl80211_get_interface,
8767 .dumpit = nl80211_dump_interface,
8768 .policy = nl80211_policy,
8769 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02008770 .internal_flags = NL80211_FLAG_NEED_WDEV |
8771 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008772 },
8773 {
8774 .cmd = NL80211_CMD_SET_INTERFACE,
8775 .doit = nl80211_set_interface,
8776 .policy = nl80211_policy,
8777 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008778 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8779 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008780 },
8781 {
8782 .cmd = NL80211_CMD_NEW_INTERFACE,
8783 .doit = nl80211_new_interface,
8784 .policy = nl80211_policy,
8785 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02008786 .internal_flags = NL80211_FLAG_NEED_WIPHY |
8787 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008788 },
8789 {
8790 .cmd = NL80211_CMD_DEL_INTERFACE,
8791 .doit = nl80211_del_interface,
8792 .policy = nl80211_policy,
8793 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02008794 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02008795 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04008796 },
Johannes Berg41ade002007-12-19 02:03:29 +01008797 {
8798 .cmd = NL80211_CMD_GET_KEY,
8799 .doit = nl80211_get_key,
8800 .policy = nl80211_policy,
8801 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008802 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008803 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008804 },
8805 {
8806 .cmd = NL80211_CMD_SET_KEY,
8807 .doit = nl80211_set_key,
8808 .policy = nl80211_policy,
8809 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008811 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008812 },
8813 {
8814 .cmd = NL80211_CMD_NEW_KEY,
8815 .doit = nl80211_new_key,
8816 .policy = nl80211_policy,
8817 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008819 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008820 },
8821 {
8822 .cmd = NL80211_CMD_DEL_KEY,
8823 .doit = nl80211_del_key,
8824 .policy = nl80211_policy,
8825 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008826 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008827 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01008828 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01008829 {
8830 .cmd = NL80211_CMD_SET_BEACON,
8831 .policy = nl80211_policy,
8832 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008833 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008834 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008835 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008836 },
8837 {
Johannes Berg88600202012-02-13 15:17:18 +01008838 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008839 .policy = nl80211_policy,
8840 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008841 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008843 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008844 },
8845 {
Johannes Berg88600202012-02-13 15:17:18 +01008846 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008847 .policy = nl80211_policy,
8848 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01008849 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008851 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01008852 },
Johannes Berg5727ef12007-12-19 02:03:34 +01008853 {
8854 .cmd = NL80211_CMD_GET_STATION,
8855 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008856 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01008857 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02008858 .internal_flags = NL80211_FLAG_NEED_NETDEV |
8859 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008860 },
8861 {
8862 .cmd = NL80211_CMD_SET_STATION,
8863 .doit = nl80211_set_station,
8864 .policy = nl80211_policy,
8865 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008866 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008867 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008868 },
8869 {
8870 .cmd = NL80211_CMD_NEW_STATION,
8871 .doit = nl80211_new_station,
8872 .policy = nl80211_policy,
8873 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008874 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008875 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008876 },
8877 {
8878 .cmd = NL80211_CMD_DEL_STATION,
8879 .doit = nl80211_del_station,
8880 .policy = nl80211_policy,
8881 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008883 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01008884 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008885 {
8886 .cmd = NL80211_CMD_GET_MPATH,
8887 .doit = nl80211_get_mpath,
8888 .dumpit = nl80211_dump_mpath,
8889 .policy = nl80211_policy,
8890 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008891 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008892 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008893 },
8894 {
8895 .cmd = NL80211_CMD_SET_MPATH,
8896 .doit = nl80211_set_mpath,
8897 .policy = nl80211_policy,
8898 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008899 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008900 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008901 },
8902 {
8903 .cmd = NL80211_CMD_NEW_MPATH,
8904 .doit = nl80211_new_mpath,
8905 .policy = nl80211_policy,
8906 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008908 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008909 },
8910 {
8911 .cmd = NL80211_CMD_DEL_MPATH,
8912 .doit = nl80211_del_mpath,
8913 .policy = nl80211_policy,
8914 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008915 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008916 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01008917 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008918 {
8919 .cmd = NL80211_CMD_SET_BSS,
8920 .doit = nl80211_set_bss,
8921 .policy = nl80211_policy,
8922 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008923 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008924 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03008925 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008926 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008927 .cmd = NL80211_CMD_GET_REG,
8928 .doit = nl80211_get_reg,
8929 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008930 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08008931 /* can be retrieved by unprivileged users */
8932 },
8933 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008934 .cmd = NL80211_CMD_SET_REG,
8935 .doit = nl80211_set_reg,
8936 .policy = nl80211_policy,
8937 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02008938 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07008939 },
8940 {
8941 .cmd = NL80211_CMD_REQ_SET_REG,
8942 .doit = nl80211_req_set_reg,
8943 .policy = nl80211_policy,
8944 .flags = GENL_ADMIN_PERM,
8945 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008946 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008947 .cmd = NL80211_CMD_GET_MESH_CONFIG,
8948 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008949 .policy = nl80211_policy,
8950 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02008951 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008952 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008953 },
8954 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008955 .cmd = NL80211_CMD_SET_MESH_CONFIG,
8956 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008957 .policy = nl80211_policy,
8958 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01008959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008960 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07008961 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02008962 {
Johannes Berg2a519312009-02-10 21:25:55 +01008963 .cmd = NL80211_CMD_TRIGGER_SCAN,
8964 .doit = nl80211_trigger_scan,
8965 .policy = nl80211_policy,
8966 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02008967 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008968 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01008969 },
8970 {
8971 .cmd = NL80211_CMD_GET_SCAN,
8972 .policy = nl80211_policy,
8973 .dumpit = nl80211_dump_scan,
8974 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02008975 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008976 .cmd = NL80211_CMD_START_SCHED_SCAN,
8977 .doit = nl80211_start_sched_scan,
8978 .policy = nl80211_policy,
8979 .flags = GENL_ADMIN_PERM,
8980 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8981 NL80211_FLAG_NEED_RTNL,
8982 },
8983 {
8984 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
8985 .doit = nl80211_stop_sched_scan,
8986 .policy = nl80211_policy,
8987 .flags = GENL_ADMIN_PERM,
8988 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
8989 NL80211_FLAG_NEED_RTNL,
8990 },
8991 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02008992 .cmd = NL80211_CMD_AUTHENTICATE,
8993 .doit = nl80211_authenticate,
8994 .policy = nl80211_policy,
8995 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02008996 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02008997 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02008998 },
8999 {
9000 .cmd = NL80211_CMD_ASSOCIATE,
9001 .doit = nl80211_associate,
9002 .policy = nl80211_policy,
9003 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009004 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009005 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009006 },
9007 {
9008 .cmd = NL80211_CMD_DEAUTHENTICATE,
9009 .doit = nl80211_deauthenticate,
9010 .policy = nl80211_policy,
9011 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009012 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009013 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009014 },
9015 {
9016 .cmd = NL80211_CMD_DISASSOCIATE,
9017 .doit = nl80211_disassociate,
9018 .policy = nl80211_policy,
9019 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009020 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009021 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009022 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009023 {
9024 .cmd = NL80211_CMD_JOIN_IBSS,
9025 .doit = nl80211_join_ibss,
9026 .policy = nl80211_policy,
9027 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009028 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009029 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009030 },
9031 {
9032 .cmd = NL80211_CMD_LEAVE_IBSS,
9033 .doit = nl80211_leave_ibss,
9034 .policy = nl80211_policy,
9035 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009036 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009037 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009038 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009039#ifdef CONFIG_NL80211_TESTMODE
9040 {
9041 .cmd = NL80211_CMD_TESTMODE,
9042 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009043 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009044 .policy = nl80211_policy,
9045 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009046 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9047 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009048 },
9049#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009050 {
9051 .cmd = NL80211_CMD_CONNECT,
9052 .doit = nl80211_connect,
9053 .policy = nl80211_policy,
9054 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009056 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009057 },
9058 {
9059 .cmd = NL80211_CMD_DISCONNECT,
9060 .doit = nl80211_disconnect,
9061 .policy = nl80211_policy,
9062 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009063 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009064 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009065 },
Johannes Berg463d0182009-07-14 00:33:35 +02009066 {
9067 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9068 .doit = nl80211_wiphy_netns,
9069 .policy = nl80211_policy,
9070 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009071 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9072 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009073 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009074 {
9075 .cmd = NL80211_CMD_GET_SURVEY,
9076 .policy = nl80211_policy,
9077 .dumpit = nl80211_dump_survey,
9078 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009079 {
9080 .cmd = NL80211_CMD_SET_PMKSA,
9081 .doit = nl80211_setdel_pmksa,
9082 .policy = nl80211_policy,
9083 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009084 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009085 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009086 },
9087 {
9088 .cmd = NL80211_CMD_DEL_PMKSA,
9089 .doit = nl80211_setdel_pmksa,
9090 .policy = nl80211_policy,
9091 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009093 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009094 },
9095 {
9096 .cmd = NL80211_CMD_FLUSH_PMKSA,
9097 .doit = nl80211_flush_pmksa,
9098 .policy = nl80211_policy,
9099 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009101 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009102 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009103 {
9104 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9105 .doit = nl80211_remain_on_channel,
9106 .policy = nl80211_policy,
9107 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009108 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009109 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009110 },
9111 {
9112 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9113 .doit = nl80211_cancel_remain_on_channel,
9114 .policy = nl80211_policy,
9115 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009116 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009117 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009118 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009119 {
9120 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9121 .doit = nl80211_set_tx_bitrate_mask,
9122 .policy = nl80211_policy,
9123 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009124 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9125 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009126 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009127 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009128 .cmd = NL80211_CMD_REGISTER_FRAME,
9129 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009130 .policy = nl80211_policy,
9131 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009132 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009133 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009134 },
9135 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009136 .cmd = NL80211_CMD_FRAME,
9137 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009138 .policy = nl80211_policy,
9139 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009140 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009141 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009142 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009143 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009144 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9145 .doit = nl80211_tx_mgmt_cancel_wait,
9146 .policy = nl80211_policy,
9147 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009148 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009149 NL80211_FLAG_NEED_RTNL,
9150 },
9151 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009152 .cmd = NL80211_CMD_SET_POWER_SAVE,
9153 .doit = nl80211_set_power_save,
9154 .policy = nl80211_policy,
9155 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009156 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9157 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009158 },
9159 {
9160 .cmd = NL80211_CMD_GET_POWER_SAVE,
9161 .doit = nl80211_get_power_save,
9162 .policy = nl80211_policy,
9163 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009164 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9165 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009166 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009167 {
9168 .cmd = NL80211_CMD_SET_CQM,
9169 .doit = nl80211_set_cqm,
9170 .policy = nl80211_policy,
9171 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009172 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9173 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009174 },
Johannes Bergf444de02010-05-05 15:25:02 +02009175 {
9176 .cmd = NL80211_CMD_SET_CHANNEL,
9177 .doit = nl80211_set_channel,
9178 .policy = nl80211_policy,
9179 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009180 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9181 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009182 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009183 {
9184 .cmd = NL80211_CMD_SET_WDS_PEER,
9185 .doit = nl80211_set_wds_peer,
9186 .policy = nl80211_policy,
9187 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009188 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9189 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009190 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009191 {
9192 .cmd = NL80211_CMD_JOIN_MESH,
9193 .doit = nl80211_join_mesh,
9194 .policy = nl80211_policy,
9195 .flags = GENL_ADMIN_PERM,
9196 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9197 NL80211_FLAG_NEED_RTNL,
9198 },
9199 {
9200 .cmd = NL80211_CMD_LEAVE_MESH,
9201 .doit = nl80211_leave_mesh,
9202 .policy = nl80211_policy,
9203 .flags = GENL_ADMIN_PERM,
9204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9205 NL80211_FLAG_NEED_RTNL,
9206 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009207#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009208 {
9209 .cmd = NL80211_CMD_GET_WOWLAN,
9210 .doit = nl80211_get_wowlan,
9211 .policy = nl80211_policy,
9212 /* can be retrieved by unprivileged users */
9213 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9214 NL80211_FLAG_NEED_RTNL,
9215 },
9216 {
9217 .cmd = NL80211_CMD_SET_WOWLAN,
9218 .doit = nl80211_set_wowlan,
9219 .policy = nl80211_policy,
9220 .flags = GENL_ADMIN_PERM,
9221 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9222 NL80211_FLAG_NEED_RTNL,
9223 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009224#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009225 {
9226 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9227 .doit = nl80211_set_rekey_data,
9228 .policy = nl80211_policy,
9229 .flags = GENL_ADMIN_PERM,
9230 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9231 NL80211_FLAG_NEED_RTNL,
9232 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009233 {
9234 .cmd = NL80211_CMD_TDLS_MGMT,
9235 .doit = nl80211_tdls_mgmt,
9236 .policy = nl80211_policy,
9237 .flags = GENL_ADMIN_PERM,
9238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9239 NL80211_FLAG_NEED_RTNL,
9240 },
9241 {
9242 .cmd = NL80211_CMD_TDLS_OPER,
9243 .doit = nl80211_tdls_oper,
9244 .policy = nl80211_policy,
9245 .flags = GENL_ADMIN_PERM,
9246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9247 NL80211_FLAG_NEED_RTNL,
9248 },
Johannes Berg28946da2011-11-04 11:18:12 +01009249 {
9250 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9251 .doit = nl80211_register_unexpected_frame,
9252 .policy = nl80211_policy,
9253 .flags = GENL_ADMIN_PERM,
9254 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9255 NL80211_FLAG_NEED_RTNL,
9256 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009257 {
9258 .cmd = NL80211_CMD_PROBE_CLIENT,
9259 .doit = nl80211_probe_client,
9260 .policy = nl80211_policy,
9261 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009262 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009263 NL80211_FLAG_NEED_RTNL,
9264 },
Johannes Berg5e7602302011-11-04 11:18:17 +01009265 {
9266 .cmd = NL80211_CMD_REGISTER_BEACONS,
9267 .doit = nl80211_register_beacons,
9268 .policy = nl80211_policy,
9269 .flags = GENL_ADMIN_PERM,
9270 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9271 NL80211_FLAG_NEED_RTNL,
9272 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009273 {
9274 .cmd = NL80211_CMD_SET_NOACK_MAP,
9275 .doit = nl80211_set_noack_map,
9276 .policy = nl80211_policy,
9277 .flags = GENL_ADMIN_PERM,
9278 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9279 NL80211_FLAG_NEED_RTNL,
9280 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009281 {
9282 .cmd = NL80211_CMD_START_P2P_DEVICE,
9283 .doit = nl80211_start_p2p_device,
9284 .policy = nl80211_policy,
9285 .flags = GENL_ADMIN_PERM,
9286 .internal_flags = NL80211_FLAG_NEED_WDEV |
9287 NL80211_FLAG_NEED_RTNL,
9288 },
9289 {
9290 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9291 .doit = nl80211_stop_p2p_device,
9292 .policy = nl80211_policy,
9293 .flags = GENL_ADMIN_PERM,
9294 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9295 NL80211_FLAG_NEED_RTNL,
9296 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009297 {
9298 .cmd = NL80211_CMD_SET_MCAST_RATE,
9299 .doit = nl80211_set_mcast_rate,
9300 .policy = nl80211_policy,
9301 .flags = GENL_ADMIN_PERM,
9302 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9303 NL80211_FLAG_NEED_RTNL,
9304 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309305 {
9306 .cmd = NL80211_CMD_SET_MAC_ACL,
9307 .doit = nl80211_set_mac_acl,
9308 .policy = nl80211_policy,
9309 .flags = GENL_ADMIN_PERM,
9310 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9311 NL80211_FLAG_NEED_RTNL,
9312 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009313 {
9314 .cmd = NL80211_CMD_RADAR_DETECT,
9315 .doit = nl80211_start_radar_detection,
9316 .policy = nl80211_policy,
9317 .flags = GENL_ADMIN_PERM,
9318 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9319 NL80211_FLAG_NEED_RTNL,
9320 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009321 {
9322 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9323 .doit = nl80211_get_protocol_features,
9324 .policy = nl80211_policy,
9325 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009326 {
9327 .cmd = NL80211_CMD_UPDATE_FT_IES,
9328 .doit = nl80211_update_ft_ies,
9329 .policy = nl80211_policy,
9330 .flags = GENL_ADMIN_PERM,
9331 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9332 NL80211_FLAG_NEED_RTNL,
9333 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009334 {
9335 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9336 .doit = nl80211_crit_protocol_start,
9337 .policy = nl80211_policy,
9338 .flags = GENL_ADMIN_PERM,
9339 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9340 NL80211_FLAG_NEED_RTNL,
9341 },
9342 {
9343 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9344 .doit = nl80211_crit_protocol_stop,
9345 .policy = nl80211_policy,
9346 .flags = GENL_ADMIN_PERM,
9347 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9348 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009349 },
9350 {
9351 .cmd = NL80211_CMD_GET_COALESCE,
9352 .doit = nl80211_get_coalesce,
9353 .policy = nl80211_policy,
9354 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9355 NL80211_FLAG_NEED_RTNL,
9356 },
9357 {
9358 .cmd = NL80211_CMD_SET_COALESCE,
9359 .doit = nl80211_set_coalesce,
9360 .policy = nl80211_policy,
9361 .flags = GENL_ADMIN_PERM,
9362 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9363 NL80211_FLAG_NEED_RTNL,
Arend van Spriel5de17982013-04-18 15:49:00 +02009364 }
Johannes Berg55682962007-09-20 13:09:35 -04009365};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009366
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009367static struct genl_multicast_group nl80211_mlme_mcgrp = {
9368 .name = "mlme",
9369};
Johannes Berg55682962007-09-20 13:09:35 -04009370
9371/* multicast groups */
9372static struct genl_multicast_group nl80211_config_mcgrp = {
9373 .name = "config",
9374};
Johannes Berg2a519312009-02-10 21:25:55 +01009375static struct genl_multicast_group nl80211_scan_mcgrp = {
9376 .name = "scan",
9377};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009378static struct genl_multicast_group nl80211_regulatory_mcgrp = {
9379 .name = "regulatory",
9380};
Johannes Berg55682962007-09-20 13:09:35 -04009381
9382/* notification functions */
9383
9384void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9385{
9386 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009387 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009388
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009389 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009390 if (!msg)
9391 return;
9392
Johannes Berg86e8cf92013-06-19 10:57:22 +02009393 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009394 nlmsg_free(msg);
9395 return;
9396 }
9397
Johannes Berg463d0182009-07-14 00:33:35 +02009398 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9399 nl80211_config_mcgrp.id, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009400}
9401
Johannes Berg362a4152009-05-24 16:43:15 +02009402static int nl80211_add_scan_req(struct sk_buff *msg,
9403 struct cfg80211_registered_device *rdev)
9404{
9405 struct cfg80211_scan_request *req = rdev->scan_req;
9406 struct nlattr *nest;
9407 int i;
9408
9409 if (WARN_ON(!req))
9410 return 0;
9411
9412 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9413 if (!nest)
9414 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009415 for (i = 0; i < req->n_ssids; i++) {
9416 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9417 goto nla_put_failure;
9418 }
Johannes Berg362a4152009-05-24 16:43:15 +02009419 nla_nest_end(msg, nest);
9420
9421 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9422 if (!nest)
9423 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009424 for (i = 0; i < req->n_channels; i++) {
9425 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9426 goto nla_put_failure;
9427 }
Johannes Berg362a4152009-05-24 16:43:15 +02009428 nla_nest_end(msg, nest);
9429
David S. Miller9360ffd2012-03-29 04:41:26 -04009430 if (req->ie &&
9431 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9432 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009433
Sam Lefflered4737712012-10-11 21:03:31 -07009434 if (req->flags)
9435 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags);
9436
Johannes Berg362a4152009-05-24 16:43:15 +02009437 return 0;
9438 nla_put_failure:
9439 return -ENOBUFS;
9440}
9441
Johannes Berga538e2d2009-06-16 19:56:42 +02009442static int nl80211_send_scan_msg(struct sk_buff *msg,
9443 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009444 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009445 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009446 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009447{
9448 void *hdr;
9449
Eric W. Biederman15e47302012-09-07 20:12:54 +00009450 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009451 if (!hdr)
9452 return -1;
9453
David S. Miller9360ffd2012-03-29 04:41:26 -04009454 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009455 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9456 wdev->netdev->ifindex)) ||
9457 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009458 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009459
Johannes Berg362a4152009-05-24 16:43:15 +02009460 /* ignore errors and send incomplete event anyway */
9461 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009462
9463 return genlmsg_end(msg, hdr);
9464
9465 nla_put_failure:
9466 genlmsg_cancel(msg, hdr);
9467 return -EMSGSIZE;
9468}
9469
Luciano Coelho807f8a82011-05-11 17:09:35 +03009470static int
9471nl80211_send_sched_scan_msg(struct sk_buff *msg,
9472 struct cfg80211_registered_device *rdev,
9473 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009474 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009475{
9476 void *hdr;
9477
Eric W. Biederman15e47302012-09-07 20:12:54 +00009478 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009479 if (!hdr)
9480 return -1;
9481
David S. Miller9360ffd2012-03-29 04:41:26 -04009482 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9483 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9484 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009485
9486 return genlmsg_end(msg, hdr);
9487
9488 nla_put_failure:
9489 genlmsg_cancel(msg, hdr);
9490 return -EMSGSIZE;
9491}
9492
Johannes Berga538e2d2009-06-16 19:56:42 +02009493void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009494 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009495{
9496 struct sk_buff *msg;
9497
Thomas Graf58050fc2012-06-28 03:57:45 +00009498 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009499 if (!msg)
9500 return;
9501
Johannes Bergfd014282012-06-18 19:17:03 +02009502 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009503 NL80211_CMD_TRIGGER_SCAN) < 0) {
9504 nlmsg_free(msg);
9505 return;
9506 }
9507
Johannes Berg463d0182009-07-14 00:33:35 +02009508 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9509 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009510}
9511
Johannes Berg2a519312009-02-10 21:25:55 +01009512void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009513 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009514{
9515 struct sk_buff *msg;
9516
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009517 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009518 if (!msg)
9519 return;
9520
Johannes Bergfd014282012-06-18 19:17:03 +02009521 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009522 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009523 nlmsg_free(msg);
9524 return;
9525 }
9526
Johannes Berg463d0182009-07-14 00:33:35 +02009527 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9528 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009529}
9530
9531void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009532 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009533{
9534 struct sk_buff *msg;
9535
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009536 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009537 if (!msg)
9538 return;
9539
Johannes Bergfd014282012-06-18 19:17:03 +02009540 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009541 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009542 nlmsg_free(msg);
9543 return;
9544 }
9545
Johannes Berg463d0182009-07-14 00:33:35 +02009546 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9547 nl80211_scan_mcgrp.id, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009548}
9549
Luciano Coelho807f8a82011-05-11 17:09:35 +03009550void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9551 struct net_device *netdev)
9552{
9553 struct sk_buff *msg;
9554
9555 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9556 if (!msg)
9557 return;
9558
9559 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9560 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9561 nlmsg_free(msg);
9562 return;
9563 }
9564
9565 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9566 nl80211_scan_mcgrp.id, GFP_KERNEL);
9567}
9568
9569void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9570 struct net_device *netdev, u32 cmd)
9571{
9572 struct sk_buff *msg;
9573
Thomas Graf58050fc2012-06-28 03:57:45 +00009574 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009575 if (!msg)
9576 return;
9577
9578 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9579 nlmsg_free(msg);
9580 return;
9581 }
9582
9583 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9584 nl80211_scan_mcgrp.id, GFP_KERNEL);
9585}
9586
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009587/*
9588 * This can happen on global regulatory changes or device specific settings
9589 * based on custom world regulatory domains.
9590 */
9591void nl80211_send_reg_change_event(struct regulatory_request *request)
9592{
9593 struct sk_buff *msg;
9594 void *hdr;
9595
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009597 if (!msg)
9598 return;
9599
9600 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
9601 if (!hdr) {
9602 nlmsg_free(msg);
9603 return;
9604 }
9605
9606 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -04009607 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
9608 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009609
David S. Miller9360ffd2012-03-29 04:41:26 -04009610 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
9611 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9612 NL80211_REGDOM_TYPE_WORLD))
9613 goto nla_put_failure;
9614 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
9615 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9616 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
9617 goto nla_put_failure;
9618 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
9619 request->intersect) {
9620 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9621 NL80211_REGDOM_TYPE_INTERSECTION))
9622 goto nla_put_failure;
9623 } else {
9624 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
9625 NL80211_REGDOM_TYPE_COUNTRY) ||
9626 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
9627 request->alpha2))
9628 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009629 }
9630
Johannes Bergf4173762012-12-03 18:23:37 +01009631 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009632 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
9633 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009634
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009635 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009636
Johannes Bergbc43b282009-07-25 10:54:13 +02009637 rcu_read_lock();
Johannes Berg463d0182009-07-14 00:33:35 +02009638 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
Johannes Bergbc43b282009-07-25 10:54:13 +02009639 GFP_ATOMIC);
9640 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04009641
9642 return;
9643
9644nla_put_failure:
9645 genlmsg_cancel(msg, hdr);
9646 nlmsg_free(msg);
9647}
9648
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009649static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
9650 struct net_device *netdev,
9651 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009652 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009653{
9654 struct sk_buff *msg;
9655 void *hdr;
9656
Johannes Berge6d6e342009-07-01 21:26:47 +02009657 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009658 if (!msg)
9659 return;
9660
9661 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9662 if (!hdr) {
9663 nlmsg_free(msg);
9664 return;
9665 }
9666
David S. Miller9360ffd2012-03-29 04:41:26 -04009667 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9668 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9669 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
9670 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009671
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009672 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009673
Johannes Berg463d0182009-07-14 00:33:35 +02009674 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9675 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009676 return;
9677
9678 nla_put_failure:
9679 genlmsg_cancel(msg, hdr);
9680 nlmsg_free(msg);
9681}
9682
9683void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009684 struct net_device *netdev, const u8 *buf,
9685 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009686{
9687 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009688 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009689}
9690
9691void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
9692 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009693 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009694{
Johannes Berge6d6e342009-07-01 21:26:47 +02009695 nl80211_send_mlme_event(rdev, netdev, buf, len,
9696 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009697}
9698
Jouni Malinen53b46b82009-03-27 20:53:56 +02009699void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009700 struct net_device *netdev, const u8 *buf,
9701 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009702{
9703 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009704 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009705}
9706
Jouni Malinen53b46b82009-03-27 20:53:56 +02009707void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
9708 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +02009709 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009710{
9711 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +02009712 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02009713}
9714
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009715void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
9716 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +02009717{
Johannes Berg947add32013-02-22 22:05:20 +01009718 struct wireless_dev *wdev = dev->ieee80211_ptr;
9719 struct wiphy *wiphy = wdev->wiphy;
9720 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009721 const struct ieee80211_mgmt *mgmt = (void *)buf;
9722 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +02009723
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009724 if (WARN_ON(len < 2))
9725 return;
9726
9727 if (ieee80211_is_deauth(mgmt->frame_control))
9728 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
9729 else
9730 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
9731
9732 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
9733 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009734}
Johannes Berg6ff57cf2013-05-16 00:55:00 +02009735EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +02009736
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04009737static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
9738 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +02009739 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009740{
9741 struct sk_buff *msg;
9742 void *hdr;
9743
Johannes Berge6d6e342009-07-01 21:26:47 +02009744 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009745 if (!msg)
9746 return;
9747
9748 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
9749 if (!hdr) {
9750 nlmsg_free(msg);
9751 return;
9752 }
9753
David S. Miller9360ffd2012-03-29 04:41:26 -04009754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9755 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9756 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
9757 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
9758 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +03009759
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009760 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +03009761
Johannes Berg463d0182009-07-14 00:33:35 +02009762 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9763 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009764 return;
9765
9766 nla_put_failure:
9767 genlmsg_cancel(msg, hdr);
9768 nlmsg_free(msg);
9769}
9770
9771void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009772 struct net_device *netdev, const u8 *addr,
9773 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009774{
9775 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +02009776 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009777}
9778
9779void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +02009780 struct net_device *netdev, const u8 *addr,
9781 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +03009782{
Johannes Berge6d6e342009-07-01 21:26:47 +02009783 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
9784 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +03009785}
9786
Samuel Ortizb23aa672009-07-01 21:26:54 +02009787void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
9788 struct net_device *netdev, const u8 *bssid,
9789 const u8 *req_ie, size_t req_ie_len,
9790 const u8 *resp_ie, size_t resp_ie_len,
9791 u16 status, gfp_t gfp)
9792{
9793 struct sk_buff *msg;
9794 void *hdr;
9795
Thomas Graf58050fc2012-06-28 03:57:45 +00009796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009797 if (!msg)
9798 return;
9799
9800 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
9801 if (!hdr) {
9802 nlmsg_free(msg);
9803 return;
9804 }
9805
David S. Miller9360ffd2012-03-29 04:41:26 -04009806 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9807 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9808 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
9809 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
9810 (req_ie &&
9811 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9812 (resp_ie &&
9813 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9814 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009815
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009816 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009817
Johannes Berg463d0182009-07-14 00:33:35 +02009818 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9819 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009820 return;
9821
9822 nla_put_failure:
9823 genlmsg_cancel(msg, hdr);
9824 nlmsg_free(msg);
9825
9826}
9827
9828void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
9829 struct net_device *netdev, const u8 *bssid,
9830 const u8 *req_ie, size_t req_ie_len,
9831 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
9832{
9833 struct sk_buff *msg;
9834 void *hdr;
9835
Thomas Graf58050fc2012-06-28 03:57:45 +00009836 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009837 if (!msg)
9838 return;
9839
9840 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
9841 if (!hdr) {
9842 nlmsg_free(msg);
9843 return;
9844 }
9845
David S. Miller9360ffd2012-03-29 04:41:26 -04009846 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9847 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9848 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
9849 (req_ie &&
9850 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
9851 (resp_ie &&
9852 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
9853 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009854
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009855 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009856
Johannes Berg463d0182009-07-14 00:33:35 +02009857 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9858 nl80211_mlme_mcgrp.id, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009859 return;
9860
9861 nla_put_failure:
9862 genlmsg_cancel(msg, hdr);
9863 nlmsg_free(msg);
9864
9865}
9866
9867void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
9868 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +02009869 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009870{
9871 struct sk_buff *msg;
9872 void *hdr;
9873
Thomas Graf58050fc2012-06-28 03:57:45 +00009874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009875 if (!msg)
9876 return;
9877
9878 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
9879 if (!hdr) {
9880 nlmsg_free(msg);
9881 return;
9882 }
9883
David S. Miller9360ffd2012-03-29 04:41:26 -04009884 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9885 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9886 (from_ap && reason &&
9887 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
9888 (from_ap &&
9889 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
9890 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
9891 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009892
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009893 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009894
Johannes Berg463d0182009-07-14 00:33:35 +02009895 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9896 nl80211_mlme_mcgrp.id, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009897 return;
9898
9899 nla_put_failure:
9900 genlmsg_cancel(msg, hdr);
9901 nlmsg_free(msg);
9902
9903}
9904
Johannes Berg04a773a2009-04-19 21:24:32 +02009905void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
9906 struct net_device *netdev, const u8 *bssid,
9907 gfp_t gfp)
9908{
9909 struct sk_buff *msg;
9910 void *hdr;
9911
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009912 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009913 if (!msg)
9914 return;
9915
9916 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
9917 if (!hdr) {
9918 nlmsg_free(msg);
9919 return;
9920 }
9921
David S. Miller9360ffd2012-03-29 04:41:26 -04009922 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9923 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
9924 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
9925 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +02009926
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009927 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +02009928
Johannes Berg463d0182009-07-14 00:33:35 +02009929 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9930 nl80211_mlme_mcgrp.id, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +02009931 return;
9932
9933 nla_put_failure:
9934 genlmsg_cancel(msg, hdr);
9935 nlmsg_free(msg);
9936}
9937
Johannes Berg947add32013-02-22 22:05:20 +01009938void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
9939 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -07009940{
Johannes Berg947add32013-02-22 22:05:20 +01009941 struct wireless_dev *wdev = dev->ieee80211_ptr;
9942 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009943 struct sk_buff *msg;
9944 void *hdr;
9945
Johannes Berg947add32013-02-22 22:05:20 +01009946 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
9947 return;
9948
9949 trace_cfg80211_notify_new_peer_candidate(dev, addr);
9950
Javier Cardonac93b5e72011-04-07 15:08:34 -07009951 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
9952 if (!msg)
9953 return;
9954
9955 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
9956 if (!hdr) {
9957 nlmsg_free(msg);
9958 return;
9959 }
9960
David S. Miller9360ffd2012-03-29 04:41:26 -04009961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +01009962 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
9963 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009964 (ie_len && ie &&
9965 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
9966 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -07009967
Johannes Berg3b7b72e2011-10-22 19:05:51 +02009968 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009969
9970 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
9971 nl80211_mlme_mcgrp.id, gfp);
9972 return;
9973
9974 nla_put_failure:
9975 genlmsg_cancel(msg, hdr);
9976 nlmsg_free(msg);
9977}
Johannes Berg947add32013-02-22 22:05:20 +01009978EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -07009979
Jouni Malinena3b8b052009-03-27 21:59:49 +02009980void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
9981 struct net_device *netdev, const u8 *addr,
9982 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +02009983 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +02009984{
9985 struct sk_buff *msg;
9986 void *hdr;
9987
Johannes Berge6d6e342009-07-01 21:26:47 +02009988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +02009989 if (!msg)
9990 return;
9991
9992 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
9993 if (!hdr) {
9994 nlmsg_free(msg);
9995 return;
9996 }
9997
David S. Miller9360ffd2012-03-29 04:41:26 -04009998 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9999 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10000 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10001 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10002 (key_id != -1 &&
10003 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10004 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10005 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010006
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010007 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010008
Johannes Berg463d0182009-07-14 00:33:35 +020010009 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10010 nl80211_mlme_mcgrp.id, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010011 return;
10012
10013 nla_put_failure:
10014 genlmsg_cancel(msg, hdr);
10015 nlmsg_free(msg);
10016}
10017
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010018void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10019 struct ieee80211_channel *channel_before,
10020 struct ieee80211_channel *channel_after)
10021{
10022 struct sk_buff *msg;
10023 void *hdr;
10024 struct nlattr *nl_freq;
10025
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010026 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010027 if (!msg)
10028 return;
10029
10030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10031 if (!hdr) {
10032 nlmsg_free(msg);
10033 return;
10034 }
10035
10036 /*
10037 * Since we are applying the beacon hint to a wiphy we know its
10038 * wiphy_idx is valid
10039 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010040 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10041 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010042
10043 /* Before */
10044 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10045 if (!nl_freq)
10046 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010047 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010048 goto nla_put_failure;
10049 nla_nest_end(msg, nl_freq);
10050
10051 /* After */
10052 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10053 if (!nl_freq)
10054 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010055 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010056 goto nla_put_failure;
10057 nla_nest_end(msg, nl_freq);
10058
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010059 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010060
Johannes Berg463d0182009-07-14 00:33:35 +020010061 rcu_read_lock();
10062 genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id,
10063 GFP_ATOMIC);
10064 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010065
10066 return;
10067
10068nla_put_failure:
10069 genlmsg_cancel(msg, hdr);
10070 nlmsg_free(msg);
10071}
10072
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010073static void nl80211_send_remain_on_chan_event(
10074 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010075 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010076 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010077 unsigned int duration, gfp_t gfp)
10078{
10079 struct sk_buff *msg;
10080 void *hdr;
10081
10082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10083 if (!msg)
10084 return;
10085
10086 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10087 if (!hdr) {
10088 nlmsg_free(msg);
10089 return;
10090 }
10091
David S. Miller9360ffd2012-03-29 04:41:26 -040010092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010093 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10094 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010095 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010096 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010097 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10098 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010099 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10100 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010101
David S. Miller9360ffd2012-03-29 04:41:26 -040010102 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10103 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10104 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010105
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010106 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010107
10108 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10109 nl80211_mlme_mcgrp.id, gfp);
10110 return;
10111
10112 nla_put_failure:
10113 genlmsg_cancel(msg, hdr);
10114 nlmsg_free(msg);
10115}
10116
Johannes Berg947add32013-02-22 22:05:20 +010010117void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10118 struct ieee80211_channel *chan,
10119 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010120{
Johannes Berg947add32013-02-22 22:05:20 +010010121 struct wiphy *wiphy = wdev->wiphy;
10122 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10123
10124 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010125 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010126 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010127 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010128}
Johannes Berg947add32013-02-22 22:05:20 +010010129EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010130
Johannes Berg947add32013-02-22 22:05:20 +010010131void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10132 struct ieee80211_channel *chan,
10133 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010134{
Johannes Berg947add32013-02-22 22:05:20 +010010135 struct wiphy *wiphy = wdev->wiphy;
10136 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10137
10138 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010139 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010140 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010141}
Johannes Berg947add32013-02-22 22:05:20 +010010142EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010143
Johannes Berg947add32013-02-22 22:05:20 +010010144void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10145 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010146{
Johannes Berg947add32013-02-22 22:05:20 +010010147 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10148 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010149 struct sk_buff *msg;
10150
Johannes Berg947add32013-02-22 22:05:20 +010010151 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10152
Thomas Graf58050fc2012-06-28 03:57:45 +000010153 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010154 if (!msg)
10155 return;
10156
John W. Linville66266b32012-03-15 13:25:41 -040010157 if (nl80211_send_station(msg, 0, 0, 0,
10158 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010159 nlmsg_free(msg);
10160 return;
10161 }
10162
10163 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10164 nl80211_mlme_mcgrp.id, gfp);
10165}
Johannes Berg947add32013-02-22 22:05:20 +010010166EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010167
Johannes Berg947add32013-02-22 22:05:20 +010010168void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010169{
Johannes Berg947add32013-02-22 22:05:20 +010010170 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10171 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010172 struct sk_buff *msg;
10173 void *hdr;
10174
Johannes Berg947add32013-02-22 22:05:20 +010010175 trace_cfg80211_del_sta(dev, mac_addr);
10176
Thomas Graf58050fc2012-06-28 03:57:45 +000010177 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010178 if (!msg)
10179 return;
10180
10181 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10182 if (!hdr) {
10183 nlmsg_free(msg);
10184 return;
10185 }
10186
David S. Miller9360ffd2012-03-29 04:41:26 -040010187 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10188 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10189 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010190
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010191 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010192
10193 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10194 nl80211_mlme_mcgrp.id, gfp);
10195 return;
10196
10197 nla_put_failure:
10198 genlmsg_cancel(msg, hdr);
10199 nlmsg_free(msg);
10200}
Johannes Berg947add32013-02-22 22:05:20 +010010201EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010202
Johannes Berg947add32013-02-22 22:05:20 +010010203void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10204 enum nl80211_connect_failed_reason reason,
10205 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010206{
Johannes Berg947add32013-02-22 22:05:20 +010010207 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10208 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010209 struct sk_buff *msg;
10210 void *hdr;
10211
10212 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10213 if (!msg)
10214 return;
10215
10216 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10217 if (!hdr) {
10218 nlmsg_free(msg);
10219 return;
10220 }
10221
10222 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10223 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10224 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10225 goto nla_put_failure;
10226
10227 genlmsg_end(msg, hdr);
10228
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}
Johannes Berg947add32013-02-22 22:05:20 +010010237EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010238
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010239static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10240 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010241{
10242 struct wireless_dev *wdev = dev->ieee80211_ptr;
10243 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10244 struct sk_buff *msg;
10245 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010246 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010247
Eric W. Biederman15e47302012-09-07 20:12:54 +000010248 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010249 return false;
10250
10251 msg = nlmsg_new(100, gfp);
10252 if (!msg)
10253 return true;
10254
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010255 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010256 if (!hdr) {
10257 nlmsg_free(msg);
10258 return true;
10259 }
10260
David S. Miller9360ffd2012-03-29 04:41:26 -040010261 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10262 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10263 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10264 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010265
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010266 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010267 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010268 return true;
10269
10270 nla_put_failure:
10271 genlmsg_cancel(msg, hdr);
10272 nlmsg_free(msg);
10273 return true;
10274}
10275
Johannes Berg947add32013-02-22 22:05:20 +010010276bool cfg80211_rx_spurious_frame(struct net_device *dev,
10277 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010278{
Johannes Berg947add32013-02-22 22:05:20 +010010279 struct wireless_dev *wdev = dev->ieee80211_ptr;
10280 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010281
Johannes Berg947add32013-02-22 22:05:20 +010010282 trace_cfg80211_rx_spurious_frame(dev, addr);
10283
10284 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10285 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10286 trace_cfg80211_return_bool(false);
10287 return false;
10288 }
10289 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10290 addr, gfp);
10291 trace_cfg80211_return_bool(ret);
10292 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010293}
Johannes Berg947add32013-02-22 22:05:20 +010010294EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10295
10296bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10297 const u8 *addr, gfp_t gfp)
10298{
10299 struct wireless_dev *wdev = dev->ieee80211_ptr;
10300 bool ret;
10301
10302 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10303
10304 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10305 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10306 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10307 trace_cfg80211_return_bool(false);
10308 return false;
10309 }
10310 ret = __nl80211_unexpected_frame(dev,
10311 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10312 addr, gfp);
10313 trace_cfg80211_return_bool(ret);
10314 return ret;
10315}
10316EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010317
Johannes Berg2e161f72010-08-12 15:38:38 +020010318int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010319 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010320 int freq, int sig_dbm,
10321 const u8 *buf, size_t len, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010322{
Johannes Berg71bbc992012-06-15 15:30:18 +020010323 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010324 struct sk_buff *msg;
10325 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010326
10327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10328 if (!msg)
10329 return -ENOMEM;
10330
Johannes Berg2e161f72010-08-12 15:38:38 +020010331 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010332 if (!hdr) {
10333 nlmsg_free(msg);
10334 return -ENOMEM;
10335 }
10336
David S. Miller9360ffd2012-03-29 04:41:26 -040010337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010338 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10339 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010340 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010341 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10342 (sig_dbm &&
10343 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10344 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10345 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010346
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010347 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010348
Eric W. Biederman15e47302012-09-07 20:12:54 +000010349 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010350
10351 nla_put_failure:
10352 genlmsg_cancel(msg, hdr);
10353 nlmsg_free(msg);
10354 return -ENOBUFS;
10355}
10356
Johannes Berg947add32013-02-22 22:05:20 +010010357void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10358 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010359{
Johannes Berg947add32013-02-22 22:05:20 +010010360 struct wiphy *wiphy = wdev->wiphy;
10361 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010362 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010363 struct sk_buff *msg;
10364 void *hdr;
10365
Johannes Berg947add32013-02-22 22:05:20 +010010366 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10367
Jouni Malinen026331c2010-02-15 12:53:10 +020010368 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10369 if (!msg)
10370 return;
10371
Johannes Berg2e161f72010-08-12 15:38:38 +020010372 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010373 if (!hdr) {
10374 nlmsg_free(msg);
10375 return;
10376 }
10377
David S. Miller9360ffd2012-03-29 04:41:26 -040010378 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010379 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10380 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010381 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010382 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10383 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10384 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10385 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010386
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010387 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010388
10389 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
10390 return;
10391
10392 nla_put_failure:
10393 genlmsg_cancel(msg, hdr);
10394 nlmsg_free(msg);
10395}
Johannes Berg947add32013-02-22 22:05:20 +010010396EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010397
Johannes Berg947add32013-02-22 22:05:20 +010010398void cfg80211_cqm_rssi_notify(struct net_device *dev,
10399 enum nl80211_cqm_rssi_threshold_event rssi_event,
10400 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010401{
Johannes Berg947add32013-02-22 22:05:20 +010010402 struct wireless_dev *wdev = dev->ieee80211_ptr;
10403 struct wiphy *wiphy = wdev->wiphy;
10404 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010405 struct sk_buff *msg;
10406 struct nlattr *pinfoattr;
10407 void *hdr;
10408
Johannes Berg947add32013-02-22 22:05:20 +010010409 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10410
Thomas Graf58050fc2012-06-28 03:57:45 +000010411 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010412 if (!msg)
10413 return;
10414
10415 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10416 if (!hdr) {
10417 nlmsg_free(msg);
10418 return;
10419 }
10420
David S. Miller9360ffd2012-03-29 04:41:26 -040010421 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010422 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010423 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010424
10425 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10426 if (!pinfoattr)
10427 goto nla_put_failure;
10428
David S. Miller9360ffd2012-03-29 04:41:26 -040010429 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10430 rssi_event))
10431 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010432
10433 nla_nest_end(msg, pinfoattr);
10434
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010435 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010436
10437 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10438 nl80211_mlme_mcgrp.id, gfp);
10439 return;
10440
10441 nla_put_failure:
10442 genlmsg_cancel(msg, hdr);
10443 nlmsg_free(msg);
10444}
Johannes Berg947add32013-02-22 22:05:20 +010010445EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010446
Johannes Berg947add32013-02-22 22:05:20 +010010447static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10448 struct net_device *netdev, const u8 *bssid,
10449 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010450{
10451 struct sk_buff *msg;
10452 struct nlattr *rekey_attr;
10453 void *hdr;
10454
Thomas Graf58050fc2012-06-28 03:57:45 +000010455 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010456 if (!msg)
10457 return;
10458
10459 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10460 if (!hdr) {
10461 nlmsg_free(msg);
10462 return;
10463 }
10464
David S. Miller9360ffd2012-03-29 04:41:26 -040010465 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10467 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10468 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010469
10470 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10471 if (!rekey_attr)
10472 goto nla_put_failure;
10473
David S. Miller9360ffd2012-03-29 04:41:26 -040010474 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10475 NL80211_REPLAY_CTR_LEN, replay_ctr))
10476 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010477
10478 nla_nest_end(msg, rekey_attr);
10479
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010480 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010481
10482 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10483 nl80211_mlme_mcgrp.id, gfp);
10484 return;
10485
10486 nla_put_failure:
10487 genlmsg_cancel(msg, hdr);
10488 nlmsg_free(msg);
10489}
10490
Johannes Berg947add32013-02-22 22:05:20 +010010491void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10492 const u8 *replay_ctr, gfp_t gfp)
10493{
10494 struct wireless_dev *wdev = dev->ieee80211_ptr;
10495 struct wiphy *wiphy = wdev->wiphy;
10496 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10497
10498 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10499 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10500}
10501EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10502
10503static void
10504nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10505 struct net_device *netdev, int index,
10506 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010507{
10508 struct sk_buff *msg;
10509 struct nlattr *attr;
10510 void *hdr;
10511
Thomas Graf58050fc2012-06-28 03:57:45 +000010512 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010513 if (!msg)
10514 return;
10515
10516 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10517 if (!hdr) {
10518 nlmsg_free(msg);
10519 return;
10520 }
10521
David S. Miller9360ffd2012-03-29 04:41:26 -040010522 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10523 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10524 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010525
10526 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10527 if (!attr)
10528 goto nla_put_failure;
10529
David S. Miller9360ffd2012-03-29 04:41:26 -040010530 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10531 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10532 (preauth &&
10533 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10534 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010535
10536 nla_nest_end(msg, attr);
10537
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010538 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010539
10540 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10541 nl80211_mlme_mcgrp.id, gfp);
10542 return;
10543
10544 nla_put_failure:
10545 genlmsg_cancel(msg, hdr);
10546 nlmsg_free(msg);
10547}
10548
Johannes Berg947add32013-02-22 22:05:20 +010010549void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10550 const u8 *bssid, bool preauth, gfp_t gfp)
10551{
10552 struct wireless_dev *wdev = dev->ieee80211_ptr;
10553 struct wiphy *wiphy = wdev->wiphy;
10554 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10555
10556 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10557 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10558}
10559EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10560
10561static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10562 struct net_device *netdev,
10563 struct cfg80211_chan_def *chandef,
10564 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010565{
10566 struct sk_buff *msg;
10567 void *hdr;
10568
Thomas Graf58050fc2012-06-28 03:57:45 +000010569 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010570 if (!msg)
10571 return;
10572
10573 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10574 if (!hdr) {
10575 nlmsg_free(msg);
10576 return;
10577 }
10578
Johannes Berg683b6d32012-11-08 21:25:48 +010010579 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10580 goto nla_put_failure;
10581
10582 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040010583 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070010584
10585 genlmsg_end(msg, hdr);
10586
10587 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10588 nl80211_mlme_mcgrp.id, gfp);
10589 return;
10590
10591 nla_put_failure:
10592 genlmsg_cancel(msg, hdr);
10593 nlmsg_free(msg);
10594}
10595
Johannes Berg947add32013-02-22 22:05:20 +010010596void cfg80211_ch_switch_notify(struct net_device *dev,
10597 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010598{
Johannes Berg947add32013-02-22 22:05:20 +010010599 struct wireless_dev *wdev = dev->ieee80211_ptr;
10600 struct wiphy *wiphy = wdev->wiphy;
10601 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10602
10603 trace_cfg80211_ch_switch_notify(dev, chandef);
10604
10605 wdev_lock(wdev);
10606
10607 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10608 wdev->iftype != NL80211_IFTYPE_P2P_GO))
10609 goto out;
10610
10611 wdev->channel = chandef->chan;
10612 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
10613out:
10614 wdev_unlock(wdev);
10615 return;
10616}
10617EXPORT_SYMBOL(cfg80211_ch_switch_notify);
10618
10619void cfg80211_cqm_txe_notify(struct net_device *dev,
10620 const u8 *peer, u32 num_packets,
10621 u32 rate, u32 intvl, gfp_t gfp)
10622{
10623 struct wireless_dev *wdev = dev->ieee80211_ptr;
10624 struct wiphy *wiphy = wdev->wiphy;
10625 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010626 struct sk_buff *msg;
10627 struct nlattr *pinfoattr;
10628 void *hdr;
10629
10630 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10631 if (!msg)
10632 return;
10633
10634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10635 if (!hdr) {
10636 nlmsg_free(msg);
10637 return;
10638 }
10639
10640 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010641 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070010642 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10643 goto nla_put_failure;
10644
10645 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10646 if (!pinfoattr)
10647 goto nla_put_failure;
10648
10649 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
10650 goto nla_put_failure;
10651
10652 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
10653 goto nla_put_failure;
10654
10655 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
10656 goto nla_put_failure;
10657
10658 nla_nest_end(msg, pinfoattr);
10659
10660 genlmsg_end(msg, hdr);
10661
10662 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10663 nl80211_mlme_mcgrp.id, gfp);
10664 return;
10665
10666 nla_put_failure:
10667 genlmsg_cancel(msg, hdr);
10668 nlmsg_free(msg);
10669}
Johannes Berg947add32013-02-22 22:05:20 +010010670EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010671
10672void
Simon Wunderlich04f39042013-02-08 18:16:19 +010010673nl80211_radar_notify(struct cfg80211_registered_device *rdev,
10674 struct cfg80211_chan_def *chandef,
10675 enum nl80211_radar_event event,
10676 struct net_device *netdev, gfp_t gfp)
10677{
10678 struct sk_buff *msg;
10679 void *hdr;
10680
10681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10682 if (!msg)
10683 return;
10684
10685 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
10686 if (!hdr) {
10687 nlmsg_free(msg);
10688 return;
10689 }
10690
10691 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10692 goto nla_put_failure;
10693
10694 /* NOP and radar events don't need a netdev parameter */
10695 if (netdev) {
10696 struct wireless_dev *wdev = netdev->ieee80211_ptr;
10697
10698 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10699 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10700 goto nla_put_failure;
10701 }
10702
10703 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
10704 goto nla_put_failure;
10705
10706 if (nl80211_send_chandef(msg, chandef))
10707 goto nla_put_failure;
10708
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010709 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010010710
10711 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10712 nl80211_mlme_mcgrp.id, gfp);
10713 return;
10714
10715 nla_put_failure:
10716 genlmsg_cancel(msg, hdr);
10717 nlmsg_free(msg);
10718}
10719
Johannes Berg947add32013-02-22 22:05:20 +010010720void cfg80211_cqm_pktloss_notify(struct net_device *dev,
10721 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010010722{
Johannes Berg947add32013-02-22 22:05:20 +010010723 struct wireless_dev *wdev = dev->ieee80211_ptr;
10724 struct wiphy *wiphy = wdev->wiphy;
10725 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010726 struct sk_buff *msg;
10727 struct nlattr *pinfoattr;
10728 void *hdr;
10729
Johannes Berg947add32013-02-22 22:05:20 +010010730 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
10731
Thomas Graf58050fc2012-06-28 03:57:45 +000010732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010733 if (!msg)
10734 return;
10735
10736 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10737 if (!hdr) {
10738 nlmsg_free(msg);
10739 return;
10740 }
10741
David S. Miller9360ffd2012-03-29 04:41:26 -040010742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010743 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010744 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
10745 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010746
10747 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10748 if (!pinfoattr)
10749 goto nla_put_failure;
10750
David S. Miller9360ffd2012-03-29 04:41:26 -040010751 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
10752 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010010753
10754 nla_nest_end(msg, pinfoattr);
10755
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010756 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010757
10758 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10759 nl80211_mlme_mcgrp.id, gfp);
10760 return;
10761
10762 nla_put_failure:
10763 genlmsg_cancel(msg, hdr);
10764 nlmsg_free(msg);
10765}
Johannes Berg947add32013-02-22 22:05:20 +010010766EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010010767
Johannes Berg7f6cf312011-11-04 11:18:15 +010010768void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
10769 u64 cookie, bool acked, gfp_t gfp)
10770{
10771 struct wireless_dev *wdev = dev->ieee80211_ptr;
10772 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10773 struct sk_buff *msg;
10774 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010775
Beni Lev4ee3e062012-08-27 12:49:39 +030010776 trace_cfg80211_probe_status(dev, addr, cookie, acked);
10777
Thomas Graf58050fc2012-06-28 03:57:45 +000010778 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030010779
Johannes Berg7f6cf312011-11-04 11:18:15 +010010780 if (!msg)
10781 return;
10782
10783 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
10784 if (!hdr) {
10785 nlmsg_free(msg);
10786 return;
10787 }
10788
David S. Miller9360ffd2012-03-29 04:41:26 -040010789 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10790 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10791 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
10792 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10793 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
10794 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010010795
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010796 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010010797
10798 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10799 nl80211_mlme_mcgrp.id, gfp);
10800 return;
10801
10802 nla_put_failure:
10803 genlmsg_cancel(msg, hdr);
10804 nlmsg_free(msg);
10805}
10806EXPORT_SYMBOL(cfg80211_probe_status);
10807
Johannes Berg5e7602302011-11-04 11:18:17 +010010808void cfg80211_report_obss_beacon(struct wiphy *wiphy,
10809 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070010810 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010010811{
10812 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10813 struct sk_buff *msg;
10814 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070010815 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010010816
Beni Lev4ee3e062012-08-27 12:49:39 +030010817 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
10818
Ben Greear37c73b52012-10-26 14:49:25 -070010819 spin_lock_bh(&rdev->beacon_registrations_lock);
10820 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
10821 msg = nlmsg_new(len + 100, GFP_ATOMIC);
10822 if (!msg) {
10823 spin_unlock_bh(&rdev->beacon_registrations_lock);
10824 return;
10825 }
Johannes Berg5e7602302011-11-04 11:18:17 +010010826
Ben Greear37c73b52012-10-26 14:49:25 -070010827 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
10828 if (!hdr)
10829 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010010830
Ben Greear37c73b52012-10-26 14:49:25 -070010831 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10832 (freq &&
10833 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
10834 (sig_dbm &&
10835 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
10836 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
10837 goto nla_put_failure;
10838
10839 genlmsg_end(msg, hdr);
10840
10841 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010010842 }
Ben Greear37c73b52012-10-26 14:49:25 -070010843 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010010844 return;
10845
10846 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070010847 spin_unlock_bh(&rdev->beacon_registrations_lock);
10848 if (hdr)
10849 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010010850 nlmsg_free(msg);
10851}
10852EXPORT_SYMBOL(cfg80211_report_obss_beacon);
10853
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010854#ifdef CONFIG_PM
10855void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
10856 struct cfg80211_wowlan_wakeup *wakeup,
10857 gfp_t gfp)
10858{
10859 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10860 struct sk_buff *msg;
10861 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010862 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010863
10864 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
10865
10866 if (wakeup)
10867 size += wakeup->packet_present_len;
10868
10869 msg = nlmsg_new(size, gfp);
10870 if (!msg)
10871 return;
10872
10873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
10874 if (!hdr)
10875 goto free_msg;
10876
10877 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10878 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
10879 goto free_msg;
10880
10881 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10882 wdev->netdev->ifindex))
10883 goto free_msg;
10884
10885 if (wakeup) {
10886 struct nlattr *reasons;
10887
10888 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
10889
10890 if (wakeup->disconnect &&
10891 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
10892 goto free_msg;
10893 if (wakeup->magic_pkt &&
10894 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
10895 goto free_msg;
10896 if (wakeup->gtk_rekey_failure &&
10897 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
10898 goto free_msg;
10899 if (wakeup->eap_identity_req &&
10900 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
10901 goto free_msg;
10902 if (wakeup->four_way_handshake &&
10903 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
10904 goto free_msg;
10905 if (wakeup->rfkill_release &&
10906 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
10907 goto free_msg;
10908
10909 if (wakeup->pattern_idx >= 0 &&
10910 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
10911 wakeup->pattern_idx))
10912 goto free_msg;
10913
Johannes Berg2a0e0472013-01-23 22:57:40 +010010914 if (wakeup->tcp_match)
10915 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH);
10916
10917 if (wakeup->tcp_connlost)
10918 nla_put_flag(msg,
10919 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST);
10920
10921 if (wakeup->tcp_nomoretokens)
10922 nla_put_flag(msg,
10923 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS);
10924
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010925 if (wakeup->packet) {
10926 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
10927 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
10928
10929 if (!wakeup->packet_80211) {
10930 pkt_attr =
10931 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
10932 len_attr =
10933 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
10934 }
10935
10936 if (wakeup->packet_len &&
10937 nla_put_u32(msg, len_attr, wakeup->packet_len))
10938 goto free_msg;
10939
10940 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
10941 wakeup->packet))
10942 goto free_msg;
10943 }
10944
10945 nla_nest_end(msg, reasons);
10946 }
10947
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010948 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010010949
10950 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10951 nl80211_mlme_mcgrp.id, gfp);
10952 return;
10953
10954 free_msg:
10955 nlmsg_free(msg);
10956}
10957EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
10958#endif
10959
Jouni Malinen3475b092012-11-16 22:49:57 +020010960void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
10961 enum nl80211_tdls_operation oper,
10962 u16 reason_code, gfp_t gfp)
10963{
10964 struct wireless_dev *wdev = dev->ieee80211_ptr;
10965 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10966 struct sk_buff *msg;
10967 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020010968
10969 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
10970 reason_code);
10971
10972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10973 if (!msg)
10974 return;
10975
10976 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
10977 if (!hdr) {
10978 nlmsg_free(msg);
10979 return;
10980 }
10981
10982 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10983 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10984 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
10985 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
10986 (reason_code > 0 &&
10987 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
10988 goto nla_put_failure;
10989
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010990 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020010991
10992 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
10993 nl80211_mlme_mcgrp.id, gfp);
10994 return;
10995
10996 nla_put_failure:
10997 genlmsg_cancel(msg, hdr);
10998 nlmsg_free(msg);
10999}
11000EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11001
Jouni Malinen026331c2010-02-15 12:53:10 +020011002static int nl80211_netlink_notify(struct notifier_block * nb,
11003 unsigned long state,
11004 void *_notify)
11005{
11006 struct netlink_notify *notify = _notify;
11007 struct cfg80211_registered_device *rdev;
11008 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011009 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011010
11011 if (state != NETLINK_URELEASE)
11012 return NOTIFY_DONE;
11013
11014 rcu_read_lock();
11015
Johannes Berg5e7602302011-11-04 11:18:17 +010011016 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011017 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011018 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011019
11020 spin_lock_bh(&rdev->beacon_registrations_lock);
11021 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11022 list) {
11023 if (reg->nlportid == notify->portid) {
11024 list_del(&reg->list);
11025 kfree(reg);
11026 break;
11027 }
11028 }
11029 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011030 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011031
11032 rcu_read_unlock();
11033
11034 return NOTIFY_DONE;
11035}
11036
11037static struct notifier_block nl80211_netlink_notifier = {
11038 .notifier_call = nl80211_netlink_notify,
11039};
11040
Jouni Malinen355199e2013-02-27 17:14:27 +020011041void cfg80211_ft_event(struct net_device *netdev,
11042 struct cfg80211_ft_event_params *ft_event)
11043{
11044 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11045 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11046 struct sk_buff *msg;
11047 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011048
11049 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11050
11051 if (!ft_event->target_ap)
11052 return;
11053
11054 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11055 if (!msg)
11056 return;
11057
11058 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
11059 if (!hdr) {
11060 nlmsg_free(msg);
11061 return;
11062 }
11063
11064 nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
11065 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
11066 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap);
11067 if (ft_event->ies)
11068 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies);
11069 if (ft_event->ric_ies)
11070 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11071 ft_event->ric_ies);
11072
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011073 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011074
11075 genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
11076 nl80211_mlme_mcgrp.id, GFP_KERNEL);
11077}
11078EXPORT_SYMBOL(cfg80211_ft_event);
11079
Arend van Spriel5de17982013-04-18 15:49:00 +020011080void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11081{
11082 struct cfg80211_registered_device *rdev;
11083 struct sk_buff *msg;
11084 void *hdr;
11085 u32 nlportid;
11086
11087 rdev = wiphy_to_dev(wdev->wiphy);
11088 if (!rdev->crit_proto_nlportid)
11089 return;
11090
11091 nlportid = rdev->crit_proto_nlportid;
11092 rdev->crit_proto_nlportid = 0;
11093
11094 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11095 if (!msg)
11096 return;
11097
11098 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11099 if (!hdr)
11100 goto nla_put_failure;
11101
11102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11103 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11104 goto nla_put_failure;
11105
11106 genlmsg_end(msg, hdr);
11107
11108 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11109 return;
11110
11111 nla_put_failure:
11112 if (hdr)
11113 genlmsg_cancel(msg, hdr);
11114 nlmsg_free(msg);
11115
11116}
11117EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11118
Johannes Berg55682962007-09-20 13:09:35 -040011119/* initialisation/exit functions */
11120
11121int nl80211_init(void)
11122{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011123 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011124
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011125 err = genl_register_family_with_ops(&nl80211_fam,
11126 nl80211_ops, ARRAY_SIZE(nl80211_ops));
Johannes Berg55682962007-09-20 13:09:35 -040011127 if (err)
11128 return err;
11129
Johannes Berg55682962007-09-20 13:09:35 -040011130 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
11131 if (err)
11132 goto err_out;
11133
Johannes Berg2a519312009-02-10 21:25:55 +010011134 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
11135 if (err)
11136 goto err_out;
11137
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011138 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
11139 if (err)
11140 goto err_out;
11141
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011142 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
11143 if (err)
11144 goto err_out;
11145
Johannes Bergaff89a92009-07-01 21:26:51 +020011146#ifdef CONFIG_NL80211_TESTMODE
11147 err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp);
11148 if (err)
11149 goto err_out;
11150#endif
11151
Jouni Malinen026331c2010-02-15 12:53:10 +020011152 err = netlink_register_notifier(&nl80211_netlink_notifier);
11153 if (err)
11154 goto err_out;
11155
Johannes Berg55682962007-09-20 13:09:35 -040011156 return 0;
11157 err_out:
11158 genl_unregister_family(&nl80211_fam);
11159 return err;
11160}
11161
11162void nl80211_exit(void)
11163{
Jouni Malinen026331c2010-02-15 12:53:10 +020011164 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011165 genl_unregister_family(&nl80211_fam);
11166}